utils (version 1.0.2) | index utils.py

`This tool runs CLI scripts and displays output in a Web Interface.
This file implements some tools for WebScripts server
and scripts (Logs, Namespace for configuration, ...).`

Modules
`` |  |
logging | ntpath |  |

Classes
`` |  | builtins.object _Logs logging.handlers.RotatingFileHandler(logging.handlers.BaseRotatingHandler) CustomLogHandler types.SimpleNamespace(builtins.object) DefaultNamespace
class CustomLogHandler(logging.handlers.RotatingFileHandler)
`` | `CustomLogHandler(filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False, errors=None) This class is a custom logging handler.`
| Method resolution order: CustomLogHandler logging.handlers.RotatingFileHandler logging.handlers.BaseRotatingHandler logging.FileHandler logging.StreamHandler logging.Handler logging.Filterer builtins.object Methods defined here: doRollover(self) `Do a rollover, as described in __init__().` namer(self, name: str) -> str `This function returns the new name of the old log files.` rotator(self, source: str, destination: str) -> None `This function compresses old log files.` Methods inherited from logging.handlers.RotatingFileHandler: __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False, errors=None) `Open the specified file and use it as the stream for logging. By default, the file grows indefinitely. You can specify particular values of maxBytes and backupCount to allow the file to rollover at a predetermined size. Rollover occurs whenever the current log file is nearly maxBytes in length. If backupCount is >= 1, the system will successively create new files with the same pathname as the base file, but with extensions ".1", ".2" etc. appended to it. For example, with a backupCount of 5 and a base file name of "app.log", you would get "app.log", "app.log.1", "app.log.2", ... through to "app.log.5". The file being written to is always "app.log" - when it gets filled up, it is closed and renamed to "app.log.1", and if files "app.log.1", "app.log.2" etc. exist, then they are renamed to "app.log.2", "app.log.3" etc. respectively. If maxBytes is zero, rollover never occurs.` shouldRollover(self, record) `Determine if rollover should occur. Basically, see if the supplied record would cause the file to exceed the size limit we have.` Methods inherited from logging.handlers.BaseRotatingHandler: emit(self, record) `Emit a record. Output the record to the file, catering for rollover as described in doRollover().` rotate(self, source, dest) `When rotating, rotate the current log. The default implementation calls the 'rotator' attribute of the handler, if it's callable, passing the source and dest arguments to it. If the attribute isn't callable (the default is None), the source is simply renamed to the destination. :param source: The source filename. This is normally the base filename, e.g. 'test.log' :param dest: The destination filename. This is normally what the source is rotated to, e.g. 'test.log.1'.` rotation_filename(self, default_name) `Modify the filename of a log file when rotating. This is provided so that a custom filename can be provided. The default implementation calls the 'namer' attribute of the handler, if it's callable, passing the default name to it. If the attribute isn't callable (the default is None), the name is returned unchanged. :param default_name: The default name for the log file.` Methods inherited from logging.FileHandler: __repr__(self) `Return repr(self).` close(self) `Closes the stream.` Methods inherited from logging.StreamHandler: flush(self) `Flushes the stream.` setStream(self, stream) `Sets the StreamHandler's stream to the specified value, if it is different. Returns the old stream, if the stream was changed, or None if it wasn't.` Data and other attributes inherited from logging.StreamHandler: terminator = '\n' Methods inherited from logging.Handler: acquire(self) `Acquire the I/O thread lock.` createLock(self) `Acquire a thread lock for serializing access to the underlying I/O.` format(self, record) `Format the specified record. If a formatter is set, use it. Otherwise, use the default formatter for the module.` get_name(self) handle(self, record) `Conditionally emit the specified logging record. Emission depends on filters which may have been added to the handler. Wrap the actual emission of the record with acquisition/release of the I/O thread lock. Returns whether the filter passed the record for emission.` handleError(self, record) `Handle errors which occur during an emit() call. This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method.` release(self) `Release the I/O thread lock.` setFormatter(self, fmt) `Set the formatter for this handler.` setLevel(self, level) `Set the logging level of this handler. level must be an int or a str.` set_name(self, name) Data descriptors inherited from logging.Handler: name Methods inherited from logging.Filterer: addFilter(self, filter) `Add the specified filter to this handler.` filter(self, record) `Determine if a record is loggable by consulting all the filters. The default is to allow the record to be logged; any filter can veto this and the record is then dropped. Returns a zero value if a record is to be dropped, else non-zero. .. versionchanged:: 3.2 Allow filters to be just callables.` removeFilter(self, filter) `Remove the specified filter from this handler.` Data descriptors inherited from logging.Filterer: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class DefaultNamespace(types.SimpleNamespace)
`` | `DefaultNamespace(required: List[str] = [], optional: List[str] = [], default: dict = {}, types: dict = {}) This class build simple namespace with default attributs.`
| Method resolution order: DefaultNamespace types.SimpleNamespace builtins.object Methods defined here: __getitem__(self, key: str) `Compatibility with dict.` __init__(self, required: List[str] = [], optional: List[str] = [], default: dict = {}, types: dict = {}) `Initialize self. See help(type(self)) for accurate signature.` build_type(self, attribut: str, value: Any, type_: type = None) -> None `This function builds type from configuration value.` build_types(self) -> None `This function builds type from configuration values.` check_required(self) -> None `This function checks required attributes if one of required attributes is missing this function raise MissingAttributesError.` export_as_json(self, name: str = None) -> None `This function export namespace values (useful for debugging).` get(self, key: str, default=None) `Compatibility with dict.` get_dict(self) -> None `This function return a dict of attributes.` get_missings(self) -> List[str] `This function checks required attributes and return a List[str] of missing required attributes.` get_unexpecteds(self, log: bool = True) -> List[str] `This function return a List[str] of all attributes not in optional and required attributes. If log argument is True a Warning log message is write for all unexpected attributes.` set_defaults(self) -> None `This function set defaults attribut with defaults values.` update(self, **kwargs) `This function add/update attributes with **kwargs arguments.` Class methods defined here: default_build(**kwargs) -> ~DefaultNamespace from builtins.type `Default build for DefaultNamespace (set defaults, add values, check requirements and unexpected values and build types).` Data descriptors defined here: __weakref__ `list of weak references to the object (if defined)` Methods inherited from types.SimpleNamespace: __delattr__(self, name, /) `Implement delattr(self, name).` __eq__(self, value, /) `Return self==value.` __ge__(self, value, /) `Return self>=value.` __getattribute__(self, name, /) `Return getattr(self, name).` __gt__(self, value, /) `Return self>value.` __le__(self, value, /) `Return self<=value.` __lt__(self, value, /) `Return self<value.` __ne__(self, value, /) `Return self!=value.` __reduce__(...) `Return state information for pickling` __repr__(self, /) `Return repr(self).` __setattr__(self, name, value, /) `Implement setattr(self, name, value).` Static methods inherited from types.SimpleNamespace: __new__(*args, **kwargs) from builtins.type `Create and return a new object. See help(type) for accurate signature.` Data descriptors inherited from types.SimpleNamespace: __dict__ Data and other attributes inherited from types.SimpleNamespace: __hash__ = None
Logs = class _Logs(builtins.object)
`` | `This class implements basic python logs.`
| Methods defined here: access(log: str) -> None `This function implements access logs for WebScripts.` authentication(log: str) -> None `This function implements authentication logs for WebScripts.` command(log: str) -> None `This function implements response logs for WebScripts.` config(*args, **kwargs) `This function config ROOT logger.` critical(log: str) -> None `This function implements basic python critical logs for WebScripts.` debug(log: str) -> None `This function implements basic python debug logs for WebScripts.` error(log: str) -> None `This function implements basic python error logs for WebScripts.` exception(log: str) -> None `This function implements basic python exception (error) logs for WebScripts.` info(log: str) -> None `This function implements basic python info logs for WebScripts.` response(log: str) -> None `This function implements response logs for WebScripts.` trace(log: str) -> None `This function implements trace logs for WebScripts.` warning(log: str) -> None `This function implements basic python warning logs for WebScripts.` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)` Data and other attributes defined here: __annotations__ = {'console': <class 'logging.Logger'>, 'file': <class 'logging.Logger'>, 'log_access': <class 'logging.Logger'>, 'log_authentication': <class 'logging.Logger'>, 'log_command': <class 'logging.Logger'>, 'log_critical': <class 'logging.Logger'>, 'log_debug': <class 'logging.Logger'>, 'log_error': <class 'logging.Logger'>, 'log_info': <class 'logging.Logger'>, 'log_response': <class 'logging.Logger'>, ...} console = <Logger WebScripts.console (WARNING)> file = <Logger WebScripts.file (WARNING)> log_access = <Logger WebScripts.access (WARNING)> log_authentication = <Logger WebScripts.authentication (WARNING)> log_command = <Logger WebScripts.command (WARNING)> log_critical = <Logger WebScripts.critical (WARNING)> log_debug = <Logger WebScripts.debug (WARNING)> log_error = <Logger WebScripts.error (WARNING)> log_info = <Logger WebScripts.info (WARNING)> log_response = <Logger WebScripts.response (WARNING)> log_trace = <Logger WebScripts.trace (WARNING)> log_warning = <Logger WebScripts.warning (WARNING)>

Functions
`` |  | check_file_permission(configuration: utils.DefaultNamespace, filepath: str, recursive: bool = False, executable: bool = False, dir_check: bool = True) -> bool `This function checks files and directories permissions for security.` get_arguments_count(object_: collections.abc.Callable) `This function return the number of argument to call this Callable object.` get_encodings() `This function returns the probable encodings.` get_file_content(file_path, *args, as_iterator: bool = False, **kwargs) -> ~StrOrBytes `This function return the file content.` get_ini_dict(filename: str) -> Dict[str, Dict[str, str]] `This function return a dict from ini filename.` get_ip(environ: os._Environ, ip_number: int = None, protected: bool = True) -> str `This function return the real IP.` get_real_path(file_path: str, is_dir: bool = False, no_error: bool = False) -> str `This function return the real path for files.` log_trace(function: Union[function, method]) -> Union[function, method] `This decorator traces functions (start and end).` logger_access = access(log: str) -> None `This function implements access logs for WebScripts.` logger_auth = authentication(log: str) -> None `This function implements authentication logs for WebScripts.` logger_command = command(log: str) -> None `This function implements response logs for WebScripts.` logger_critical = critical(log: str) -> None `This function implements basic python critical logs for WebScripts.` logger_debug = debug(log: str) -> None `This function implements basic python debug logs for WebScripts.` logger_error = error(log: str) -> None `This function implements basic python error logs for WebScripts.` logger_info = info(log: str) -> None `This function implements basic python info logs for WebScripts.` logger_response = response(log: str) -> None `This function implements response logs for WebScripts.` logger_warning = warning(log: str) -> None `This function implements basic python warning logs for WebScripts.`

Data
`` |  | __all__ = ['Logs', 'DefaultNamespace', 'log_trace', 'get_ip', 'get_arguments_count', 'get_file_content', 'get_real_path', 'get_encodings', 'get_ini_dict', 'server_path', 'CustomLogHandler', 'logger_debug', 'logger_info', 'logger_auth', 'logger_access', 'logger_response', 'logger_command', 'logger_warning', 'logger_error', 'logger_critical', ...] __annotations__ = {'date_format': <class 'str'>, 'logger_access': <class 'collections.abc.Callable'>, 'logger_auth': <class 'collections.abc.Callable'>, 'logger_command': <class 'collections.abc.Callable'>, 'logger_critical': <class 'collections.abc.Callable'>, 'logger_debug': <class 'collections.abc.Callable'>, 'logger_error': <class 'collections.abc.Callable'>, 'logger_info': <class 'collections.abc.Callable'>, 'logger_response': <class 'collections.abc.Callable'>, 'logger_trace': <class 'collections.abc.Callable'>, ...} __author_email__ = 'mauricelambert434@gmail.com' __copyright__ = '\nWebScripts Copyright (C) 2021, 2022, 2023 Mau...ome to redistribute it\nunder certain conditions.\n' __description__ = '\nThis tool run scripts and display the result in...cripts (Logs, Namespace for configuration, ...).\n' __license__ = 'GPL-3.0 License' __maintainer__ = 'Maurice Lambert' __maintainer_email__ = 'mauricelambert434@gmail.com' __url__ = 'https://github.com/mauricelambert/WebScripts' server_path = /home/WebScripts

Author
`` |  | Maurice Lambert