diff --git a/.gitignore b/.gitignore index 3e3c1b1..5d381cc 100644 --- a/.gitignore +++ b/.gitignore @@ -160,10 +160,3 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -# replit -.replit -venv/ -replit.nix -.upm/ -.cache/ -.config/ diff --git a/owo/__init__.py b/owo/__init__.py index 7326395..2d9f559 100644 --- a/owo/__init__.py +++ b/owo/__init__.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- -# TODO: clean this up -# TODO: load datafiles. if not found, either fail or install files (maybe)? -from .output.owoOutputClass import owoOutputClass -from . import datafiles + +# from . import config +from . import output import logging import sys @@ -15,17 +14,22 @@ __version__ = "0.0.0-alpha0" DEBUG = True +def main() -> dict: + try: + out=output.OutputObject() + except Exception as exc: + return { + '_err':True, + 'exception':exc, + 'vars':{ + 'globals': globals(), + 'locals': locals(), + 'dir': dir() + } + } + try: + pass + # do shit + except KeyboardInterrupt: + return {'_kbi':True} -def main() -> owoOutputClass: - # PART 1: init - try: - out = owoOutputClass() - except Exception as exc: - import traceback - traceback.print_exc(exc, file=sys.stderr) - sys.exit(1) - else: - pass - # PART 2: load config/data files - try: - diff --git a/owo/__main__.py b/owo/__main__.py index 622eab0..169e443 100644 --- a/owo/__main__.py +++ b/owo/__main__.py @@ -9,8 +9,11 @@ import owo if __name__ == "__main__": output=owo.main() - if output == None: - print("an error might have occured...",file=sys.stderr) + del owo + if output.__contains__('_err'): + print("an error occured!", file=sys.stderr) + if output.__contains__('_kb'): + print("interupted by keyboard") + sys.exit() else: - from yaml import dump - print(dump(output)) \ No newline at end of file + pass # output results diff --git a/owo/config.py b/owo/config.py new file mode 100644 index 0000000..a340abe --- /dev/null +++ b/owo/config.py @@ -0,0 +1,6 @@ +confDict = {} + +def loadConfig(confLocation = "$HOME/.config/owo.yaml"): + from os import path + if not path.exists(confLocation): + diff --git a/owo/datafiles/__init__.py b/owo/datafiles/__init__.py index 799190e..665a9cb 100644 --- a/owo/datafiles/__init__.py +++ b/owo/datafiles/__init__.py @@ -2,8 +2,7 @@ from pathlib import Path from sys import platform from yaml import load, dump import os -import sys -import re +from re import search, IGNORECASE import collections.abc _config={} @@ -16,7 +15,7 @@ _LOCATIONS = { "{}/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()) + 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?)$" @@ -24,48 +23,26 @@ _LOCATIONS = { } -def _mDC_listMatches(inp: str) -> list: - "\n".join(os.listdir(inp)) - return re.findall( - _LOCATIONS['_YAMLCONFPATH']['_FNAME_RE'], - inp - ) - -def _makeDefaultConfs() -> list: - locates=[] - for x in _LOCATIONS['_YAMLCONFPATH']['_DIR']: - locates+=_mDC_listMatches(x) - return locates - def _updateConf(toAdd: dict): - _config.update(toAdd) + _config = toAdd.update(_config) -def _loadConfigFile(path: str): - try: - file = Path(path) - - if file.exists() and not file.is_dir(): - try: - conf = yaml.load(file.read_text()) - except Exception as exc: - raise exc - else: - if not _config: - _config = conf - else: - _updateConf(conf) - if file not in _files: - _files+str(file) - except Exception as exc: - print(exc) - import traceback - traceback.print_exc(file=sys.stderr) - -def initConfig(path: str = None) -> bool: +def initConfig(path: str) -> bool: if _configloaded: return True# If config already loaded, do not reload. else: - _toLookIn=_makeDefaultConfs()+path - for loc in _toLookIn: - _loadConfigFile(loc) + try: + file = Path(path) + + if file.exists() and not file.is_dir(): + try: + conf = yaml.load(file.read_text()) + except Exception as exc: + raise exc + else: + if not _config: + _config = conf + else: + _updateConf(conf) + if file not in _files: + _files+str(file) diff --git a/owo/format.py b/owo/format.py index 8ab32c6..46ac9d7 100644 --- a/owo/format.py +++ b/owo/format.py @@ -1,7 +1,3 @@ -# TODO: clean this up -# TODO: complete dateFormat() -# TODO: complete stringFormat() - _DEFAULT = { '_DATETEMP':'%a, %d %b %Y %H:%M:%S %Z%z', '_INCLUDE':[ @@ -18,7 +14,7 @@ def dateFormat(input: str = _DEFAULT._DATETEMP,use_local:bool=True) -> str: from time import gmtime return strftime(input,gmtime()) -def stringFormat( +def stringformat( input: str, include: list = _DEFAULT._INCLUDE ) -> str: diff --git a/owo/output/OutputObject.py b/owo/output/OutputObject.py index ca99e2e..3f36075 100644 --- a/owo/output/OutputObject.py +++ b/owo/output/OutputObject.py @@ -10,14 +10,15 @@ import logging # 'errors': [] # } - class OutputObject: - def __init__(self, type: int): - self.OOType = [ - 'HeaderTable', 'BasicInfoTable', 'AdvancedInfoTable', 'DebugInfoTable' - ][type] - if type == 0: - import sys - self.input = {'argsRaw': sys.argv, 'streamObjects': []} - del sys + def __init__(self): + self.status = 1 + import sys + self.input = { + 'argsRaw': sys.argv, + 'streamObjects': [] + } + del sys + self.output = [] + self.errors = [] diff --git a/owo/output/owoOutputClass.py b/owo/output/owoOutputClass.py deleted file mode 100644 index 6ccbecb..0000000 --- a/owo/output/owoOutputClass.py +++ /dev/null @@ -1,10 +0,0 @@ -from .OutputObject import OutputObject -class owoOutputClass: - def newObject(self,type: int): - self.objects.push(OutputObject(type)) - def __init__(self): - self.objects=[OutputObject(0)] - # def __iter__(self): - # yield [ - # self.header - # ]+self.objects \ No newline at end of file diff --git a/owo/parseargs.py b/owo/parseargs.py deleted file mode 100644 index af81c9e..0000000 --- a/owo/parseargs.py +++ /dev/null @@ -1,2 +0,0 @@ -def parse(): - \ No newline at end of file