archiver/util.py
def fix_folder_path(archive_path, link_folder, link):
    """given a folder, merge it to the canonical 'correct' path for the given link object"""
    source = os.path.join(archive_path, link_folder)
    target = os.path.join(archive_path, link['timestamp'])

    url_in_folder = parse_url(source)
    if not (url_in_folder in link['base_url']
            or link['base_url'] in url_in_folder):
        raise ValueError('The link does not match the url for this folder.')

    if not os.path.exists(target):
        # target doesn't exist so nothing needs merging, simply move A to B
        run(['mv', source, target])
    else:
        # target folder exists, check for conflicting files and attempt manual merge
        files_in_source = set(os.listdir(source))
        files_in_target = set(os.listdir(target))
        conflicting_files = files_in_source & files_in_target

        if not conflicting_files:
            for file in files_in_source:
                run(['mv', os.path.join(source, file), os.path.join(target, file)])

    if os.path.exists(source):
        files_in_source = set(os.listdir(source))
        if files_in_source:
            manually_merge_folders(source, target)
        else:
            run(['rm', '-R', source])
given a folder, merge it to the canonical 'correct' path for the given link object
given a folder, merge it to the canonical 'correct' path for the given link object
given a folder merge it to the canonical ' correct ' path for the given link object
def fix_folder_path(archive_path, link_folder, link):
    source = os.path.join(archive_path, link_folder)
    target = os.path.join(archive_path, link['timestamp'])
    url_in_folder = parse_url(source)
    if not (url_in_folder in link['base_url']
            or link['base_url'] in url_in_folder):
        raise ValueError('The link does not match the url for this folder.')
    if not os.path.exists(target):
        run(['mv', source, target])
    else:
        files_in_source = set(os.listdir(source))
        files_in_target = set(os.listdir(target))
        conflicting_files = files_in_source & files_in_target
        if not conflicting_files:
            for file in files_in_source:
                run(['mv', os.path.join(source, file), os.path.join(target, file)])
    if os.path.exists(source):
        files_in_source = set(os.listdir(source))
        if files_in_source:
            manually_merge_folders(source, target)
        else:
            run(['rm', '-R', source])
def fix_folder_path ( archive_path , link_folder , link ) : source = os . path . join ( archive_path , link_folder ) target = os . path . join ( archive_path , link [ 'timestamp' ] ) url_in_folder = parse_url ( source ) if not ( url_in_folder in link [ 'base_url' ] or link [ 'base_url' ] in url_in_folder ) : raise ValueError ( 'The link does not match the url for this folder.' ) if not os . path . exists ( target ) : run ( [ 'mv' , source , target ] ) else : files_in_source = set ( os . listdir ( source ) ) files_in_target = set ( os . listdir ( target ) ) conflicting_files = files_in_source & files_in_target if not conflicting_files : for file in files_in_source : run ( [ 'mv' , os . path . join ( source , file ) , os . path . join ( target , file ) ] ) if os . path . exists ( source ) : files_in_source = set ( os . listdir ( source ) ) if files_in_source : manually_merge_folders ( source , target ) else : run ( [ 'rm' , '-R' , source ] )
given a folder, merge it to the canonical 'correct' path for the given link object
given a folder merge it to the canonical ' correct ' path for the given link object
"""given a folder, merge it to the canonical 'correct' path for the given link object""" # target doesn't exist so nothing needs merging, simply move A to B # target folder exists, check for conflicting files and attempt manual merge
archive_path
link_folder
link