moving data to new repo

This commit is contained in:
elburg 2023-03-03 18:29:39 -08:00
parent 8d2bb67499
commit c94e713b1d
3 changed files with 78 additions and 37 deletions

View file

@ -14,7 +14,6 @@ __version__ = "0.0.0-alpha0"
def main() -> dict: def main() -> dict:
out=output.OutputObject() out=output.OutputObject()
try: try:

View file

@ -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={} _config={}
_files=[] _files=[]
_configloaded = False
_locations={ _LOCATIONS = {
'_yamlmainconf':[ '_YAMLCONFPATH':{
# Check current dir '_DIR':[
'./owo.yaml', "{}/owo/".format(os.environ["XDG_CONFIG_HOME"]) if "XDG_CONFIG_HOME" in os.environ else str(Path.home())+"/.config/owo/",
'./owo.yml', "{}/".format(os.environ["XDG_CONFIG_HOME"]) if "XDG_CONFIG_HOME" in os.environ else str(Path.home())+"/.config/",
'./owo.conf', str(Path('~').resolve()),
'./owo.cfg', str(Path().resolve()) if str(Path.cwd()) not in self._DIRS else None
'./.owo.yaml', ],
'./.owo.yml', '_FNAME_RE':
'./.owo.conf', r"([ou^>]w[ou^<]|config)\.(ya?ml|c(on)?fi?g?)$"
'./.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 def _updateConf(toAdd: dict):
for key, value in toAdd.items():
if isinstance(value, collections.abc.Mapping):
_locations._yamlmainconf+={ def _loadYAMLConf(path: str):
'linux':[ try:
'{env.HOME}/owo.yaml', conf = yaml.load(file.read_text())
'{env.HOME}/owo.yml', except Exception as exc:
'{env.HOME}/owo.conf', # do an err
'{env.HOME}/owo.cfg', else:
'{env.HOME}/.owo.yaml', if not _config:
'{env.HOME}/.owo.yml', _config = conf
'{env.HOME}/.owo.conf', else:
'{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

31
src/format.py Normal file
View 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)