From d09aaf67315f115e4284babba0bc0426bb908a76 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Tue, 11 Oct 2022 12:17:06 -0500 Subject: [PATCH] Update to 0.0.13; use Halloween colors --- setup.py | 2 +- src/elog/elog.py | 52 +++++++++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/setup.py b/setup.py index 8fbcf71..3d29233 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup( name="daily-event-logger", - version="0.0.10", + version="0.0.13", license="GPL-3.0", author="Jeffrey Serio", author_email="hyperreal@fedoraproject.org", diff --git a/src/elog/elog.py b/src/elog/elog.py index 29e9c0a..6691444 100755 --- a/src/elog/elog.py +++ b/src/elog/elog.py @@ -15,7 +15,7 @@ from rich.traceback import install install(show_locals=True) -VERSION = "0.0.10" +VERSION = "0.0.13" default_date = dt.date.today().strftime("%Y-%m-%d") ELOG_DIR = os.getenv("ELOG_DIR") @@ -26,8 +26,11 @@ else: def elog_init(filename): - """Initializes elog file and directory (if necessary)""" + """Initialize elog file and directory, if necessary. + elog_dir is taken from the current shell's ELOG_DIR environment variable, or else it defaults to + ~/elogs. + """ elog_file = elog_dir.joinpath(filename).with_suffix(".json") elog_dir.mkdir(exist_ok=True) @@ -40,8 +43,10 @@ def elog_init(filename): def elog_list(args): - """List elog entries for provided timestamp range and/or elog file""" + """List elog entries. + Lists elog entries for provided timestamp range and/or elog file + """ if args.file: selected_elog_file = elog_dir.joinpath(args.file) else: @@ -67,22 +72,24 @@ def elog_list(args): with open(selected_elog_file, "r") as ef: json_data = json.load(ef) - table = Table(style="yellow", header_style="bold", box=box.ROUNDED) - table.add_column("Index", justify="right", style="magenta") - table.add_column("Timestamp", justify="left", style="dim") + table = Table(style="#8700ff", header_style="bold", box=box.ROUNDED) + table.add_column("Index", justify="right", style="#ffff00") + table.add_column("Timestamp", justify="left", style="#ff8700") table.add_column("Message", justify="left") for i in range(len(json_data)): if json_data[i]["timestamp"] > ts_from and json_data[i]["timestamp"] < ts_to: table.add_row(str(i), json_data[i]["timestamp"], json_data[i]["message"]) - console = Console() + console = Console(color_system="256") console.print(table) def elog_list_files(args): - """Lists all elog files in elog directory""" + """List all elog files. + Lists all elog files currently present in elog directory. + """ for file in sorted(elog_dir.iterdir()): if file.is_file(): if args.absolute: @@ -92,8 +99,10 @@ def elog_list_files(args): def elog_search(args): - """Search for a string in all elog files and print the result.""" + """Search for a string. + Searches all elog files and prints found matches. + """ found_entries = list() elog_list = [file.name for file in elog_dir.iterdir()] @@ -122,8 +131,10 @@ def elog_search(args): def elog_sort(file): - """Sort elog entries by timestamp in provided `file`""" + """Sort elog entries. + Entries are sorted by provided timestamp. + """ with open(file, "r") as ef: json_data = json.load(ef) json_data.sort( @@ -137,8 +148,10 @@ def elog_sort(file): def validate_json(file): - """Validate JSON data in provided `file`""" + """Validate JSON data. + Call jsonschema.validate on `file`. + """ elog_schema = { "type": "array", "properties": { @@ -159,10 +172,10 @@ def validate_json(file): def elog_append(args): """ - Append a new elog entry to the elog file indicated by provided timestamp. - Else append to the elog file for current day - """ + Append a new elog entry to the elog file. + Use elog file indicated by provided timestamp, or else use the elog file for current day. + """ if not args.timestamp: ts = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S") else: @@ -188,8 +201,7 @@ def elog_append(args): def elog_edit(args): - """Edit elog entry at provided index argument""" - + """Edit elog entry at provided index argument.""" if args.file: elog_file = elog_dir.joinpath(args.file) else: @@ -208,8 +220,7 @@ def elog_edit(args): def elog_remove(args): - """Remove an elog entry at provided index argument""" - + """Remove an elog entry at provided index argument.""" if args.file: elog_file = elog_dir.joinpath(args.file) else: @@ -357,6 +368,11 @@ search_parser.set_defaults(func=elog_search) def main(): + """Parse command line arguments and run desired function. + + Checks if the number of arguments provided at the command line is less than the required number, + and if so, it prints the usage message. + """ if len(sys.argv) < 2: parser.print_usage() else: