From 5cbeb949ea5cd12042bb83ff2f89f065ec874d3c Mon Sep 17 00:00:00 2001 From: elburg Date: Tue, 14 Mar 2023 15:01:21 -0700 Subject: [PATCH] return of the datafiles and a lot of code reformats! --- owo/__init__.py | 27 ++++++++------- owo/__main__.py | 3 +- owo/config.py | 65 +++++++++++++++++++++++++++++++++++ owo/datafiles/__init__.py | 71 --------------------------------------- owo/parseargs.py | 2 +- pyproject.toml | 15 ++++++--- res/locale/en_US.yaml | 12 +++++++ setup.py | 16 +++++++++ 8 files changed, 120 insertions(+), 91 deletions(-) create mode 100644 owo/config.py delete mode 100644 owo/datafiles/__init__.py create mode 100644 res/locale/en_US.yaml create mode 100644 setup.py diff --git a/owo/__init__.py b/owo/__init__.py index 7326395..c1d597a 100644 --- a/owo/__init__.py +++ b/owo/__init__.py @@ -1,8 +1,9 @@ # -*- 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, parseargs import logging import sys @@ -17,15 +18,15 @@ DEBUG = 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: - + # PART 1: init + try: + out = owoOutputClass() # Prepare output object + args = parseargs.parse() + except Exception as exc: + import traceback + traceback.print_exc(exc, file=sys.stderr) + sys.exit(1) + else: + pass + + # PART 2: load config/data files diff --git a/owo/__main__.py b/owo/__main__.py index 622eab0..cb49484 100644 --- a/owo/__main__.py +++ b/owo/__main__.py @@ -8,9 +8,10 @@ if __package__ is None and not hasattr(sys, "frozen"): import owo if __name__ == "__main__": + output=owo.main() if output == None: print("an error might have occured...",file=sys.stderr) else: from yaml import dump - print(dump(output)) \ No newline at end of file + print(dump(output)) diff --git a/owo/config.py b/owo/config.py new file mode 100644 index 0000000..15eb859 --- /dev/null +++ b/owo/config.py @@ -0,0 +1,65 @@ +from pathlib import Path +from yaml import load +import os +import re + +global _config +_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()) + ], + '_FNAME_RE': + r"([ou^>]w[ou^<]|config)\.(ya?ml|c(on)?fi?g?)$" + } + +} + + +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) + + +def _loadConfigFile(path: str): + try: + file = Path(path) + + if file.exists() and not file.is_dir(): + conf = load(file.read_text()) + except Exception as exc: + raise exc + else: + _updateConf(conf) + if file not in _files: + _files.push(str(file)) + + +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) diff --git a/owo/datafiles/__init__.py b/owo/datafiles/__init__.py deleted file mode 100644 index 799190e..0000000 --- a/owo/datafiles/__init__.py +++ /dev/null @@ -1,71 +0,0 @@ -from pathlib import Path -from sys import platform -from yaml import load, dump -import os -import sys -import re -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()) - ], - '_FNAME_RE': - r"([ou^>]w[ou^<]|config)\.(ya?ml|c(on)?fi?g?)$" - } - -} - -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) - -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: - return True# If config already loaded, do not reload. - else: - _toLookIn=_makeDefaultConfs()+path - for loc in _toLookIn: - _loadConfigFile(loc) - diff --git a/owo/parseargs.py b/owo/parseargs.py index af81c9e..b6ce96f 100644 --- a/owo/parseargs.py +++ b/owo/parseargs.py @@ -1,2 +1,2 @@ def parse(): - \ No newline at end of file + diff --git a/pyproject.toml b/pyproject.toml index b0a361e..bc1bcd5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,16 +17,13 @@ keywords = [ "fetch", "sqlite3" ] -requires-python = ">=3.7" +requires-python = ">=3.10" classifiers = [ "Programming Language :: Python :: 3", "Development Status :: 1 - Planning", "Natural Language :: English", "Operating System :: POSIX :: Linux", "Programming Language :: Python", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", @@ -40,8 +37,16 @@ classifiers = [ "Topic :: System :: Networking", "Topic :: Utilities" ] +dependencies = [ + "PyYAML" +] [project.urls] "Homepage" = "https://basedwa.re/elburg/owo" "Repository" = "https://basedwa.re/elburg/owo.git" -"Bug Tracker" = "https://basedwa.re/elburg/owo/issues" \ No newline at end of file +"Bug Tracker" = "https://basedwa.re/elburg/owo/issues"i + +[project.optional-dependencies] +ALL = [ # ONLY FOR SERVERS OR BIG COMPUTERS + "yt-dlp" +] diff --git a/res/locale/en_US.yaml b/res/locale/en_US.yaml new file mode 100644 index 0000000..9798fd5 --- /dev/null +++ b/res/locale/en_US.yaml @@ -0,0 +1,12 @@ +_meta: + names: + lang: "English" + region: "United States" +data: + types: + audio: + codecs: + pcm_alaw: "A-law / G.711 A-law PCM" + pcm_s16le: "Little Endian Signed 16-bit PCM" + pcm_u16le: "Little Endian Unsigned 16-bit PCM" + pcm_s16be: "Big Endian Signed 16-bit PCM" diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..116b848 --- /dev/null +++ b/setup.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + +from setuptools import setup + +setup( + name = 'owo', + version = '0.0.0-alpha0', + description = 'tool to get information on just about everything', + author = 'arris kathery', + python_requires = '>=3.10', + packages = ['owo'], + package_dir = {'owo': 'owo'}, + package_data = {'owo': [ + 'res/locale/*.yaml' + ]} +)