Compare commits

..

No commits in common. "0ecd2159dde5fa5edef1d60d34c2d476155b07af" and "2c7fd18651bae87eb2dbe978db1745a8baed4610" have entirely different histories.

9 changed files with 64 additions and 96 deletions

7
.gitignore vendored
View file

@ -160,10 +160,3 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/
# replit
.replit
venv/
replit.nix
.upm/
.cache/
.config/

View file

@ -1,8 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# TODO: clean this up
# TODO: load datafiles. if not found, either fail or install files (maybe)? # from . import config
from .output.owoOutputClass import owoOutputClass from . import output
from . import datafiles
import logging import logging
import sys import sys
@ -15,17 +14,22 @@ __version__ = "0.0.0-alpha0"
DEBUG = True DEBUG = True
def main() -> dict:
def main() -> owoOutputClass:
# PART 1: init
try: try:
out = owoOutputClass() out=output.OutputObject()
except Exception as exc: except Exception as exc:
import traceback return {
traceback.print_exc(exc, file=sys.stderr) '_err':True,
sys.exit(1) 'exception':exc,
else: 'vars':{
pass 'globals': globals(),
# PART 2: load config/data files 'locals': locals(),
'dir': dir()
}
}
try: try:
pass
# do shit
except KeyboardInterrupt:
return {'_kbi':True}

View file

@ -9,8 +9,11 @@ import owo
if __name__ == "__main__": if __name__ == "__main__":
output=owo.main() output=owo.main()
if output == None: del owo
print("an error might have occured...",file=sys.stderr) if output.__contains__('_err'):
print("an error occured!", file=sys.stderr)
if output.__contains__('_kb'):
print("interupted by keyboard")
sys.exit()
else: else:
from yaml import dump pass # output results
print(dump(output))

6
owo/config.py Normal file
View file

@ -0,0 +1,6 @@
confDict = {}
def loadConfig(confLocation = "$HOME/.config/owo.yaml"):
from os import path
if not path.exists(confLocation):

View file

@ -2,8 +2,7 @@ from pathlib import Path
from sys import platform from sys import platform
from yaml import load, dump from yaml import load, dump
import os import os
import sys from re import search, IGNORECASE
import re
import collections.abc import collections.abc
_config={} _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/", "{}/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/", "{}/".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()) str(Path().resolve()) if str(Path.cwd()) not in self._DIRS else None
], ],
'_FNAME_RE': '_FNAME_RE':
r"([ou^>]w[ou^<]|config)\.(ya?ml|c(on)?fi?g?)$" r"([ou^>]w[ou^<]|config)\.(ya?ml|c(on)?fi?g?)$"
@ -24,23 +23,13 @@ _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): def _updateConf(toAdd: dict):
_config.update(toAdd) _config = toAdd.update(_config)
def _loadConfigFile(path: str): def initConfig(path: str) -> bool:
if _configloaded:
return True# If config already loaded, do not reload.
else:
try: try:
file = Path(path) file = Path(path)
@ -56,16 +45,4 @@ def _loadConfigFile(path: str):
_updateConf(conf) _updateConf(conf)
if file not in _files: if file not in _files:
_files+str(file) _files+str(file)
except Exception as exc:
print(exc)
import traceback
traceback.print_exc(file=sys.stderr)
def initConfig(path: str = None) -> bool:
if _configloaded:
return True# If config already loaded, do not reload.
else:
_toLookIn=_makeDefaultConfs()+path
for loc in _toLookIn:
_loadConfigFile(loc)

View file

@ -1,7 +1,3 @@
# TODO: clean this up
# TODO: complete dateFormat()
# TODO: complete stringFormat()
_DEFAULT = { _DEFAULT = {
'_DATETEMP':'%a, %d %b %Y %H:%M:%S %Z%z', '_DATETEMP':'%a, %d %b %Y %H:%M:%S %Z%z',
'_INCLUDE':[ '_INCLUDE':[
@ -18,7 +14,7 @@ def dateFormat(input: str = _DEFAULT._DATETEMP,use_local:bool=True) -> str:
from time import gmtime from time import gmtime
return strftime(input,gmtime()) return strftime(input,gmtime())
def stringFormat( def stringformat(
input: str, input: str,
include: list = _DEFAULT._INCLUDE include: list = _DEFAULT._INCLUDE
) -> str: ) -> str:

View file

@ -10,14 +10,15 @@ import logging
# 'errors': [] # 'errors': []
# } # }
class OutputObject: class OutputObject:
def __init__(self, type: int): def __init__(self):
self.OOType = [ self.status = 1
'HeaderTable', 'BasicInfoTable', 'AdvancedInfoTable', 'DebugInfoTable'
][type]
if type == 0:
import sys import sys
self.input = {'argsRaw': sys.argv, 'streamObjects': []} self.input = {
'argsRaw': sys.argv,
'streamObjects': []
}
del sys del sys
self.output = []
self.errors = []

View file

@ -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

View file

@ -1,2 +0,0 @@
def parse():