configparser2dtypes


Nameconfigparser2dtypes JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/configparser2dtypes
SummaryLoads configuration files, converts their values to appropriate data types, and obtains the processed data in different representations
upload_time2023-05-12 21:59:31
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords configparser cfg convert
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # loads configuration files, converts their values to appropriate data types, and obtains the processed data in different representations


### pip install configparser2dtypes


The load_config_file_vars function is useful when you need to load a configuration file, 
convert its values to appropriate data types, and obtain the processed data in different 
representations. It simplifies the process of handling configuration files and allows 
you to access the data in the desired format for further analysis or usage 
within your application.



```python
Function: load_config_file_vars(cfgfile:str, onezeroasboolean:bool, force_dtypes:dict|None=None) -> Tuple[Dict, List, Dict]

This function is designed to load and process a configuration file, extracting the values and converting them to appropriate data types. It takes the following parameters:

cfgfile (str): The path or filename of the configuration file to be loaded.
onezeroasboolean (bool): A flag indicating whether to treat the values '0' and '1' as boolean values.
force_dtypes (dict|None): A dictionary that maps specific keys to desired data types for force-conversion.
Returns:

A tuple containing three outputs:
cfgdictcopy (Dict): The configuration file values stored in a nested dictionary structure, where each section and key is a nested dictionary key.
cfgdictcopyaslist (List): A modified list representation of the configuration file values, where each item is a tuple consisting of the section, key, and value.
cfgdictcopysorted (Dict): A grouped dictionary where the values are grouped based on the first item encountered in the cfgdictcopyaslist output.
```

## Usage:



```python
# Import the necessary modules and functions:
from configparser import ConfigParser
from pprint import pprint as pp
from load_config import load_config_file_vars
# Specify the path or filename of the configuration file to be loaded:
cfgfile = "path/to/config.ini"


# Example - content 
r"""
[proc1]
path_or_pid_or_dict={"path": r"some_installer.exe","path_re": "some_installer.exe",}
path2search=C:\
savepath=e:\check2
sleeptime_psutil=1
check_files=False
check_reg=False
regexcheck=^some_installer\.exe
attrbs_of_files_2_check=("aa_path","aa_name","aa_size_on_disk","aa_created","aa_last_written","aa_last_accessed",)
suspend_hotkeys=ctrl+alt+x
folder_for_modified_files=None
copybuffer=1024000

[proc2]
path_or_pid_or_dict={"path": r"HD-Player.exe", "path_re": "HD-Player.exe"}
path2search=C:\ProgramData\BlueStacks_nxt
savepath=e:\check1
sleeptime_psutil=1
check_files=True
check_reg=False
regexcheck=check\d+
attrbs_of_files_2_check=("aa_path","aa_name","aa_size_on_disk","aa_created","aa_last_written","aa_last_accessed",)
suspend_hotkeys=ctrl+alt+q
folder_for_modified_files=None
copybuffer=1024000
"""


# Call the load_config_file_vars function to load and process the configuration file:

from  configparser2dtypes import load_config_file_vars

import re
(
    cfg_dict,
    cfg_dict_as_list,
    cfg_dict_sorted,
) = load_config_file_vars(
    cfgfile=r"path/to/config.ini",
    onezeroasboolean=False,
    force_dtypes={"regexcheck": re.compile},
)

from pprint import pprint as pp

print('\n----------cfg_dict----------\n')
pp(cfg_dict)
print('\n----------cfg_dict_as_list----------\n')

pp(cfg_dict_as_list)
print('\n----------cfg_dict_sorted----------\n')

pp(cfg_dict_sorted)

----------cfg_dict----------
{'proc1': {'attrbs_of_files_2_check': ('aa_path',
                                       'aa_name',
                                       'aa_size_on_disk',
                                       'aa_created',
                                       'aa_last_written',
                                       'aa_last_accessed'),
           'check_files': False,
           'check_reg': False,
           'copybuffer': 1024000,
           'folder_for_modified_files': None,
           'path2search': 'C:\\',
           'path_or_pid_or_dict': {'path': 'some_installer.exe',
                                   'path_re': 'some_installer.exe'},
           'regexcheck': re.compile('^some_installer\\.exe'),
           'savepath': 'e:\\check2',
           'sleeptime_psutil': 1,
           'suspend_hotkeys': 'ctrl+alt+x'},
 'proc2': {'attrbs_of_files_2_check': ('aa_path',
                                       'aa_name',
                                       'aa_size_on_disk',
                                       'aa_created',
                                       'aa_last_written',
                                       'aa_last_accessed'),
           'check_files': True,
           'check_reg': False,
           'copybuffer': 1024000,
           'folder_for_modified_files': None,
           'path2search': 'C:\\ProgramData\\BlueStacks_nxt',
           'path_or_pid_or_dict': {'path': 'HD-Player.exe',
                                   'path_re': 'HD-Player.exe'},
           'regexcheck': re.compile('check\\d+'),
           'savepath': 'e:\\check1',
           'sleeptime_psutil': 1,
           'suspend_hotkeys': 'ctrl+alt+q'}}
		   


		   
----------cfg_dict_as_list----------
[({'path': 'some_installer.exe', 'path_re': 'some_installer.exe'},
  ('proc1', 'path_or_pid_or_dict')),
 ('C:\\', ('proc1', 'path2search')),
 ('e:\\check2', ('proc1', 'savepath')),
 (1, ('proc1', 'sleeptime_psutil')),
 (False, ('proc1', 'check_files')),
 (False, ('proc1', 'check_reg')),
 (re.compile('^some_installer\\.exe'), ('proc1', 'regexcheck')),
 (('aa_path',
   'aa_name',
   'aa_size_on_disk',
   'aa_created',
   'aa_last_written',
   'aa_last_accessed'),
  ('proc1', 'attrbs_of_files_2_check')),
 ('ctrl+alt+x', ('proc1', 'suspend_hotkeys')),
 (None, ('proc1', 'folder_for_modified_files')),
 (1024000, ('proc1', 'copybuffer')),
 ({'path': 'HD-Player.exe', 'path_re': 'HD-Player.exe'},
  ('proc2', 'path_or_pid_or_dict')),
 ('C:\\ProgramData\\BlueStacks_nxt', ('proc2', 'path2search')),
 ('e:\\check1', ('proc2', 'savepath')),
 (1, ('proc2', 'sleeptime_psutil')),
 (True, ('proc2', 'check_files')),
 (False, ('proc2', 'check_reg')),
 (re.compile('check\\d+'), ('proc2', 'regexcheck')),
 (('aa_path',
   'aa_name',
   'aa_size_on_disk',
   'aa_created',
   'aa_last_written',
   'aa_last_accessed'),
  ('proc2', 'attrbs_of_files_2_check')),
 ('ctrl+alt+q', ('proc2', 'suspend_hotkeys')),
 (None, ('proc2', 'folder_for_modified_files')),
 (1024000, ('proc2', 'copybuffer'))]
----------cfg_dict_sorted----------
{'proc1': [('proc1',
            ({'path': 'some_installer.exe', 'path_re': 'some_installer.exe'},
             ('proc1', 'path_or_pid_or_dict'))),
           ('proc1', ('C:\\', ('proc1', 'path2search'))),
           ('proc1', ('e:\\check2', ('proc1', 'savepath'))),
           ('proc1', (1, ('proc1', 'sleeptime_psutil'))),
           ('proc1', (False, ('proc1', 'check_files'))),
           ('proc1', (False, ('proc1', 'check_reg'))),
           ('proc1',
            (re.compile('^some_installer\\.exe'), ('proc1', 'regexcheck'))),
           ('proc1',
            (('aa_path',
              'aa_name',
              'aa_size_on_disk',
              'aa_created',
              'aa_last_written',
              'aa_last_accessed'),
             ('proc1', 'attrbs_of_files_2_check'))),
           ('proc1', ('ctrl+alt+x', ('proc1', 'suspend_hotkeys'))),
           ('proc1', (None, ('proc1', 'folder_for_modified_files'))),
           ('proc1', (1024000, ('proc1', 'copybuffer')))],
 'proc2': [('proc2',
            ({'path': 'HD-Player.exe', 'path_re': 'HD-Player.exe'},
             ('proc2', 'path_or_pid_or_dict'))),
           ('proc2',
            ('C:\\ProgramData\\BlueStacks_nxt', ('proc2', 'path2search'))),
           ('proc2', ('e:\\check1', ('proc2', 'savepath'))),
           ('proc2', (1, ('proc2', 'sleeptime_psutil'))),
           ('proc2', (True, ('proc2', 'check_files'))),
           ('proc2', (False, ('proc2', 'check_reg'))),
           ('proc2', (re.compile('check\\d+'), ('proc2', 'regexcheck'))),
           ('proc2',
            (('aa_path',
              'aa_name',
              'aa_size_on_disk',
              'aa_created',
              'aa_last_written',
              'aa_last_accessed'),
             ('proc2', 'attrbs_of_files_2_check'))),
           ('proc2', ('ctrl+alt+q', ('proc2', 'suspend_hotkeys'))),
           ('proc2', (None, ('proc2', 'folder_for_modified_files'))),
           ('proc2', (1024000, ('proc2', 'copybuffer')))]}



```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/configparser2dtypes",
    "name": "configparser2dtypes",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "configparser,cfg,convert",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/aa/47/e0d44f7418b4d7849afd6120951745e7abb1317a832425cae92424728425/configparser2dtypes-0.10.tar.gz",
    "platform": null,
    "description": "# loads configuration files, converts their values to appropriate data types, and obtains the processed data in different representations\r\n\r\n\r\n### pip install configparser2dtypes\r\n\r\n\r\nThe load_config_file_vars function is useful when you need to load a configuration file, \r\nconvert its values to appropriate data types, and obtain the processed data in different \r\nrepresentations. It simplifies the process of handling configuration files and allows \r\nyou to access the data in the desired format for further analysis or usage \r\nwithin your application.\r\n\r\n\r\n\r\n```python\r\nFunction: load_config_file_vars(cfgfile:str, onezeroasboolean:bool, force_dtypes:dict|None=None) -> Tuple[Dict, List, Dict]\r\n\r\nThis function is designed to load and process a configuration file, extracting the values and converting them to appropriate data types. It takes the following parameters:\r\n\r\ncfgfile (str): The path or filename of the configuration file to be loaded.\r\nonezeroasboolean (bool): A flag indicating whether to treat the values '0' and '1' as boolean values.\r\nforce_dtypes (dict|None): A dictionary that maps specific keys to desired data types for force-conversion.\r\nReturns:\r\n\r\nA tuple containing three outputs:\r\ncfgdictcopy (Dict): The configuration file values stored in a nested dictionary structure, where each section and key is a nested dictionary key.\r\ncfgdictcopyaslist (List): A modified list representation of the configuration file values, where each item is a tuple consisting of the section, key, and value.\r\ncfgdictcopysorted (Dict): A grouped dictionary where the values are grouped based on the first item encountered in the cfgdictcopyaslist output.\r\n```\r\n\r\n## Usage:\r\n\r\n\r\n\r\n```python\r\n# Import the necessary modules and functions:\r\nfrom configparser import ConfigParser\r\nfrom pprint import pprint as pp\r\nfrom load_config import load_config_file_vars\r\n# Specify the path or filename of the configuration file to be loaded:\r\ncfgfile = \"path/to/config.ini\"\r\n\r\n\r\n# Example - content \r\nr\"\"\"\r\n[proc1]\r\npath_or_pid_or_dict={\"path\": r\"some_installer.exe\",\"path_re\": \"some_installer.exe\",}\r\npath2search=C:\\\r\nsavepath=e:\\check2\r\nsleeptime_psutil=1\r\ncheck_files=False\r\ncheck_reg=False\r\nregexcheck=^some_installer\\.exe\r\nattrbs_of_files_2_check=(\"aa_path\",\"aa_name\",\"aa_size_on_disk\",\"aa_created\",\"aa_last_written\",\"aa_last_accessed\",)\r\nsuspend_hotkeys=ctrl+alt+x\r\nfolder_for_modified_files=None\r\ncopybuffer=1024000\r\n\r\n[proc2]\r\npath_or_pid_or_dict={\"path\": r\"HD-Player.exe\", \"path_re\": \"HD-Player.exe\"}\r\npath2search=C:\\ProgramData\\BlueStacks_nxt\r\nsavepath=e:\\check1\r\nsleeptime_psutil=1\r\ncheck_files=True\r\ncheck_reg=False\r\nregexcheck=check\\d+\r\nattrbs_of_files_2_check=(\"aa_path\",\"aa_name\",\"aa_size_on_disk\",\"aa_created\",\"aa_last_written\",\"aa_last_accessed\",)\r\nsuspend_hotkeys=ctrl+alt+q\r\nfolder_for_modified_files=None\r\ncopybuffer=1024000\r\n\"\"\"\r\n\r\n\r\n# Call the load_config_file_vars function to load and process the configuration file:\r\n\r\nfrom  configparser2dtypes import load_config_file_vars\r\n\r\nimport re\r\n(\r\n    cfg_dict,\r\n    cfg_dict_as_list,\r\n    cfg_dict_sorted,\r\n) = load_config_file_vars(\r\n    cfgfile=r\"path/to/config.ini\",\r\n    onezeroasboolean=False,\r\n    force_dtypes={\"regexcheck\": re.compile},\r\n)\r\n\r\nfrom pprint import pprint as pp\r\n\r\nprint('\\n----------cfg_dict----------\\n')\r\npp(cfg_dict)\r\nprint('\\n----------cfg_dict_as_list----------\\n')\r\n\r\npp(cfg_dict_as_list)\r\nprint('\\n----------cfg_dict_sorted----------\\n')\r\n\r\npp(cfg_dict_sorted)\r\n\r\n----------cfg_dict----------\r\n{'proc1': {'attrbs_of_files_2_check': ('aa_path',\r\n                                       'aa_name',\r\n                                       'aa_size_on_disk',\r\n                                       'aa_created',\r\n                                       'aa_last_written',\r\n                                       'aa_last_accessed'),\r\n           'check_files': False,\r\n           'check_reg': False,\r\n           'copybuffer': 1024000,\r\n           'folder_for_modified_files': None,\r\n           'path2search': 'C:\\\\',\r\n           'path_or_pid_or_dict': {'path': 'some_installer.exe',\r\n                                   'path_re': 'some_installer.exe'},\r\n           'regexcheck': re.compile('^some_installer\\\\.exe'),\r\n           'savepath': 'e:\\\\check2',\r\n           'sleeptime_psutil': 1,\r\n           'suspend_hotkeys': 'ctrl+alt+x'},\r\n 'proc2': {'attrbs_of_files_2_check': ('aa_path',\r\n                                       'aa_name',\r\n                                       'aa_size_on_disk',\r\n                                       'aa_created',\r\n                                       'aa_last_written',\r\n                                       'aa_last_accessed'),\r\n           'check_files': True,\r\n           'check_reg': False,\r\n           'copybuffer': 1024000,\r\n           'folder_for_modified_files': None,\r\n           'path2search': 'C:\\\\ProgramData\\\\BlueStacks_nxt',\r\n           'path_or_pid_or_dict': {'path': 'HD-Player.exe',\r\n                                   'path_re': 'HD-Player.exe'},\r\n           'regexcheck': re.compile('check\\\\d+'),\r\n           'savepath': 'e:\\\\check1',\r\n           'sleeptime_psutil': 1,\r\n           'suspend_hotkeys': 'ctrl+alt+q'}}\r\n\t\t   \r\n\r\n\r\n\t\t   \r\n----------cfg_dict_as_list----------\r\n[({'path': 'some_installer.exe', 'path_re': 'some_installer.exe'},\r\n  ('proc1', 'path_or_pid_or_dict')),\r\n ('C:\\\\', ('proc1', 'path2search')),\r\n ('e:\\\\check2', ('proc1', 'savepath')),\r\n (1, ('proc1', 'sleeptime_psutil')),\r\n (False, ('proc1', 'check_files')),\r\n (False, ('proc1', 'check_reg')),\r\n (re.compile('^some_installer\\\\.exe'), ('proc1', 'regexcheck')),\r\n (('aa_path',\r\n   'aa_name',\r\n   'aa_size_on_disk',\r\n   'aa_created',\r\n   'aa_last_written',\r\n   'aa_last_accessed'),\r\n  ('proc1', 'attrbs_of_files_2_check')),\r\n ('ctrl+alt+x', ('proc1', 'suspend_hotkeys')),\r\n (None, ('proc1', 'folder_for_modified_files')),\r\n (1024000, ('proc1', 'copybuffer')),\r\n ({'path': 'HD-Player.exe', 'path_re': 'HD-Player.exe'},\r\n  ('proc2', 'path_or_pid_or_dict')),\r\n ('C:\\\\ProgramData\\\\BlueStacks_nxt', ('proc2', 'path2search')),\r\n ('e:\\\\check1', ('proc2', 'savepath')),\r\n (1, ('proc2', 'sleeptime_psutil')),\r\n (True, ('proc2', 'check_files')),\r\n (False, ('proc2', 'check_reg')),\r\n (re.compile('check\\\\d+'), ('proc2', 'regexcheck')),\r\n (('aa_path',\r\n   'aa_name',\r\n   'aa_size_on_disk',\r\n   'aa_created',\r\n   'aa_last_written',\r\n   'aa_last_accessed'),\r\n  ('proc2', 'attrbs_of_files_2_check')),\r\n ('ctrl+alt+q', ('proc2', 'suspend_hotkeys')),\r\n (None, ('proc2', 'folder_for_modified_files')),\r\n (1024000, ('proc2', 'copybuffer'))]\r\n----------cfg_dict_sorted----------\r\n{'proc1': [('proc1',\r\n            ({'path': 'some_installer.exe', 'path_re': 'some_installer.exe'},\r\n             ('proc1', 'path_or_pid_or_dict'))),\r\n           ('proc1', ('C:\\\\', ('proc1', 'path2search'))),\r\n           ('proc1', ('e:\\\\check2', ('proc1', 'savepath'))),\r\n           ('proc1', (1, ('proc1', 'sleeptime_psutil'))),\r\n           ('proc1', (False, ('proc1', 'check_files'))),\r\n           ('proc1', (False, ('proc1', 'check_reg'))),\r\n           ('proc1',\r\n            (re.compile('^some_installer\\\\.exe'), ('proc1', 'regexcheck'))),\r\n           ('proc1',\r\n            (('aa_path',\r\n              'aa_name',\r\n              'aa_size_on_disk',\r\n              'aa_created',\r\n              'aa_last_written',\r\n              'aa_last_accessed'),\r\n             ('proc1', 'attrbs_of_files_2_check'))),\r\n           ('proc1', ('ctrl+alt+x', ('proc1', 'suspend_hotkeys'))),\r\n           ('proc1', (None, ('proc1', 'folder_for_modified_files'))),\r\n           ('proc1', (1024000, ('proc1', 'copybuffer')))],\r\n 'proc2': [('proc2',\r\n            ({'path': 'HD-Player.exe', 'path_re': 'HD-Player.exe'},\r\n             ('proc2', 'path_or_pid_or_dict'))),\r\n           ('proc2',\r\n            ('C:\\\\ProgramData\\\\BlueStacks_nxt', ('proc2', 'path2search'))),\r\n           ('proc2', ('e:\\\\check1', ('proc2', 'savepath'))),\r\n           ('proc2', (1, ('proc2', 'sleeptime_psutil'))),\r\n           ('proc2', (True, ('proc2', 'check_files'))),\r\n           ('proc2', (False, ('proc2', 'check_reg'))),\r\n           ('proc2', (re.compile('check\\\\d+'), ('proc2', 'regexcheck'))),\r\n           ('proc2',\r\n            (('aa_path',\r\n              'aa_name',\r\n              'aa_size_on_disk',\r\n              'aa_created',\r\n              'aa_last_written',\r\n              'aa_last_accessed'),\r\n             ('proc2', 'attrbs_of_files_2_check'))),\r\n           ('proc2', ('ctrl+alt+q', ('proc2', 'suspend_hotkeys'))),\r\n           ('proc2', (None, ('proc2', 'folder_for_modified_files'))),\r\n           ('proc2', (1024000, ('proc2', 'copybuffer')))]}\r\n\r\n\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Loads configuration files, converts their values to appropriate data types, and obtains the processed data in different representations",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/configparser2dtypes"
    },
    "split_keywords": [
        "configparser",
        "cfg",
        "convert"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cb7a977a28d4178ce22c248c7bd77258d0bb214e3e3f189dbdba07e4a92c1b88",
                "md5": "a4c151da47e65d5744aec91b0566c764",
                "sha256": "e8321a51c852e94d20bd8f6b502b12141e10b35b9192a36c0e085f24bca1a0b2"
            },
            "downloads": -1,
            "filename": "configparser2dtypes-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a4c151da47e65d5744aec91b0566c764",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9388,
            "upload_time": "2023-05-12T21:59:28",
            "upload_time_iso_8601": "2023-05-12T21:59:28.531830Z",
            "url": "https://files.pythonhosted.org/packages/cb/7a/977a28d4178ce22c248c7bd77258d0bb214e3e3f189dbdba07e4a92c1b88/configparser2dtypes-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aa47e0d44f7418b4d7849afd6120951745e7abb1317a832425cae92424728425",
                "md5": "4dbdad945a49f7cca6652d21724972fc",
                "sha256": "c4ea53e7fafc3557dbbcac6e12b22103e2040ae1b792398c728b0eff0beff490"
            },
            "downloads": -1,
            "filename": "configparser2dtypes-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "4dbdad945a49f7cca6652d21724972fc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7442,
            "upload_time": "2023-05-12T21:59:31",
            "upload_time_iso_8601": "2023-05-12T21:59:31.162181Z",
            "url": "https://files.pythonhosted.org/packages/aa/47/e0d44f7418b4d7849afd6120951745e7abb1317a832425cae92424728425/configparser2dtypes-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-12 21:59:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "configparser2dtypes",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "configparser2dtypes"
}
        
Elapsed time: 0.06809s