Code Duplication    Length = 21-24 lines in 3 locations

bbarchivist/utilities.py 1 location

@@ 768-791 (lines=24) @@
765
    if not os.path.exists(conffile):
766
        open(conffile, 'w').close()
767
    config.read(conffile)
768
    if not config.has_section('cap'):
769
        config['cap'] = {}
770
    config['cap']['path'] = cappath
771
    with open(conffile, "w") as configfile:
772
        config.write(configfile)
773

bbarchivist/archiveutils.py 2 locations

@@ 416-439 (lines=24) @@
413
    :param homepath: Folder containing ini file. Default is user directory.
414
    :type homepath: str
415
    """
416
    config = configparser.ConfigParser()
417
    if homepath is None:
418
        homepath = os.path.expanduser("~")
419
    conffile = os.path.join(homepath, "bbarchivist.ini")
420
    if not os.path.exists(conffile):
421
        open(conffile, 'w').close()
422
    config.read(conffile)
423
    if not config.has_section('compression'):
424
        config['compression'] = {}
425
    compini = config['compression']
426
    method = compini.get('method', fallback="7z")
427
    if not utilities.new_enough(3) and method == "txz":
428
        method = "zip"  # for 3.2 compatibility
429
    return method
430
431
432
def compress_config_writer(method=None, homepath=None):
433
    """
434
    Write a ConfigParser file to store compression preferences.
435
436
    :param method: Method to use.
437
    :type method: str
438
439
    :param homepath: Folder containing ini file. Default is user directory.
440
    :type homepath: str
441
    """
442
    if method is None:
@@ 395-415 (lines=21) @@
392
393
    :param filepath: Working directory. Required.
394
    :type filepath: str
395
396
    :param method: Compression type. Default is "7z". Defined in source.
397
    :type method: str
398
399
    :param szexe: Path to 7z executable, if needed.
400
    :type szexe: str
401
402
    :param selective: Only compress autoloaders. Default is false.
403
    :type selective: bool
404
    """
405
    compress(filepath, method, szexe, selective)
406
    verify(filepath, method, szexe, selective)
407
408
409
def compress_config_loader(homepath=None):
410
    """
411
    Read a ConfigParser file to get compression preferences.
412
413
    :param homepath: Folder containing ini file. Default is user directory.
414
    :type homepath: str
415
    """
416
    config = configparser.ConfigParser()
417
    if homepath is None:
418
        homepath = os.path.expanduser("~")