diff --git a/komrade/cli/cli.py b/komrade/cli/cli.py index 3f6588c..7463de8 100644 --- a/komrade/cli/cli.py +++ b/komrade/cli/cli.py @@ -201,13 +201,13 @@ class CLI(Logger): ) clear_screen() print(f'@Operator: The public key of @{meet_name} has been saved as a QRcode to {fnfn}:\n{qrstr}') - if do_senduser: + if do_senduser.strip().lower()=='y': print('returning the invitation ...') res = self.komrade.meet(meet_name,returning=True) # print('got from meeting:',res) def prompt_msg(self,msg): - do = input(f'\n\n@Operator: Type "r" to reply, "d" to delete, or just hit Enter to continue.\n{self.komrade}: ') + do = input(f'\n\n@Operator: Type "r" to reply, "d" to delete, or hit Enter to continue.\n{self.komrade}: ') do=do.strip().lower() if do=='d': diff --git a/komrade/constants.py b/komrade/constants.py index 192800b..6800277 100644 --- a/komrade/constants.py +++ b/komrade/constants.py @@ -26,7 +26,10 @@ PATH_QRCODES = os.path.join(PATH_KOMRADE,'contacts') PATH_SECRETS = PATH_SUPER_SECRETS = os.path.join(PATH_USER_HOME,'.secrets') PATH_SUPER_SECRET_OP_KEY = os.path.join(PATH_SUPER_SECRETS,'.komrade.op.key') -for x in [PATH_KOMRADE,PATH_KOMRADE_DATA,PATH_KOMRADE_KEYS,PATH_QRCODES,PATH_SECRETS,PATH_SUPER_SECRETS]: +PATH_LOG_OUTPUT = os.path.join(PATH_KOMRADE,'logs') + + +for x in [PATH_KOMRADE,PATH_KOMRADE_DATA,PATH_KOMRADE_KEYS,PATH_QRCODES,PATH_SECRETS,PATH_SUPER_SECRETS,PATH_LOG_OUTPUT]: if not os.path.exists(x): os.makedirs(x) @@ -159,6 +162,8 @@ SHOW_STATUS = 0 PAUSE_LOGGER = 0 CLEAR_LOGGER = 0 +SAVE_LOGS = 1 + CLI_TITLE = 'KOMRADE' CLI_FONT = 'clr5x6'#'colossal' CLI_WIDTH = STATUS_LINE_WIDTH = 70 diff --git a/komrade/utils.py b/komrade/utils.py index 86a53e4..b9402b4 100644 --- a/komrade/utils.py +++ b/komrade/utils.py @@ -17,12 +17,19 @@ def logger(): LOG = None -def log(*x): +def log(*x,off=False): global LOG #if not LOG: LOG=logger().debug if not LOG: LOG=print tolog=' '.join(str(_) for _ in x) - LOG(tolog) + + if not off: + LOG(tolog) + + if SAVE_LOGS: + path_log = os.path.join(PATH_LOG_OUTPUT,date_today()+'.log') + with open(path_log,'a') as of: + of.write('\n'+tolog+'\n') def clear_screen(): import os @@ -80,12 +87,15 @@ class Logger(object): self.show_log() if self.off else self.hide_log() def log(self,*x,pause=PAUSE_LOGGER,clear=CLEAR_LOGGER): - if self.off: return curframe = inspect.currentframe() calframe = inspect.getouterframes(curframe, 2) mytype = type(self).__name__ caller = calframe[1][3] - log(f'[{mytype}.{caller}()]'.center(CLI_WIDTH) + '\n\n',*x) + log( + f'[{mytype}.{caller}()]'.center(CLI_WIDTH) + '\n\n', + *x, + off=self.off + ) # try: if pause: do_pause() @@ -366,4 +376,10 @@ def get_qr_str(data): def indent_str(x,n): import textwrap as tw - return tw.indent(x,' '*n) \ No newline at end of file + return tw.indent(x,' '*n) + + +def date_today(): + import datetime + dt = datetime.datetime.today() + return f'{dt.year}-{str(dt.month).zfill(2)}-{dt.day}' \ No newline at end of file