i ddid things
This commit is contained in:
parent
b322bcacd3
commit
0ecd2159dd
8 changed files with 90 additions and 65 deletions
|
@ -1,7 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# TODO: clean this up
|
||||||
# from . import config
|
# TODO: load datafiles. if not found, either fail or install files (maybe)?
|
||||||
from . import output
|
from .output.owoOutputClass import owoOutputClass
|
||||||
|
from . import datafiles
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -14,22 +15,17 @@ __version__ = "0.0.0-alpha0"
|
||||||
|
|
||||||
DEBUG = True
|
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:
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,8 @@ import owo
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
output=owo.main()
|
output=owo.main()
|
||||||
del owo
|
if output == None:
|
||||||
if output.__contains__('_err'):
|
print("an error might have occured...",file=sys.stderr)
|
||||||
print("an error occured!", file=sys.stderr)
|
|
||||||
if output.__contains__('_kb'):
|
|
||||||
print("interupted by keyboard")
|
|
||||||
sys.exit()
|
|
||||||
else:
|
else:
|
||||||
pass # output results
|
from yaml import dump
|
||||||
|
print(dump(output))
|
|
@ -1,6 +0,0 @@
|
||||||
confDict = {}
|
|
||||||
|
|
||||||
def loadConfig(confLocation = "$HOME/.config/owo.yaml"):
|
|
||||||
from os import path
|
|
||||||
if not path.exists(confLocation):
|
|
||||||
|
|
|
@ -2,7 +2,8 @@ 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
|
||||||
from re import search, IGNORECASE
|
import sys
|
||||||
|
import re
|
||||||
import collections.abc
|
import collections.abc
|
||||||
|
|
||||||
_config={}
|
_config={}
|
||||||
|
@ -15,7 +16,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()) if str(Path.cwd()) not in self._DIRS else None
|
str(Path().resolve())
|
||||||
],
|
],
|
||||||
'_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?)$"
|
||||||
|
@ -23,26 +24,48 @@ _LOCATIONS = {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def _updateConf(toAdd: dict):
|
def _mDC_listMatches(inp: str) -> list:
|
||||||
_config = toAdd.update(_config)
|
"\n".join(os.listdir(inp))
|
||||||
|
return re.findall(
|
||||||
|
_LOCATIONS['_YAMLCONFPATH']['_FNAME_RE'],
|
||||||
|
inp
|
||||||
|
)
|
||||||
|
|
||||||
def initConfig(path: str) -> bool:
|
def _makeDefaultConfs() -> list:
|
||||||
|
locates=[]
|
||||||
|
for x in _LOCATIONS['_YAMLCONFPATH']['_DIR']:
|
||||||
|
locates+=_mDC_listMatches(x)
|
||||||
|
return locates
|
||||||
|
|
||||||
|
def _updateConf(toAdd: dict):
|
||||||
|
_config.update(toAdd)
|
||||||
|
|
||||||
|
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:
|
||||||
if _configloaded:
|
if _configloaded:
|
||||||
return True# If config already loaded, do not reload.
|
return True# If config already loaded, do not reload.
|
||||||
else:
|
else:
|
||||||
try:
|
_toLookIn=_makeDefaultConfs()+path
|
||||||
file = Path(path)
|
for loc in _toLookIn:
|
||||||
|
_loadConfigFile(loc)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
# 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':[
|
||||||
|
@ -14,7 +18,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:
|
||||||
|
|
|
@ -10,15 +10,14 @@ import logging
|
||||||
# 'errors': []
|
# 'errors': []
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
|
||||||
class OutputObject:
|
class OutputObject:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, type: int):
|
||||||
self.status = 1
|
self.OOType = [
|
||||||
import sys
|
'HeaderTable', 'BasicInfoTable', 'AdvancedInfoTable', 'DebugInfoTable'
|
||||||
self.input = {
|
][type]
|
||||||
'argsRaw': sys.argv,
|
if type == 0:
|
||||||
'streamObjects': []
|
import sys
|
||||||
}
|
self.input = {'argsRaw': sys.argv, 'streamObjects': []}
|
||||||
del sys
|
del sys
|
||||||
self.output = []
|
|
||||||
self.errors = []
|
|
||||||
|
|
10
owo/output/owoOutputClass.py
Normal file
10
owo/output/owoOutputClass.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
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
|
2
owo/parseargs.py
Normal file
2
owo/parseargs.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
def parse():
|
||||||
|
|
Loading…
Reference in a new issue