| @@ 488-506 (lines=19) @@ | ||
| 485 | raise SystemExit |
|
| 486 | ||
| 487 | ||
| 488 | def gpg_config_loader(homepath=None): |
|
| 489 | """ |
|
| 490 | Read a ConfigParser file to get PGP key, password (optional) |
|
| 491 | ||
| 492 | :param homepath: Folder containing ini file. Default is user directory. |
|
| 493 | :type homepath: str |
|
| 494 | """ |
|
| 495 | config = configparser.ConfigParser() |
|
| 496 | if homepath is None: |
|
| 497 | homepath = os.path.expanduser("~") |
|
| 498 | conffile = os.path.join(homepath, "bbarchivist.ini") |
|
| 499 | if not os.path.exists(conffile): |
|
| 500 | open(conffile, 'w').close() |
|
| 501 | config.read(conffile) |
|
| 502 | if not config.has_section('gpgrunner'): |
|
| 503 | config['gpgrunner'] = {} |
|
| 504 | gpgkey = config.get('gpgrunner', 'key', fallback=None) |
|
| 505 | gpgpass = config.get('gpgrunner', 'pass', fallback=None) |
|
| 506 | return gpgkey, gpgpass |
|
| 507 | ||
| 508 | ||
| 509 | def gpg_config_writer(key=None, password=None, homepath=None): |
|
| @@ 668-685 (lines=18) @@ | ||
| 665 | ||
| 666 | def prep_logfile(): |
|
| 667 | """ |
|
| 668 | Prepare log file, labeling it with current date. Select folder based on frozen status. |
|
| 669 | """ |
|
| 670 | logfile = "{0}.txt".format(time.strftime("%Y_%m_%d_%H%M%S")) |
|
| 671 | root = os.getcwd() if getattr(sys, 'frozen', False) else os.path.expanduser("~") |
|
| 672 | basefolder = os.path.join(root, "lookuplogs") |
|
| 673 | os.makedirs(basefolder, exist_ok=True) |
|
| 674 | record = os.path.join(basefolder, logfile) |
|
| 675 | open(record, "w").close() |
|
| 676 | return record |
|
| 677 | ||
| 678 | ||
| 679 | def prepends(file, pre, suf): |
|
| 680 | """ |
|
| 681 | Check if filename starts with/ends with stuff. |
|
| 682 | ||
| 683 | :param file: File to check. |
|
| 684 | :type file: str |
|
| 685 | ||
| 686 | :param pre: Prefix(es) to check. |
|
| 687 | :type pre: str or list or tuple |
|
| 688 | ||