Update to 0.0.9

This commit is contained in:
Jeffrey Serio 2022-10-03 11:59:35 -05:00
parent 7902918702
commit a8dfdba029
2 changed files with 43 additions and 15 deletions

View File

@ -3,7 +3,7 @@ from setuptools import setup, find_packages
setup( setup(
name="daily-event-logger", name="daily-event-logger",
version="0.0.8", version="0.0.9",
license="GPL-3.0", license="GPL-3.0",
author="Jeffrey Serio", author="Jeffrey Serio",
author_email="hyperreal@fedoraproject.org", author_email="hyperreal@fedoraproject.org",

View File

@ -15,7 +15,7 @@ from rich.traceback import install
install(show_locals=True) install(show_locals=True)
VERSION = "0.0.8" VERSION = "0.0.9"
default_date = dt.date.today().strftime("%Y-%m-%d") default_date = dt.date.today().strftime("%Y-%m-%d")
ELOG_DIR = os.getenv("ELOG_DIR") ELOG_DIR = os.getenv("ELOG_DIR")
@ -23,11 +23,10 @@ if ELOG_DIR is None:
elog_dir = Path("~/elogs").expanduser() elog_dir = Path("~/elogs").expanduser()
else: else:
elog_dir = Path(ELOG_DIR) elog_dir = Path(ELOG_DIR)
elog_file = elog_dir.joinpath(default_date + "_elog").with_suffix(".json")
def elog_init(): def elog_init(filename):
elog_file = elog_dir.joinpath(default_date + "_elog").with_suffix(".json") elog_file = elog_dir.joinpath(filename).with_suffix(".json")
elog_dir.mkdir(exist_ok=True) elog_dir.mkdir(exist_ok=True)
elog_file.touch() elog_file.touch()
@ -42,13 +41,15 @@ def elog_list(args):
if args.file: if args.file:
selected_elog_file = elog_dir.joinpath(args.file) selected_elog_file = elog_dir.joinpath(args.file)
else: else:
selected_elog_file = elog_file selected_elog_file = elog_dir.joinpath(default_date + "_elog").with_suffix(
".json"
)
if not selected_elog_file.exists(): if not selected_elog_file.exists():
exit("elog file %s not found. Are you sure it exists?" % selected_elog_file) exit("elog file %s not found. Are you sure it exists?" % selected_elog_file)
if not args.start: if not args.start:
ts_from = default_date + " 00:00:00" ts_from = selected_elog_file.stem[:10] + " 00:00:00"
else: else:
dt.datetime.strptime(args.start, "%Y-%m-%d %H:%M:%S") dt.datetime.strptime(args.start, "%Y-%m-%d %H:%M:%S")
ts_from = args.start ts_from = args.start
@ -145,15 +146,18 @@ def validate_json(file):
def elog_append(args): def elog_append(args):
if not elog_file.exists():
elog_init()
if not args.timestamp: if not args.timestamp:
ts = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S") ts = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
else: else:
dt.datetime.strptime(args.timestamp, "%Y-%m-%d %H:%M:%S") dt.datetime.strptime(args.timestamp, "%Y-%m-%d %H:%M:%S")
ts = args.timestamp ts = args.timestamp
elog_filename = ts[:10] + "_elog"
elog_file = elog_dir.joinpath(elog_filename).with_suffix(".json")
if not elog_file.exists():
elog_init(elog_file)
entry = {"timestamp": ts, "message": args.message} entry = {"timestamp": ts, "message": args.message}
with open(elog_file, "r+") as ef: with open(elog_file, "r+") as ef:
@ -167,6 +171,11 @@ def elog_append(args):
def elog_edit(args): def elog_edit(args):
if args.file:
elog_file = elog_dir.joinpath(args.file)
else:
elog_file = elog_dir.joinpath(default_date + "_elog").with_suffix(".json")
if not elog_file.exists(): if not elog_file.exists():
exit("elog file not found. Please run 'elog append' to start a new elog file.") exit("elog file not found. Please run 'elog append' to start a new elog file.")
@ -180,6 +189,11 @@ def elog_edit(args):
def elog_remove(args): def elog_remove(args):
if args.file:
elog_file = elog_dir.joinpath(args.file)
else:
elog_file = elog_dir.joinpath(default_date + "_elog").with_suffix(".json")
if not elog_file.exists(): if not elog_file.exists():
exit("elog file not found. Please run 'elog append' to start a new elog file.") exit("elog file not found. Please run 'elog append' to start a new elog file.")
@ -239,6 +253,14 @@ edit_parser.add_argument(
action="store", action="store",
help="New message for elog entry: str", help="New message for elog entry: str",
) )
edit_parser.add_argument(
"-f",
"--file",
required=False,
type=str,
action="store",
help="elog file to edit. Ex: 2022-10-02_elog.json",
)
edit_parser.set_defaults(func=elog_edit) edit_parser.set_defaults(func=elog_edit)
rm_parser = subparsers.add_parser("rm", description="Remove an elog entry") rm_parser = subparsers.add_parser("rm", description="Remove an elog entry")
@ -250,13 +272,21 @@ rm_parser.add_argument(
action="store", action="store",
help="Index of elog entry: int", help="Index of elog entry: int",
) )
rm_parser.add_argument(
"-f",
"--file",
required=False,
type=str,
action="store",
help="elog file to remove from. Ex: 2022-10-02_elog.json",
)
rm_parser.set_defaults(func=elog_remove) rm_parser.set_defaults(func=elog_remove)
ls_parser = subparsers.add_parser("ls", description="List elog entries") ls_parser = subparsers.add_parser("ls", description="List elog entries")
ls_parser.add_argument( ls_parser.add_argument(
"-s", "-s",
"--start", "--start",
metavar="timestamp", metavar="TIMESTAMP",
required=False, required=False,
type=str, type=str,
action="store", action="store",
@ -265,7 +295,7 @@ ls_parser.add_argument(
ls_parser.add_argument( ls_parser.add_argument(
"-e", "-e",
"--end", "--end",
metavar="timestamp", metavar="TIMESTAMP",
required=False, required=False,
type=str, type=str,
action="store", action="store",
@ -274,11 +304,10 @@ ls_parser.add_argument(
ls_parser.add_argument( ls_parser.add_argument(
"-f", "-f",
"--file", "--file",
metavar="elog file",
required=False, required=False,
type=str, type=str,
action="store", action="store",
help="elog file to view", help="elog file to view. Ex: 2022-10-02_elog.json",
) )
ls_parser.set_defaults(func=elog_list) ls_parser.set_defaults(func=elog_list)
@ -298,7 +327,6 @@ search_parser = subparsers.add_parser(
search_parser.add_argument( search_parser.add_argument(
"-w", "-w",
"--word", "--word",
metavar="<word>",
required=True, required=True,
type=str, type=str,
action="store", action="store",