diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-04-08 12:31:16 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-04-08 12:31:16 +0800 |
| commit | 183ae1e1f0371e8bd3a665b1e31e6a1284ba44e4 (patch) | |
| tree | 6a71ca8f6ad19d2c4355ad992ec32a11bc79fb2b | |
| parent | 2845da8fcbf4c6024e5c8264aab04c00c5bf26a8 (diff) | |
fixed buggs, added feathersmain
| -rw-r--r-- | __pycache__/stdlib.cpython-312.pyc | bin | 9439 -> 11019 bytes | |||
| -rwxr-xr-x | delete.py | 108 | ||||
| -rwxr-xr-x | main.py | 13 | ||||
| -rwxr-xr-x | read.py | 21 | ||||
| -rwxr-xr-x | stdlib.py | 36 | ||||
| -rwxr-xr-x | write.py | 12 |
6 files changed, 149 insertions, 41 deletions
diff --git a/__pycache__/stdlib.cpython-312.pyc b/__pycache__/stdlib.cpython-312.pyc Binary files differindex 5fbf48a..614793f 100644 --- a/__pycache__/stdlib.cpython-312.pyc +++ b/__pycache__/stdlib.cpython-312.pyc diff --git a/delete.py b/delete.py new file mode 100755 index 0000000..9528ee0 --- /dev/null +++ b/delete.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python + +from stdlib import * +from sys import argv +from datetime import datetime +from configparser import ConfigParser as config +from configparser import NoOptionError, NoSectionError +from os.path import expanduser, isfile + + +expanduser = expanduser + +# function to get config +if not isfile(f"{expanduser('~')}/.config/jlog/jlog.conf"): + raise FileNotFoundError(f"Config {expanduser('~')}/.config/jlog/jlog.conf not found") +else: + printinfo(f"Using config file {expanduser('~')}/.config/jlog/jlog.conf") +config = config() +config.read(f"{expanduser('~')}/.config/jlog/jlog.conf") +try: + log_file = config.get('global', 'file').replace('~', expanduser('~')) +except NoSectionError: + raise NoSectionError(f"Section global not found in {expanduser('~')}/.config/jlog/jlog.conf") +except NoOptionError: + log_file = f"{expanduser('~')}/.config/jlog/jlog_{datetime.now()}" +if not isfile(log_file): + printerror(f"Log file {log_file} not found") + printwarning(f"Creating new log file {log_file}") + open(log_file, 'x').close() +try: + skip_ask = config.get('global','skip_ask') + try: + skip_ask = bool(skip_ask) + except ValueError: + raise ValueError("Invalid skip asking option") +except NoSectionError: + raise NoSectionError(f"Section global not found in {expanduser('~')}/.config/jlog/jlog.conf") +except NoOptionError: + printerror(f"Option skip_ask not found in {expanduser('~')}/.config/jlog/jlog.conf") + skip_ask = False +try: + ddate = config.get('global', 'detailed_date') + try: + ddate = bool(ddate) + except ValueError: + raise ValueError("Invalid detailed_date") +except NoSectionError: + raise NoSectionError(f"Section global not found in {expanduser('~')}/.config/jlog/jlog.conf") +except NoOptionError: + ddate = False + +else: + printinfo(f"Using log file {log_file}") + +if '-sk' in argv: + skip_ask = True +elif '-dd' in argv: + ddate = True + +if not skip_ask: + try: + if askinput("continue? (y/n)").lower() != 'y': + printwarning("Reseting...") + + except AttributeError: + printwarning("Reseting...") + from os import execv + from sys import executable + execv(executable, [executable] + argv) + +def remove_line(line: int): + + + + +# main function(process) +def log_message(priority: int, message: str): + priority = convert_PRIORITY(priority) + current_date = datetime.now() + if not ddate: + return f"[{current_date.date()} {current_date.strftime('%A')} {current_date.hour:02d}:{current_date.minute:02d}] [{priority}]: {message}" + elif ddate: + return f"[{current_date}] [{priority}]: {message}" + + +# main function(ui) +def main(): + global log + priority = askinput("Priority of log messages: ") + + # check if priority is valid + message = askinput("Message to log: ") + + log = log_message(priority, message) + +if __name__ == "__main__" and not len(argv) in [2, 3, 4]: + main() +elif len(argv) in [2, 3, 4]: + global log + log = log_message(argv[1], argv[2]) +else: + exit(1) + +printinfo(f"Logging into file {log_file}") +open(log_file, 'a').write(log + '\n') + +# to delete last line: +open(log_file, 'w').writelines(open(log_file, 'r').readlines()[-1])
\ No newline at end of file @@ -1,19 +1,20 @@ #!/usr/bin/env python -from sys import argv, executable -from os import execv, path +from sys import argv +from os.path import islink, dirname, abspath +from stdlib import runutil -if path.islink(__file__): +if islink(__file__): from os import readlink file = readlink(__file__) else: file = __file__ -cwd = path.dirname(path.abspath(file)) +cwd = dirname(abspath(file)) def write(): - execv(executable, ['python3', f'{cwd}/write.py']) + runutil("write.py") def read(): - execv(executable, ['python3', f'{cwd}/read.py']) + runutil("read.py") if len(argv) > 1: if argv[1] == 'write': write() @@ -4,13 +4,12 @@ from stdlib import * from datetime import datetime from configparser import ConfigParser as config from configparser import NoOptionError, NoSectionError -from os import path +from os.path import expanduser, isfile - -expanduser = path.expanduser +expanduser = expanduser # function to get config -if not path.isfile(f"{expanduser('~')}/.config/jlog/jlog.conf"): +if not isfile(f"{expanduser('~')}/.config/jlog/jlog.conf"): raise FileNotFoundError(f"Config {expanduser('~')}/.config/jlog/jlog.conf not found") else: printinfo(f"Using config file {expanduser('~')}/.config/jlog/jlog.conf") @@ -22,7 +21,7 @@ except NoSectionError: raise NoSectionError(f"Section global not found in {expanduser('~')}/.config/jlog/jlog.conf") except NoOptionError: log_file = f"{expanduser('~')}/.config/jlog/jlog_{datetime.now()}" -if not path.isfile(log_file): +if not isfile(log_file): printerror(f"Log file {log_file} not found") raise FileNotFoundError(f"Log file {log_file} not found") else: @@ -31,12 +30,12 @@ else: def colorize(log: str) -> str: lines = log.splitlines() for i in range(len(lines)): - lines[i] = lines[i].replace('DEBUG', f"{ascii.color.lcyan}DEBUG{ascii.color.reset}") - lines[i] = lines[i].replace('INFO', f"{ascii.color.green}INFO{ascii.color.reset}") - lines[i] = lines[i].replace('WARNING', f"{ascii.color.yellow}WARNING{ascii.color.reset}") - lines[i] = lines[i].replace('ERROR', f"{ascii.color.lred}ERROR{ascii.color.reset}") - lines[i] = lines[i].replace('CRITICAL', f"{ascii.color.red}CRITICAL{ascii.color.reset}") - lines[i] = lines[i].replace('FATAL', f"{ascii.color.red}FATAL{ascii.color.reset}") + lines[i] = lines[i].replace('DEBUG', f"{ascii.color.lcyan}DEBUG{ascii.color.reset}", 1) + lines[i] = lines[i].replace('INFO', f"{ascii.color.green}INFO{ascii.color.reset}", 1) + lines[i] = lines[i].replace('WARNING', f"{ascii.color.yellow}WARNING{ascii.color.reset}", 1) + lines[i] = lines[i].replace('ERROR', f"{ascii.color.lred}ERROR{ascii.color.reset}", 1) + lines[i] = lines[i].replace('CRITICAL', f"{ascii.color.red}CRITICAL{ascii.color.reset}", 1) + lines[i] = lines[i].replace('FATAL', f"{ascii.color.red}FATAL{ascii.color.reset}", 1) return '\n'.join(lines) @@ -1,8 +1,5 @@ #!/dev/null -# imports -from argparse import ArgumentParser as arg - # text ascii codes class ascii: ### ASCII @@ -149,7 +146,7 @@ def aprintf(*value: str, interval=0.01, end=None): printf(i) if ani: sleep(interval) - if end == None: + if end is None: printf(f'{ascii.color.reset}\n') else: printf(end) @@ -171,11 +168,23 @@ def printerror(str: str, outputter=aprintf, ccolor=ascii.color.red, end=None): def ainputf(str: str, end='', ccolor=ascii.color.purple): aprintf(str, end=end) + import readline return input() +def input(*arg): + import readline + from builtins import input + return input(*arg) + def askinput(str: str, inputter=ainputf, ccolor=ascii.color.blue): return inputter(f"{ccolor}[?] {str}{ascii.color.reset}") +def keepasks(info: str, inputter=ainputf, *inputargs): + tmprespond = "" + while tmprespond == "" or tmprespond == " " or tmprespond is None or not tmprespond: + tmprespond = inputter(info, *inputargs) + return tmprespond + # animated countdown from @timeoutsec def countdown(timeoutsec: int): from time import sleep @@ -189,12 +198,6 @@ def countdown(timeoutsec: int): sleep(0.2) print(1) -def keepasks(info: str, inputter=ainputf, *inputargs): - tmprespond = "" - while tmprespond == "" or tmprespond == " " or tmprespond is None: - tmprespond = inputter(info, *inputargs) - return tmprespond - # TODO: make aloading() in threading # animated loading with @msg def aloading(msg="Loading...", stop=False): @@ -222,7 +225,6 @@ def bgexec(func, arg=False, stop=False): else: t = Thread(target=func).start() - # to give a absolutly perfect path to the location of a file or self(directory) def rpath(file: str=None) -> str: from os import path @@ -244,19 +246,19 @@ def runutil(file: str, *arg) -> any: # catch & handle signals def sigcatch(sig, error=None, sysexit=False, handler=None): from signal import signal - if handler != None: + if handler is not None: pass - elif error == None: + elif error is None: def handler(sig, stack): printerror(f"catched kill signal: {sig}") if sysexit: - import sys.exit - sys.exit(sig) + from sys import exit as sysexit + sysexit(sig) elif error: def handler(sig, stack): printerror(error) if sysexit: - sys.exit(sig) + sysexit(sig) if sig == str: from signal import sig signal(signal.sig, handler) @@ -270,4 +272,4 @@ def sigcatch(sig, error=None, sysexit=False, handler=None): if __name__ == '__main__': from stdlib import * from test import tests - tests()
\ No newline at end of file + tests() @@ -5,13 +5,13 @@ from sys import argv from datetime import datetime from configparser import ConfigParser as config from configparser import NoOptionError, NoSectionError -from os import path +from os.path import expanduser, isfile -expanduser = path.expanduser +expanduser = expanduser # function to get config -if not path.isfile(f"{expanduser('~')}/.config/jlog/jlog.conf"): +if not isfile(f"{expanduser('~')}/.config/jlog/jlog.conf"): raise FileNotFoundError(f"Config {expanduser('~')}/.config/jlog/jlog.conf not found") else: printinfo(f"Using config file {expanduser('~')}/.config/jlog/jlog.conf") @@ -23,7 +23,7 @@ except NoSectionError: raise NoSectionError(f"Section global not found in {expanduser('~')}/.config/jlog/jlog.conf") except NoOptionError: log_file = f"{expanduser('~')}/.config/jlog/jlog_{datetime.now()}" -if not path.isfile(log_file): +if not isfile(log_file): printerror(f"Log file {log_file} not found") printwarning(f"Creating new log file {log_file}") open(log_file, 'x').close() @@ -61,9 +61,7 @@ if not skip_ask: try: if askinput("continue? (y/n)").lower() != 'y': printwarning("Reseting...") - from os import execv - from sys import executable - execv(executable, [executable] + argv) + except AttributeError: printwarning("Reseting...") from os import execv |
