corecfg


Namecorecfg JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryCore configuration classes to serve as a foundation (base class) for configuring various Python projects.
upload_time2024-11-02 16:36:26
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords util utility
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # CoreCfg

**CoreCfg** consists of a discrete set of base configuration classes to serve as the core foundation for configuring python projects.

Imagine a python project, such as a connection management tool providing quick access to ssh or telnet sessions. That project itself, provides session access methods, possibly logging and other functionality. Using the python project flexibly implies providing several runtime options/attributes that would be used such as an IPV4 address, an ephemeral port, possibly a connection username, etc. Instead of having to memorize session specific attributes and provide them when opening each session, it is desirable to create a set of configuration details for multiple connection sessions and store their attributes in a persistent config file, allocating these session attributes to a session label. This way, opening a connection session only depends on providing one of the configured session labels and all attributes associated with the session are available to the runtime script.

CoreCfg serves as the base class to project specific configuration handlers. CoreCfg provides the basic interfaces to deal with the project configuration without concerning itself about specific attributes. That part is left up to child classes inheriting from CoreCfg in the context of specific projects.

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install **corecfg**.

```bash
pip install corecfg
```

## Multi-Entity Sample Usage
```python
from quickcolor.color_def import color
from corecfg.multi_entity import MultiEntityCoreCfg

class TestConfig(MultiEntityCoreCfg):

    def __init__(self):
        super(TestConfig, self).__init__(cfgFileName='test_config.json')

        cfgMetadataInit = { 'label' : 'Test Items', 'maxLabelLen' : 20 }
        categoryMetadataInit = {
                'trait-A' : { 'color' : color.CGREEN, 'maxLen' : 15 },
                'trait-B' : { 'color' : color.CWHITE2, 'maxLen' : 12 },
                'trait-C' : { 'color' : color.CBLUE2, 'maxLen' : 12 },
                'trait-D' : { 'color' : color.CVIOLET2, 'maxLen' : -1 },
                }

        if cfgMetadataInit != self.get_cfg_metadata() or categoryMetadataInit != self.get_category_metadata():
            self.initialize_metadata(cfgMetadata=cfgMetadataInit, categoryMetadata=categoryMetadataInit)


    def register(self, itemLabel, itemTraitA, itemTraitB, itemTraitC, itemTraitD):
        tupleList = {}
        tupleList['trait-A'] = itemTraitA
        tupleList['trait-B'] = itemTraitB
        tupleList['trait-C'] = itemTraitC
        tupleList['trait-D'] = itemTraitD

        cfgItemList = self.get_all_configured_items()

        if itemLabel in cfgItemList and tupleList in cfgItemList.values():
            print(f'{color.CRED2}Error: {color.CWHITE}Item {itemLabel} and tuple ' + \
                    f'{color.CBLUE2}{str(tupleList.values())} ' + \
                    f'{color.CWHITE}are already registered!{color.CEND}')
            return

        self.update_item(itemLabel = itemLabel, newTuple = tupleList)

    def unregister(self, itemLabel):
        cfgItemList = self.get_all_configured_items()
        if itemLabel not in cfgItemList:
            print(f'{color.CRED2}Error: {color.CWHITE} Test item label {color.CBLUE2}{itemLabel} ' + \
                    f'{color.CWHITE}is not registered in test config!{color.CEND}')
            return

        print(f'{color.CVIOLET2}\n   -- removing test item {color.CYELLOW}{itemLabel} ' + \
                f'{color.CVIOLET2}containing\n{color.CWHITE2}{str(cfgItemList[itemLabel])}{color.CEND}')

        self.remove_item(itemLabel=itemLabel)

tc = TestConfig()
tc.register('item #1', 'i1.a', 'i1.b', 'i1.c', 'i1.d')
tc.register('item #2', 'i2.a', 'i2.b', 'i2.c', 'i2.d')
tc.register('item #3', 'i3.a', 'i3.b', 'i3.c', 'i3.d')

tc.show_full_config()

tc.unregister('item #2')

tc.show_full_config()
```

## Multi-Entity Sample Output
```bash
  ----------------------------------------
  |  test_config.json          (custom)  |
  ----------------------------------------

   Test Items          trait-A        trait-B     trait-C     trait-D
   ----------          -------        -------     -------     -------
   item #1             i1.a           i1.b        i1.c        i1.d
   item #2             i2.a           i2.b        i2.c        i2.d
-> item #3             i3.a           i3.b        i3.c        i3.d


   -- removing test item item #2 containing
{'trait-A': 'i2.a', 'trait-B': 'i2.b', 'trait-C': 'i2.c', 'trait-D': 'i2.d'}

  ----------------------------------------
  |  test_config.json          (custom)  |
  ----------------------------------------

   Test Items          trait-A        trait-B     trait-C     trait-D
   ----------          -------        -------     -------     -------
   item #1             i1.a           i1.b        i1.c        i1.d
-> item #3             i3.a           i3.b        i3.c        i3.d
```

## CLI Utilities

The following multi entity CLI is provided in this package.

```bash
# corecfg-me -h
usage: corecfg-me [-h] [--cfgfile <cfg file>] [-d]
                  {remove.cfg,read.cfg,write.cfg,select.item,update.item,remove.item,remove.item.list,show.full.cfg,show.item.labels} ...

-.-.-. Core Config multi-entity controls

positional arguments:
  {remove.cfg,read.cfg,write.cfg,select.item,update.item,remove.item,remove.item.list,show.full.cfg,show.item.labels}
    remove.cfg          remove config file
    read.cfg            read from config file
    write.cfg           write to config file
    select.item         select config tuple
    update.item         update config tuple
    remove.item         remove config tuple
    remove.item.list    remove identified config tuples
    show.full.cfg       show full config
    show.item.labels    show item labels

options:
  -h, --help            show this help message and exit
  --cfgfile <cfg file>  Config filename
  -d, --debug           Run with debug hooks enabled

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
```


## License

[MIT](https://choosealicense.com/licenses/mit/)


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "corecfg",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Ed Waldner <waldevburry@proton.me>",
    "keywords": "util, utility",
    "author": null,
    "author_email": "Ed Waldner <waldevburry@proton.me>",
    "download_url": "https://files.pythonhosted.org/packages/0b/19/bb4a6a03187061ad5a6a5ddc8b952abf13503e863fdd0ce78a01d5d6109a/corecfg-0.1.2.tar.gz",
    "platform": null,
    "description": "# CoreCfg\n\n**CoreCfg** consists of a discrete set of base configuration classes to serve as the core foundation for configuring python projects.\n\nImagine a python project, such as a connection management tool providing quick access to ssh or telnet sessions. That project itself, provides session access methods, possibly logging and other functionality. Using the python project flexibly implies providing several runtime options/attributes that would be used such as an IPV4 address, an ephemeral port, possibly a connection username, etc. Instead of having to memorize session specific attributes and provide them when opening each session, it is desirable to create a set of configuration details for multiple connection sessions and store their attributes in a persistent config file, allocating these session attributes to a session label. This way, opening a connection session only depends on providing one of the configured session labels and all attributes associated with the session are available to the runtime script.\n\nCoreCfg serves as the base class to project specific configuration handlers. CoreCfg provides the basic interfaces to deal with the project configuration without concerning itself about specific attributes. That part is left up to child classes inheriting from CoreCfg in the context of specific projects.\n\n## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install **corecfg**.\n\n```bash\npip install corecfg\n```\n\n## Multi-Entity Sample Usage\n```python\nfrom quickcolor.color_def import color\nfrom corecfg.multi_entity import MultiEntityCoreCfg\n\nclass TestConfig(MultiEntityCoreCfg):\n\n    def __init__(self):\n        super(TestConfig, self).__init__(cfgFileName='test_config.json')\n\n        cfgMetadataInit = { 'label' : 'Test Items', 'maxLabelLen' : 20 }\n        categoryMetadataInit = {\n                'trait-A' : { 'color' : color.CGREEN, 'maxLen' : 15 },\n                'trait-B' : { 'color' : color.CWHITE2, 'maxLen' : 12 },\n                'trait-C' : { 'color' : color.CBLUE2, 'maxLen' : 12 },\n                'trait-D' : { 'color' : color.CVIOLET2, 'maxLen' : -1 },\n                }\n\n        if cfgMetadataInit != self.get_cfg_metadata() or categoryMetadataInit != self.get_category_metadata():\n            self.initialize_metadata(cfgMetadata=cfgMetadataInit, categoryMetadata=categoryMetadataInit)\n\n\n    def register(self, itemLabel, itemTraitA, itemTraitB, itemTraitC, itemTraitD):\n        tupleList = {}\n        tupleList['trait-A'] = itemTraitA\n        tupleList['trait-B'] = itemTraitB\n        tupleList['trait-C'] = itemTraitC\n        tupleList['trait-D'] = itemTraitD\n\n        cfgItemList = self.get_all_configured_items()\n\n        if itemLabel in cfgItemList and tupleList in cfgItemList.values():\n            print(f'{color.CRED2}Error: {color.CWHITE}Item {itemLabel} and tuple ' + \\\n                    f'{color.CBLUE2}{str(tupleList.values())} ' + \\\n                    f'{color.CWHITE}are already registered!{color.CEND}')\n            return\n\n        self.update_item(itemLabel = itemLabel, newTuple = tupleList)\n\n    def unregister(self, itemLabel):\n        cfgItemList = self.get_all_configured_items()\n        if itemLabel not in cfgItemList:\n            print(f'{color.CRED2}Error: {color.CWHITE} Test item label {color.CBLUE2}{itemLabel} ' + \\\n                    f'{color.CWHITE}is not registered in test config!{color.CEND}')\n            return\n\n        print(f'{color.CVIOLET2}\\n   -- removing test item {color.CYELLOW}{itemLabel} ' + \\\n                f'{color.CVIOLET2}containing\\n{color.CWHITE2}{str(cfgItemList[itemLabel])}{color.CEND}')\n\n        self.remove_item(itemLabel=itemLabel)\n\ntc = TestConfig()\ntc.register('item #1', 'i1.a', 'i1.b', 'i1.c', 'i1.d')\ntc.register('item #2', 'i2.a', 'i2.b', 'i2.c', 'i2.d')\ntc.register('item #3', 'i3.a', 'i3.b', 'i3.c', 'i3.d')\n\ntc.show_full_config()\n\ntc.unregister('item #2')\n\ntc.show_full_config()\n```\n\n## Multi-Entity Sample Output\n```bash\n  ----------------------------------------\n  |  test_config.json          (custom)  |\n  ----------------------------------------\n\n   Test Items          trait-A        trait-B     trait-C     trait-D\n   ----------          -------        -------     -------     -------\n   item #1             i1.a           i1.b        i1.c        i1.d\n   item #2             i2.a           i2.b        i2.c        i2.d\n-> item #3             i3.a           i3.b        i3.c        i3.d\n\n\n   -- removing test item item #2 containing\n{'trait-A': 'i2.a', 'trait-B': 'i2.b', 'trait-C': 'i2.c', 'trait-D': 'i2.d'}\n\n  ----------------------------------------\n  |  test_config.json          (custom)  |\n  ----------------------------------------\n\n   Test Items          trait-A        trait-B     trait-C     trait-D\n   ----------          -------        -------     -------     -------\n   item #1             i1.a           i1.b        i1.c        i1.d\n-> item #3             i3.a           i3.b        i3.c        i3.d\n```\n\n## CLI Utilities\n\nThe following multi entity CLI is provided in this package.\n\n```bash\n# corecfg-me -h\nusage: corecfg-me [-h] [--cfgfile <cfg file>] [-d]\n                  {remove.cfg,read.cfg,write.cfg,select.item,update.item,remove.item,remove.item.list,show.full.cfg,show.item.labels} ...\n\n-.-.-. Core Config multi-entity controls\n\npositional arguments:\n  {remove.cfg,read.cfg,write.cfg,select.item,update.item,remove.item,remove.item.list,show.full.cfg,show.item.labels}\n    remove.cfg          remove config file\n    read.cfg            read from config file\n    write.cfg           write to config file\n    select.item         select config tuple\n    update.item         update config tuple\n    remove.item         remove config tuple\n    remove.item.list    remove identified config tuples\n    show.full.cfg       show full config\n    show.item.labels    show item labels\n\noptions:\n  -h, --help            show this help message and exit\n  --cfgfile <cfg file>  Config filename\n  -d, --debug           Run with debug hooks enabled\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.\n```\n\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Core configuration classes to serve as a foundation (base class) for configuring various Python projects.",
    "version": "0.1.2",
    "project_urls": {
        "Documentation": "https://github.com/ew98/corecfg/wiki/CoreCfg",
        "Homepage": "https://github.com/ew98/corecfg",
        "Issues": "https://github.com/ew98/corecfg/issues"
    },
    "split_keywords": [
        "util",
        " utility"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b4101f85cdf001ad065a1ec136ca9e7814d9fb96f4fc96f4e563be4ce74e5a2b",
                "md5": "aca724ee1a3dd231f98277e5aa4b3ae8",
                "sha256": "5191e62825e0286d9d2809a7d46ca2827dd428a6ff1de62d94f983f6c7f97907"
            },
            "downloads": -1,
            "filename": "corecfg-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "aca724ee1a3dd231f98277e5aa4b3ae8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9827,
            "upload_time": "2024-11-02T16:36:25",
            "upload_time_iso_8601": "2024-11-02T16:36:25.504072Z",
            "url": "https://files.pythonhosted.org/packages/b4/10/1f85cdf001ad065a1ec136ca9e7814d9fb96f4fc96f4e563be4ce74e5a2b/corecfg-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0b19bb4a6a03187061ad5a6a5ddc8b952abf13503e863fdd0ce78a01d5d6109a",
                "md5": "bd91e28eb2ccbb58ac7291847898a813",
                "sha256": "ba378abf07ccbfde1d0a329cd288c583a57f95c9140836982997c75aa5037557"
            },
            "downloads": -1,
            "filename": "corecfg-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "bd91e28eb2ccbb58ac7291847898a813",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 10691,
            "upload_time": "2024-11-02T16:36:26",
            "upload_time_iso_8601": "2024-11-02T16:36:26.488426Z",
            "url": "https://files.pythonhosted.org/packages/0b/19/bb4a6a03187061ad5a6a5ddc8b952abf13503e863fdd0ce78a01d5d6109a/corecfg-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-02 16:36:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ew98",
    "github_project": "corecfg",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "corecfg"
}
        
Elapsed time: 2.28460s