onecscripting


Nameonecscripting JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryPurpose of this package is to simplify interaction with 1C databases through COMobjects using Python language.
upload_time2024-09-25 15:49:18
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2023 Vladislav Anisimov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords onec 1c scripting script automation comobject
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # onecscripting

Purpose of this package is to simplify interaction with 1C databases through COMobjects using Python language. Access to database carried out by login and password and depends on your user's rights in that database.

> The package:
 - contain techniques (methods) that can be used by an information security consultant working with RBAC.
 - allow you to make scripting/automation task to deal with 1C database.
 - **work only for Windows OS**.

## Initial configuration:

1. Install 1C client version 8.3 (**supported versions >= 8.3.21.164**).
2. Register dll for you sepcific -version- (due to security policy might not be installed by default in step 1, see [this](https://its.1c.ru/db/edtdoc/content/10397/hdoc)):
```PowerShell
regsvr32 "C:\Program Files\1cv8\-version-\bin\comcntr.dll"
```
3. Setup your user in 1C database:
    - grant access rights to:
        - External Connection (StartExternalConnection);
        - *(optional)* read/write/e.t.c;
    - set authentification by login and password (domain/OS not allowed, only 1C: Enterprise);
    - additional for COM connection in control panel (top bar):
        - deselect *Tools -> User Settings -> Request confirmation when closing the program (Сервис->Настройки пользователя->Запрашивать подтверждение при закрытии программы)*;
        - select *Tools -> User Settings -> Prevent opening multiple sessions (Cервис->Настройки пользователя->Запретить открытие нескольких сеансов)*.

## Usage

### Initialization
```python
from onecscripting.infobase import OneC


user: str = 'user'
password: str = 'password'
host: str = 'host'
database: str = 'database'

onec = OneC()
```
I'm assume that you aren't familiar with 1C API, that's why you should call `onec = OneC()` before connection to database. It's allow you to work with predefined class methods.

##### Sync conenction
```python
with onec.connect(host=host, database=database, user=user, password=password):
    # do some stuff
    pass
```
##### Async connection
```python
from typing import Dict, Any

from concurrent.futures import ThreadPoolExecutor, Future, as_completed


workers: int = 2  # number of threads
databases: Dict[str, str] = {
    'database1': 'host1',
    'database2': 'host2'
    }  # define databases parameters (let user and password be the same)

def job(system: OneC, **settings):
    with system.connect(**settings):
        # do some stuff in specific connection
        pass

# start async jobs
with ThreadPoolExecutor(max_workers=workers) as executor:
    jobs: Dict[Future, str] = {
        executor.submit(
            job,
            system=onec,
            host=host,
            database=database,
            user=user,
            password=password
            ): database for database, host in databases.items()
        }
    for future in as_completed(jobs):
        database: str = jobs[future]
        try:
            # get results of async jobs
            job_result: Any = future.result()
        except Exception as e:
            print('%s, %s' % (database, e))
        else:
            # do some stuff with job's result
            pass
```
### Get all database users
```python
from typing import List, Optional

from onecscripting.infobase import OneC
from onecscripting.dbobj import User


onec = OneC()
with onec.connect(
    host='host',
    database='database',
    user='user',
    password='password'
    ) as connection:
    infobase_users: List[Optional[User]] = connection.get_all_users()
```
### Change password if it's expired
```python
from onecscripting.infobase import OneC
from onecscripting.dbobj import User


onec = OneC()
with onec.connect(
    host='host',
    database='database',
    user='user',
    password='password'
    ) as connection:
    current_user: User = onec.current_user
    if current_user.password_is_expire(days_to_expire=30):
        current_user.change_password(password='new password')
```

> For more information about usage please see additional examples in [/tests dir](tests) and [1C examples tasks](examples/onecguitasks.py).


## TODO:
1) Implement PEP 249;
2) Python standart async/await support;
3) Check for password change applied.


## LICENSE
> MIT

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "onecscripting",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Vladislav Anisimov <pan.vlados.w@gmail.com>",
    "keywords": "onec, 1C, scripting, script, automation, COMObject",
    "author": null,
    "author_email": "Vladislav Anisimov <pan.vlados.w@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a7/31/581c0cb50b1345dbf8ef4599cac60742d09fa1f6d5ad6606975dfaa4e885/onecscripting-1.0.0.tar.gz",
    "platform": null,
    "description": "# onecscripting\n\nPurpose of this package is to simplify interaction with 1C databases through COMobjects using Python language. Access to database carried out by login and password and depends on your user's rights in that database.\n\n> The package:\n - contain techniques (methods) that can be used by an information security consultant working with RBAC.\n - allow you to make scripting/automation task to deal with 1C database.\n - **work only for Windows OS**.\n\n## Initial configuration:\n\n1. Install 1C client version 8.3 (**supported versions >= 8.3.21.164**).\n2. Register dll for you sepcific -version- (due to security policy might not be installed by default in step 1, see [this](https://its.1c.ru/db/edtdoc/content/10397/hdoc)):\n```PowerShell\nregsvr32 \"C:\\Program Files\\1cv8\\-version-\\bin\\comcntr.dll\"\n```\n3. Setup your user in 1C database:\n    - grant access rights to:\n        - External Connection (StartExternalConnection);\n        - *(optional)* read/write/e.t.c;\n    - set authentification by login and password (domain/OS not allowed, only 1C: Enterprise);\n    - additional for COM connection in control panel (top bar):\n        - deselect *Tools -> User Settings -> Request confirmation when closing the program (\u0421\u0435\u0440\u0432\u0438\u0441->\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f->\u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b)*;\n        - select *Tools -> User Settings -> Prevent opening multiple sessions (C\u0435\u0440\u0432\u0438\u0441->\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f->\u0417\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0435\u0430\u043d\u0441\u043e\u0432)*.\n\n## Usage\n\n### Initialization\n```python\nfrom onecscripting.infobase import OneC\n\n\nuser: str = 'user'\npassword: str = 'password'\nhost: str = 'host'\ndatabase: str = 'database'\n\nonec = OneC()\n```\nI'm assume that you aren't familiar with 1C API, that's why you should call `onec = OneC()` before connection to database. It's allow you to work with predefined class methods.\n\n##### Sync conenction\n```python\nwith onec.connect(host=host, database=database, user=user, password=password):\n    # do some stuff\n    pass\n```\n##### Async connection\n```python\nfrom typing import Dict, Any\n\nfrom concurrent.futures import ThreadPoolExecutor, Future, as_completed\n\n\nworkers: int = 2  # number of threads\ndatabases: Dict[str, str] = {\n    'database1': 'host1',\n    'database2': 'host2'\n    }  # define databases parameters (let user and password be the same)\n\ndef job(system: OneC, **settings):\n    with system.connect(**settings):\n        # do some stuff in specific connection\n        pass\n\n# start async jobs\nwith ThreadPoolExecutor(max_workers=workers) as executor:\n    jobs: Dict[Future, str] = {\n        executor.submit(\n            job,\n            system=onec,\n            host=host,\n            database=database,\n            user=user,\n            password=password\n            ): database for database, host in databases.items()\n        }\n    for future in as_completed(jobs):\n        database: str = jobs[future]\n        try:\n            # get results of async jobs\n            job_result: Any = future.result()\n        except Exception as e:\n            print('%s, %s' % (database, e))\n        else:\n            # do some stuff with job's result\n            pass\n```\n### Get all database users\n```python\nfrom typing import List, Optional\n\nfrom onecscripting.infobase import OneC\nfrom onecscripting.dbobj import User\n\n\nonec = OneC()\nwith onec.connect(\n    host='host',\n    database='database',\n    user='user',\n    password='password'\n    ) as connection:\n    infobase_users: List[Optional[User]] = connection.get_all_users()\n```\n### Change password if it's expired\n```python\nfrom onecscripting.infobase import OneC\nfrom onecscripting.dbobj import User\n\n\nonec = OneC()\nwith onec.connect(\n    host='host',\n    database='database',\n    user='user',\n    password='password'\n    ) as connection:\n    current_user: User = onec.current_user\n    if current_user.password_is_expire(days_to_expire=30):\n        current_user.change_password(password='new password')\n```\n\n> For more information about usage please see additional examples in [/tests dir](tests) and [1C examples tasks](examples/onecguitasks.py).\n\n\n## TODO:\n1) Implement PEP 249;\n2) Python standart async/await support;\n3) Check for password change applied.\n\n\n## LICENSE\n> MIT\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Vladislav Anisimov  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  ",
    "summary": "Purpose of this package is to simplify interaction with 1C databases through COMobjects using Python language.",
    "version": "1.0.0",
    "project_urls": {
        "repository": "https://github.com/pan-vlados/onecscripting"
    },
    "split_keywords": [
        "onec",
        " 1c",
        " scripting",
        " script",
        " automation",
        " comobject"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "26210474366cd342442484ca47bb14b61503ea0e79f6483adc13a0cf8785ba29",
                "md5": "5dd0082dda753cbea599e50441e36819",
                "sha256": "2b6117745a99cd47fd88ec9a32f2e7d949d46450c1abf8eb73f49fe56bca89f4"
            },
            "downloads": -1,
            "filename": "onecscripting-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5dd0082dda753cbea599e50441e36819",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12680,
            "upload_time": "2024-09-25T15:49:17",
            "upload_time_iso_8601": "2024-09-25T15:49:17.103278Z",
            "url": "https://files.pythonhosted.org/packages/26/21/0474366cd342442484ca47bb14b61503ea0e79f6483adc13a0cf8785ba29/onecscripting-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a731581c0cb50b1345dbf8ef4599cac60742d09fa1f6d5ad6606975dfaa4e885",
                "md5": "8ee5eff6484ac98d43db00faaf1baa9a",
                "sha256": "2b35543e750b061211403619947d47cd2ca535555a5620fcf45d2813c13d9851"
            },
            "downloads": -1,
            "filename": "onecscripting-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8ee5eff6484ac98d43db00faaf1baa9a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 15136,
            "upload_time": "2024-09-25T15:49:18",
            "upload_time_iso_8601": "2024-09-25T15:49:18.919937Z",
            "url": "https://files.pythonhosted.org/packages/a7/31/581c0cb50b1345dbf8ef4599cac60742d09fa1f6d5ad6606975dfaa4e885/onecscripting-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-25 15:49:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pan-vlados",
    "github_project": "onecscripting",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "onecscripting"
}
        
Elapsed time: 0.31915s