Skip to main content

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 to install corecfg.

pip install corecfg

Multi-Entity Sample Usage

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

  ----------------------------------------
  |  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.

# 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

Metadata

Release files for corecfg 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for corecfg 0.1.2
File Size Uploaded Provenance Actions
corecfg-0.1.2.tar.gz 10.7 kB Without provenance Details for corecfg-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for corecfg 0.1.2
File Interpreter ABI Platform Actions
corecfg-0.1.2-py3-none-any.whl Python 3 none any Details for corecfg-0.1.2-py3-none-any.whl

Total release size: 20.5 kB

Release files / corecfg-0.1.2.tar.gz

Download URL corecfg-0.1.2.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ba378abf07ccbfde1d0a329cd288c583a57f95c9140836982997c75aa5037557
BLAKE2b-256 checksum
How to use checksums
0b19bb4a6a03187061ad5a6a5ddc8b952abf13503e863fdd0ce78a01d5d6109a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / corecfg-0.1.2-py3-none-any.whl

Download URL corecfg-0.1.2-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5191e62825e0286d9d2809a7d46ca2827dd428a6ff1de62d94f983f6c7f97907
BLAKE2b-256 checksum
How to use checksums
b4101f85cdf001ad065a1ec136ca9e7814d9fb96f4fc96f4e563be4ce74e5a2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Security for corecfg 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page