from datetime import date import os.path # # # # # # # def patch_for_debugger(kind): splitter = f'License{kind}_DontShowAgainToday="' registry = os.path.expanduser("~/.config/SEGGER/SEGGER_REG_HKEY_CURRENT_USER.xml") lines = open(registry).readlines() line3 = lines[3] before, rest = line3.split(splitter) prev_date, after = rest.split('"', 1) today = date.today() def hx(i, n): return hex(i)[2:].rjust(n, '0') year = hx(today.year, 4).upper() month = hx(today.month, 2).upper() day = hx(today.day, 2).upper() try: old_date = date( int(prev_date[:6], 16), int(prev_date[6:8], 16), int(prev_date[8:], 16), ) except ValueError: old_date = "N/a" # for safety if prev_date != "0x00000000": return new_date = f"0x{year}{month}{day}" print(f"bumping date from {prev_date} ({old_date}) -> {new_date} ({today})") lines[3] = before + splitter + new_date + '"' + after with open(registry, "w") as fh: for line in lines: # the original has this # fh.write(line[:-1]+ "\r\n") fh.write(line) for kind in ("LPCLink2", "EDUMini"): patch_for_debugger(kind)