things
This commit is contained in:
parent
c94e713b1d
commit
c9b97a5f97
10 changed files with 199 additions and 0 deletions
35
owo/__init__.py
Normal file
35
owo/__init__.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# from . import config
|
||||
from . import output
|
||||
import logging
|
||||
import sys
|
||||
|
||||
__author__ = "arris kathery"
|
||||
__copyright__ = "copyright 2023 brendan berger"
|
||||
__license__ = ""
|
||||
__maintainer__ = "arris kathery"
|
||||
__email__ = "whotookelburg@hotmail.com"
|
||||
__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}
|
||||
|
24
owo/__main__.py
Normal file
24
owo/__main__.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import sys
|
||||
|
||||
if __package__ is None and not hasattr(sys, "frozen"):
|
||||
import os.path
|
||||
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, os.path.realpath(path))
|
||||
|
||||
import owo
|
||||
|
||||
if __name__ == "__main__":
|
||||
output=owo.main()
|
||||
del owo
|
||||
if output.__contains__('_err'):
|
||||
#from yaml import dump
|
||||
#print("exception! check stderr!!")
|
||||
#print(dump(output),file=sys.stderr)
|
||||
from json import dumps
|
||||
print(dumps(output))
|
||||
sys.exit(1)
|
||||
if output.__contains__('_kb'):
|
||||
print("interupted by keyboard")
|
||||
sys.exit()
|
||||
else:
|
||||
pass # output results
|
6
owo/config.py
Normal file
6
owo/config.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
confDict = {}
|
||||
|
||||
def loadConfig(confLocation = "$HOME/.config/owo.yaml"):
|
||||
from os import path
|
||||
if not path.exists(confLocation):
|
||||
|
48
owo/datafiles/__init__.py
Normal file
48
owo/datafiles/__init__.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
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 = {
|
||||
'_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?)$"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
def _updateConf(toAdd: dict):
|
||||
_config = toAdd.update(_config)
|
||||
|
||||
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:
|
||||
raise exc
|
||||
else:
|
||||
if not _config:
|
||||
_config = conf
|
||||
else:
|
||||
_updateConf(conf)
|
||||
if file not in _files:
|
||||
_files+str(file)
|
||||
|
31
owo/format.py
Normal file
31
owo/format.py
Normal file
|
@ -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)
|
24
owo/output/OutputObject.py
Normal file
24
owo/output/OutputObject.py
Normal file
|
@ -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 = []
|
1
owo/output/__init__.py
Normal file
1
owo/output/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from . import OutputObject
|
0
owo/source/__init__.py
Normal file
0
owo/source/__init__.py
Normal file
10
owo/source/network/DownloadJob.py
Normal file
10
owo/source/network/DownloadJob.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from .NetworkPath import NetworkPath
|
||||
from ...config.datafiles.owoDataFile import owoDataFile
|
||||
from ...config import moduleConfig
|
||||
|
||||
class DownloadJob:
|
||||
|
||||
def __init__(self,
|
||||
url: NetworkPath,
|
||||
engine: string = moduleConfig.source.network.engine,
|
||||
engineConfig: dict = moduleConfig.source.network.engineConfig
|
20
scripts/test_debug.sh
Normal file
20
scripts/test_debug.sh
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
date="$(date +%Y-%j-%H-%M-%S)"
|
||||
|
||||
python_args="-d -v"
|
||||
owo_args=""
|
||||
|
||||
_rst=$PWD
|
||||
dir=".debug/runs/$date"
|
||||
mkdir -p $dir
|
||||
|
||||
touch $dir/stdout.term
|
||||
touch $dir/stderr.term
|
||||
|
||||
python3 $python_args owo/__main__.py $owo_args > $dir/stdout.term 2> $dir/stderr.term
|
||||
|
||||
7z a -m0=LZMA2 -mx9 -sdel -ssw -t7z -- $dir.7z $dir/*
|
||||
rm -rfv $dir
|
||||
|
||||
printf "done"
|
Loading…
Reference in a new issue