''' import kvutil import kvgmailsend import time import re import datetime import sys from socket import gethostname # logging - import kvlogger config=kvlogger.get_config(kvutil.filename_create(__file__, filename_ext='log')) kvlogger.dictConfig(config) logger=kvlogger.getLogger(__name__) # added logging feature to capture and log unhandled exceptions def handle_exception(exc_type, exc_value, exc_traceback): if issubclass(exc_type, KeyboardInterrupt): sys.__excepthook__(exc_type, exc_value, exc_traceback) return logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback)) sys.excepthook = handle_exception
def update_file_version(filename, major_update=False, test=False, debug=False): file_tmp = kvutil.filename_create(filename, filename_ext='tmp') file_bak = kvutil.filename_create(filename, filename_ext='bak') if debug: print('update_file_version:start') print('update_file_version:filename:', filename) print('update_file_version:file_bak:', file_bak) print('update_file_version:file_tmp:', file_tmp) print('update_file_version:major_update:', major_update) print('update_file_version:test:', test) app_ver = '' new_app_ver = '' version_found = False opt_ver_found = False version_changed = False with open(file_tmp, 'w') as fpOut: with open(filename, 'r') as fpIn: filelines = fpIn.readlines() for line in filelines: if version_found: if opt_ver_found: # clear the flag no matter what opt_ver_found = False # this next line should be the value line to test for it if reOptValueLine.search(line): version_changed = True fpOut.write(fmtOptValue.format(new_app_ver)) continue if reOptVerLine.search(line): opt_ver_found = True elif reAppVerLine.search(line): if debug: print('AppVerLine') print('line:', line) print('now.:', fmtAppVerLine.format(new_app_ver)) version_changed = True fpOut.write(fmtAppVerLine.format(new_app_ver)) continue elif rePgmVerLine.search(line): if debug: print('PgmVerLine') print('line:', line) print('now.:', fmtPgmVerLine.format(new_app_ver)) version_changed = True fpOut.write(fmtPgmVerLine.format(new_app_ver)) continue elif reVerLine.search(line): if debug: print('VerLine') print('line:', line) print('now.:', VerLine.format(new_app_ver)) version_changed = True fpOut.write(fmtVerLine.format(new_app_ver)) continue else: # find the first version defintion and use it to set the version for srch_idx, reSearchRegex in enumerate(reSearchList): m = reSearchRegex.search(line) if m: # app_ver = m.group(1) major_ver = int(m.group(1)) minor_ver = int(m.group(2)) app_ver = '{}.{}'.format(m.group(1), m.group(2)) if debug: print('matching line:', line) print('major_ver:', major_ver) print('minor_ver:', minor_ver) if major_update: new_major_ver = major_ver + 1 new_minor_ver = 1 else: new_major_ver = major_ver new_minor_ver = minor_ver + 1 if new_minor_ver < 100: new_app_ver = fmtVersion2d.format(new_major_ver, new_minor_ver) else: new_app_ver = fmtVersion3d.format(new_major_ver, new_minor_ver) if debug: print('major_ver-updt:', new_major_ver) print('minor_ver-updt:', new_minor_ver) print('new_app_ver:', new_app_ver) print('srch_idx:', srch_idx) print('line:', line) print('new.:', fmtSearchList[srch_idx].format(new_app_ver)) version_found = True version_changed = True fpOut.write(fmtSearchList[srch_idx].format(new_app_ver)) break if version_found: continue fpOut.write(line) if debug: print('update_file_version:version_found:', version_found) print('update_file_version:version_changed:', version_changed) print('update_file_version:test:', test) # create temp file determine if we take existing file # convert to bak and make tmp the current file if version_found and version_changed: if not test: if os.path.exists(file_bak): kvutil.remove_filename(file_bak) os.rename(filename, file_bak) os.rename(file_tmp, filename) return app_ver, new_app_ver, filename, file_bak else: return app_ver, None, None, None
import datetime import imaplib import sys import re import wineutil import time # Logging Setup import sys import kvlogger config = kvlogger.get_config( kvutil.filename_create(__file__, filename_ext='log')) kvlogger.dictConfig(config) logger = kvlogger.getLogger(__name__) # added logging feature to capture and log unhandled exceptions def handle_exception(exc_type, exc_value, exc_traceback): if issubclass(exc_type, KeyboardInterrupt): sys.__excepthook__(exc_type, exc_value, exc_traceback) return logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback)) sys.excepthook = handle_exception
import kvutil import kvargs # may comment out in the future import pprint pp = pprint.PrettyPrinter(indent=4) # logging import sys import kvlogger # pick the log file structure from list below # single file that is rotated config = kvlogger.get_config(kvutil.filename_create(__file__, filename_ext='log', path_blank=True), loggerlevel='NOTSET') # single file # one file per day of month # config=kvlogger.get_config(kvutil.filename_log_day_of_month(__file__, ext_override='log'), 'logging.FileHandler') # one file per day of month kvlogger.dictConfig(config) logger = kvlogger.getLogger(__name__) # added logging feature to capture and log unhandled exceptions def handle_exception(exc_type, exc_value, exc_traceback): if issubclass(exc_type, KeyboardInterrupt): # if this is a keyboard interrupt - we dont' want to handle it here # reset and return sys.__excepthook__(exc_type, exc_value, exc_traceback) return
import kvutil # this test program is used to validate the command line parsing and reporting # # test1: python t_kvutil2.py - it should terminate with error message # test2: python t_kvutil2.py workingdir=. alldir=1 - should run display but not terminate # test2: python t_kvutil2.py help=1 - should run display long list and terminate # # # logging - import sys import kvlogger config = kvlogger.get_config( kvutil.filename_create(__file__, filename_ext='log', path_blank=True)) kvlogger.dictConfig(config) logger = kvlogger.getLogger(__name__) # added logging feature to capture and log unhandled exceptions def handle_exception(exc_type, exc_value, exc_traceback): if issubclass(exc_type, KeyboardInterrupt): sys.__excepthook__(exc_type, exc_value, exc_traceback) return logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback)) sys.excepthook = handle_exception