From 62d1d9baca2b5de523a306e4ff798023229570cf Mon Sep 17 00:00:00 2001 From: elburg Date: Tue, 28 Feb 2023 18:13:53 -0800 Subject: [PATCH 1/3] no change? --- src/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index 267948f..8a388b3 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,5 +1,5 @@ from . import config from . import output import logging -def main(): - \ No newline at end of file +def main() : + From 8d2bb67499a65ad2d160d35d49171580e8176c01 Mon Sep 17 00:00:00 2001 From: elburg Date: Wed, 1 Mar 2023 10:14:04 -0800 Subject: [PATCH 2/3] naking stuff --- src/__init__.py | 23 ++++++++++++++++++-- src/__main__.py | 10 ++++++++- src/config.py | 6 +++++- src/datafiles/__init__.py | 44 ++++++++++++++++++++++++++++++++++++++ src/output.py | 1 - src/output/OutputObject.py | 24 +++++++++++++++++++++ src/output/__init__.py | 1 + 7 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 src/datafiles/__init__.py delete mode 100644 src/output.py create mode 100644 src/output/OutputObject.py create mode 100644 src/output/__init__.py diff --git a/src/__init__.py b/src/__init__.py index 8a388b3..068f71a 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,5 +1,24 @@ +# -*- coding: utf-8 -*- + from . import config from . import output import logging -def main() : - +import sys + +__author__ = "arris kathery" +__copyright__ = "copyright 2023 brendan berger" +__license__ = "" +__maintainer__ = "arris kathery" +__email__ = "whotookelburg@hotmail.com" +__version__ = "0.0.0-alpha0" + + +def main() -> dict: + + out=output.OutputObject() + + try: + # do shit + except KeyboardInterrupt: + return {'_kbi':True} + diff --git a/src/__main__.py b/src/__main__.py index 0393157..06c3fed 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -1 +1,9 @@ -raise "nononono u can't do that! >~<" \ No newline at end of file +import owo, sys + +if __name__ == "__main__": + output=owo.main() + del owo + if output._kb: + sys.exit() + else: + # output results diff --git a/src/config.py b/src/config.py index a953800..a340abe 100644 --- a/src/config.py +++ b/src/config.py @@ -1,2 +1,6 @@ +confDict = {} + def loadConfig(confLocation = "$HOME/.config/owo.yaml"): - \ No newline at end of file + from os import path + if not path.exists(confLocation): + diff --git a/src/datafiles/__init__.py b/src/datafiles/__init__.py new file mode 100644 index 0000000..c2b07e9 --- /dev/null +++ b/src/datafiles/__init__.py @@ -0,0 +1,44 @@ +_config={} +_files=[] + +_locations={ + '_yamlmainconf':[ + # Check current dir + './owo.yaml', + './owo.yml', + './owo.conf', + './owo.cfg', + './.owo.yaml', + './.owo.yml', + './.owo.conf', + './.owo.cfg', + + # Check home dir + '~/owo.yaml', + '~/owo.yml', + '~/owo.conf', + '~/owo.cfg', + '~/.owo.yaml', + '~/.owo.yml', + '~/.owo.conf', + '~/.owo.cfg' + ] +} + +from sys import platform + +_locations._yamlmainconf+={ + 'linux':[ + '{env.HOME}/owo.yaml', + '{env.HOME}/owo.yml', + '{env.HOME}/owo.conf', + '{env.HOME}/owo.cfg', + '{env.HOME}/.owo.yaml', + '{env.HOME}/.owo.yml', + '{env.HOME}/.owo.conf', + '{env.HOME}/.owo.cfg' + ], + 'linux2':self.linux +}[platform] + +def loadConfig(path: str) -> bool: diff --git a/src/output.py b/src/output.py deleted file mode 100644 index ade1461..0000000 --- a/src/output.py +++ /dev/null @@ -1 +0,0 @@ -import logging diff --git a/src/output/OutputObject.py b/src/output/OutputObject.py new file mode 100644 index 0000000..3f36075 --- /dev/null +++ b/src/output/OutputObject.py @@ -0,0 +1,24 @@ +import logging + +# outputDict={ +# 'status': 1, +# 'input': { +# 'argsRaw': sys.argv, +# 'streamObjects': [] +# }, +# 'output': [], +# 'errors': [] +# } + +class OutputObject: + + def __init__(self): + self.status = 1 + import sys + self.input = { + 'argsRaw': sys.argv, + 'streamObjects': [] + } + del sys + self.output = [] + self.errors = [] diff --git a/src/output/__init__.py b/src/output/__init__.py new file mode 100644 index 0000000..c9e1e71 --- /dev/null +++ b/src/output/__init__.py @@ -0,0 +1 @@ +from . import OutputObject From c94e713b1da8d3e5a951b868181902fa77017ac3 Mon Sep 17 00:00:00 2001 From: elburg Date: Fri, 3 Mar 2023 18:29:39 -0800 Subject: [PATCH 3/3] moving data to new repo --- src/__init__.py | 1 - src/datafiles/__init__.py | 83 ++++++++++++++++++++++----------------- src/format.py | 31 +++++++++++++++ 3 files changed, 78 insertions(+), 37 deletions(-) create mode 100644 src/format.py diff --git a/src/__init__.py b/src/__init__.py index 068f71a..d3b10bd 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -14,7 +14,6 @@ __version__ = "0.0.0-alpha0" def main() -> dict: - out=output.OutputObject() try: diff --git a/src/datafiles/__init__.py b/src/datafiles/__init__.py index c2b07e9..8ae5842 100644 --- a/src/datafiles/__init__.py +++ b/src/datafiles/__init__.py @@ -1,44 +1,55 @@ +from pathlib import Path +from sys import platform +from yaml import load, dump +import os +from re import search, IGNORECASE +import collections.abc + _config={} _files=[] +_configloaded = False -_locations={ - '_yamlmainconf':[ - # Check current dir - './owo.yaml', - './owo.yml', - './owo.conf', - './owo.cfg', - './.owo.yaml', - './.owo.yml', - './.owo.conf', - './.owo.cfg', +_LOCATIONS = { + '_YAMLCONFPATH':{ + '_DIR':[ + "{}/owo/".format(os.environ["XDG_CONFIG_HOME"]) if "XDG_CONFIG_HOME" in os.environ else str(Path.home())+"/.config/owo/", + "{}/".format(os.environ["XDG_CONFIG_HOME"]) if "XDG_CONFIG_HOME" in os.environ else str(Path.home())+"/.config/", + str(Path('~').resolve()), + str(Path().resolve()) if str(Path.cwd()) not in self._DIRS else None + ], + '_FNAME_RE': + r"([ou^>]w[ou^<]|config)\.(ya?ml|c(on)?fi?g?)$" + } - # Check home dir - '~/owo.yaml', - '~/owo.yml', - '~/owo.conf', - '~/owo.cfg', - '~/.owo.yaml', - '~/.owo.yml', - '~/.owo.conf', - '~/.owo.cfg' - ] } -from sys import platform +def _updateConf(toAdd: dict): + for key, value in toAdd.items(): + if isinstance(value, collections.abc.Mapping): + +def _loadYAMLConf(path: str): + try: + conf = yaml.load(file.read_text()) + except Exception as exc: + # do an err + else: + if not _config: + _config = conf + else: + -_locations._yamlmainconf+={ - 'linux':[ - '{env.HOME}/owo.yaml', - '{env.HOME}/owo.yml', - '{env.HOME}/owo.conf', - '{env.HOME}/owo.cfg', - '{env.HOME}/.owo.yaml', - '{env.HOME}/.owo.yml', - '{env.HOME}/.owo.conf', - '{env.HOME}/.owo.cfg' - ], - 'linux2':self.linux -}[platform] -def loadConfig(path: str) -> bool: +def initConfig(path: str) -> bool: + if _configloaded: + return True# If config already loaded, do not reload. + else: + try: + file = Path(path) + + if file.exists() and not file.is_dir(): + try: + conf = yaml.load(file.read_text()) + except Exception as exc: + # do an err + else: + if not _config diff --git a/src/format.py b/src/format.py new file mode 100644 index 0000000..46ac9d7 --- /dev/null +++ b/src/format.py @@ -0,0 +1,31 @@ +_DEFAULT = { + '_DATETEMP':'%a, %d %b %Y %H:%M:%S %Z%z', + '_INCLUDE':[ + 'env', + ] +} + +def dateFormat(input: str = _DEFAULT._DATETEMP,use_local:bool=True) -> str: + from time import strftime + if use_local: + from time import localtime + return strftime(input,localtime()) + else: + from time import gmtime + return strftime(input,gmtime()) + +def stringformat( + input: str, + include: list = _DEFAULT._INCLUDE + ) -> str: + + imap = { + 'time': dateFormat() + } + + if 'env' in include: + import os + imap['env'] = os.environ + del os + + return input.format_map(imap)