Metadata-Version: 2.4
Name: ruth-tools
Version: 2022.1.0
Summary: Python utility package
Author-email: Eyes Rutherford <ruth-tools@inbox.ru>
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: ruth-tokenizer>=2022.0.0
Provides-Extra: startup-info
Provides-Extra: common
Provides-Extra: folders
Requires-Dist: ruth-logger>=2022.0.0; extra == "folders"
Provides-Extra: files
Requires-Dist: ruth-tools[folders]; extra == "files"
Requires-Dist: ruth-logger>=2022.0.0; extra == "files"
Requires-Dist: portalocker>=3.2.0; extra == "files"
Provides-Extra: tables
Requires-Dist: ruth-logger>=2022.0.0; extra == "tables"
Provides-Extra: all
Dynamic: license-file

from xml.etree.ElementTree import indentfrom sys import prefix

# Tools
Python Utility Tools Library



### Startup Info
This module print in stdout general info at startup.
Should be added at the beginning of the main program or where you need to display this information:

- [ ] examples:
    ```python
    from tools.startup_info import startup_info
    startup_info()
    ```
  
    result:
    ```cmd
    --------------------------
    2020-11-12 13:14:15.678901
    User: DemoUser
    Host: DemoUser-PC
    OS Platform: Windows-10-10.0.19020-SP0
    Python Version: 3.11.2 (tags/v3.11.2:bffe2c1, Jan 08 2020, 10:12:11) [MSC v.1936 64 bit (AMD64)]
    Implementation: CPython
    -----------------------
    ```





### Common
This module contains tools for general use.


##### Attribute Manager
This class contains methods for managing class attributes taking in consideration real mangled name of each attribute.

- [ ] examples:
    ```python
    from tools.common import AttributeManager

    class SomeClass:
        __slots__ = ('__private_attr', '_protected_attr', 'public_attr')
        ...
        def as_static(self, attr_name: str):
            mangled_name = AttributeManager.get_name(obj=self, attr=attr_name)
            print(f'attribute_mangled_name: {mangled_name}')
            #
            found = AttributeManager.has_attribute(obj=self, attr=attr_name)
            print(f'found: {found}')
            #
            if not found:
                AttributeManager.set_attribute(obj=self, attr=attr_name, value=None)
            #
            value = AttributeManager.get_attribute(obj=self, attr=attr_name)
            print(f'value: {value}')
            pass
            
        def as_instance(self, attr_name: str):
            attr = AttributeManager(obj=self, attr=attr_name)
            #
            mangled_name = attr.name
            print(f'attribute_mangled_name: {mangled_name}')
            #
            found = attr.exists
            print(f'found: {found}')
            #
            if not found:
                attr.value = None
            #
            value = attr.value
            print(f'value: {value}')
            pass
        ...
    pass
    ```


##### Hide Big Content
This method tries to hide big content over a limit of characters.

- [ ] examples:
    ```python
    from tools.common import hide_big_content
  
    content = {
        'key': 'value',
        'l': [1, 'a', 'b'],
        's': 'aaa',
        't': (1, 2, 'a' * 5000)
    }
    print(f'content: {content}')
    processed = hide_big_content(value=content)
    print(f'processed: {processed}')
    ```


##### Mask password
This method tries to mask passwords from provided object.

- [ ] examples:
    ```python
    from tools.common import mask_password
  
    content = [
        1, 2, True,
        {
            'password': '12345',
            'pwd': 'x56',
            'pwd_lst': ['123', '345', '567']
        }
    ]
    print(f'content: {content}')
    processed = mask_password(value=content)
    print(f'processed: {processed}')
    ```


##### Get Location
Try to resolve file / method location. Can be used for template relative location

- [ ] examples:
    ```python
    from tools.common import get_location
  
    def func(): pass
  
    func_location = get_location(func=func)
    print(f'func_location: {func_location}')
  
    file_location = get_location(file=__file__)
    print(f'file_location: {file_location}')
    ```





### Folders
This module was created to manage main folder operations.

- [ ] examples:
    ```python
    from tools.folders import Folder
    
    path = 'path/to/folder'

    if not Folder.exists(path=path):
        Folder.create(path='path/to/old-folder', recursive=True)
        
    Folder.remove(path='path/to/new-folder', recursive=True)
    ```





### Files
This module was created to perform main file operations.

- [ ] examples:
    ```python
    from tools.files import File
  
    path = 'path/to/file'
    name = 'file-name.ext'
  
    if not File.exists(path=path, name=name):
        File.write(path=path, name=name, content=None)
  
    demo = File.read(path=path, name=name)
    print(f'Demo file: {demo}')
  
    locked = File.lock(path=path, name=name)
    print('File is locked')
  
    try:
        File.write(path=path, name=name, content=b'new-content')
    except Exception as exc:
        print(f'Something got wrong: {exc}')
    
    File.unlock(file=locked)
    print('File is free to use')
  
    File.remove(path=path, name=name)
    ```





### Tables
This module was created to store data as a table, with data / column validation and filtering.
Cells can be accessed by index or by key.

- [ ] examples:
    ```python
    from tools.tables import Table
  
    table = Table(
        table={
            'columns': ['col-1', 'col-2'],
            'data': [
                # row-1
                {'col-1': 1, 'col-2': 2},
                # row-2
                {'col-1': True, 'col-2': 'str'}
            ]
        }
    )
    print(f'table: {table}')
  
    filtered_1 = table.filter(exclude=('col-1',))
    print(f'filtered_1: {filtered_1}')
    
    filtered_2 = table.filter(include=('col-2',))
    print(f'filtered_2: {filtered_2}')
    ```




