archiver/util.py
def manually_merge_folders(source, target):
    """prompt for user input to resolve a conflict between two archive folders"""

    if not IS_TTY:
        return

    fname = lambda path: path.split('/')[-1]

    print('    {} and {} have conflicting files, which do you want to keep?'.format(fname(source), fname(target)))
    print('      - [enter]: do nothing (keep both)')
    print('      - a:       prefer files from {}'.format(source))
    print('      - b:       prefer files from {}'.format(target))
    print('      - q:       quit and resolve the conflict manually')
    try:
        answer = input('> ').strip().lower()
    except KeyboardInterrupt:
        answer = 'q'

    assert answer in ('', 'a', 'b', 'q'), 'Invalid choice.'

    if answer == 'q':
        print('\nJust run Bookmark Archiver again to pick up where you left off.')
        raise SystemExit(0)
    elif answer == '':
        return

    files_in_source = set(os.listdir(source))
    files_in_target = set(os.listdir(target))
    for file in files_in_source:
        if file in files_in_target:
            to_delete = target if answer == 'a' else source
            run(['rm', '-Rf', os.path.join(to_delete, file)])
        run(['mv', os.path.join(source, file), os.path.join(target, file)])

    if not set(os.listdir(source)):
        run(['rm', '-Rf', source])
prompt for user input to resolve a conflict between two archive folders
prompt for user input to resolve a conflict between two archive folders
prompt for user input to resolve a conflict between two archive folders
def manually_merge_folders(source, target):
    if not IS_TTY:
        return
    fname = lambda path: path.split('/')[-1]
    print('    {} and {} have conflicting files, which do you want to keep?'.format(fname(source), fname(target)))
    print('      - [enter]: do nothing (keep both)')
    print('      - a:       prefer files from {}'.format(source))
    print('      - b:       prefer files from {}'.format(target))
    print('      - q:       quit and resolve the conflict manually')
    try:
        answer = input('> ').strip().lower()
    except KeyboardInterrupt:
        answer = 'q'
    assert answer in ('', 'a', 'b', 'q'), 'Invalid choice.'
    if answer == 'q':
        print('\nJust run Bookmark Archiver again to pick up where you left off.')
        raise SystemExit(0)
    elif answer == '':
        return
    files_in_source = set(os.listdir(source))
    files_in_target = set(os.listdir(target))
    for file in files_in_source:
        if file in files_in_target:
            to_delete = target if answer == 'a' else source
            run(['rm', '-Rf', os.path.join(to_delete, file)])
        run(['mv', os.path.join(source, file), os.path.join(target, file)])
    if not set(os.listdir(source)):
        run(['rm', '-Rf', source])
def manually_merge_folders ( source , target ) : if not IS_TTY : return fname = lambda path : path . split ( '/' ) [ - 1 ] print ( '    {} and {} have conflicting files, which do you want to keep?' . format ( fname ( source ) , fname ( target ) ) ) print ( '      - [enter]: do nothing (keep both)' ) print ( '      - a:       prefer files from {}' . format ( source ) ) print ( '      - b:       prefer files from {}' . format ( target ) ) print ( '      - q:       quit and resolve the conflict manually' ) try : answer = input ( '> ' ) . strip ( ) . lower ( ) except KeyboardInterrupt : answer = 'q' assert answer in ( '' , 'a' , 'b' , 'q' ) , 'Invalid choice.' if answer == 'q' : print ( '\nJust run Bookmark Archiver again to pick up where you left off.' ) raise SystemExit ( 0 ) elif answer == '' : return files_in_source = set ( os . listdir ( source ) ) files_in_target = set ( os . listdir ( target ) ) for file in files_in_source : if file in files_in_target : to_delete = target if answer == 'a' else source run ( [ 'rm' , '-Rf' , os . path . join ( to_delete , file ) ] ) run ( [ 'mv' , os . path . join ( source , file ) , os . path . join ( target , file ) ] ) if not set ( os . listdir ( source ) ) : run ( [ 'rm' , '-Rf' , source ] )
prompt for user input to resolve a conflict between two archive folders
prompt for user input to resolve a conflict between two archive folders
"""prompt for user input to resolve a conflict between two archive folders"""
source
target