archiver/util.py
def cleanup_archive(archive_path, links):
    """move any incorrectly named folders to their canonical locations"""
    
    # for each folder that exists, see if we can match it up with a known good link
    # if we can, then merge the two folders (TODO: if not, move it to lost & found)

    unmatched = []
    bad_folders = []

    if not os.path.exists(archive_path):
        return

    for folder in os.listdir(archive_path):
        try:
            files = os.listdir(os.path.join(archive_path, folder))
        except NotADirectoryError:
            continue
        
        if files:
            link = find_link(folder, links)
            if link is None:
                unmatched.append(folder)
                continue
            
            if folder != link['timestamp']:
                bad_folders.append((folder, link))
        else:
            # delete empty folders
            run(['rm', '-R', os.path.join(archive_path, folder)])
    
    if bad_folders and IS_TTY and input('[!] Cleanup archive? y/[n]: ') == 'y':
        print('[!] Fixing {} improperly named folders in archive...'.format(len(bad_folders)))
        for folder, link in bad_folders:
            fix_folder_path(archive_path, folder, link)
    elif bad_folders:
        print('[!] Warning! {} folders need to be merged, fix by running bookmark archiver.'.format(len(bad_folders)))

    if unmatched:
        print('[!] Warning! {} unrecognized folders in html/archive/'.format(len(unmatched)))
        print('    '+ '\n    '.join(unmatched))
move any incorrectly named folders to their canonical locations
move any incorrectly named folders to their canonical locations
move any incorrectly named folders to their canonical locations
def cleanup_archive(archive_path, links):
    unmatched = []
    bad_folders = []
    if not os.path.exists(archive_path):
        return
    for folder in os.listdir(archive_path):
        try:
            files = os.listdir(os.path.join(archive_path, folder))
        except NotADirectoryError:
            continue
        if files:
            link = find_link(folder, links)
            if link is None:
                unmatched.append(folder)
                continue
            if folder != link['timestamp']:
                bad_folders.append((folder, link))
        else:
            run(['rm', '-R', os.path.join(archive_path, folder)])
    if bad_folders and IS_TTY and input('[!] Cleanup archive? y/[n]: ') == 'y':
        print('[!] Fixing {} improperly named folders in archive...'.format(len(bad_folders)))
        for folder, link in bad_folders:
            fix_folder_path(archive_path, folder, link)
    elif bad_folders:
        print('[!] Warning! {} folders need to be merged, fix by running bookmark archiver.'.format(len(bad_folders)))
    if unmatched:
        print('[!] Warning! {} unrecognized folders in html/archive/'.format(len(unmatched)))
        print('    '+ '\n    '.join(unmatched))
def cleanup_archive ( archive_path , links ) : unmatched = [ ] bad_folders = [ ] if not os . path . exists ( archive_path ) : return for folder in os . listdir ( archive_path ) : try : files = os . listdir ( os . path . join ( archive_path , folder ) ) except NotADirectoryError : continue if files : link = find_link ( folder , links ) if link is None : unmatched . append ( folder ) continue if folder != link [ 'timestamp' ] : bad_folders . append ( ( folder , link ) ) else : run ( [ 'rm' , '-R' , os . path . join ( archive_path , folder ) ] ) if bad_folders and IS_TTY and input ( '[!] Cleanup archive? y/[n]: ' ) == 'y' : print ( '[!] Fixing {} improperly named folders in archive...' . format ( len ( bad_folders ) ) ) for folder , link in bad_folders : fix_folder_path ( archive_path , folder , link ) elif bad_folders : print ( '[!] Warning! {} folders need to be merged, fix by running bookmark archiver.' . format ( len ( bad_folders ) ) ) if unmatched : print ( '[!] Warning! {} unrecognized folders in html/archive/' . format ( len ( unmatched ) ) ) print ( '    ' + '\n    ' . join ( unmatched ) )
move any incorrectly named folders to their canonical locations
move any incorrectly named folders to their canonical locations
"""move any incorrectly named folders to their canonical locations""" # for each folder that exists, see if we can match it up with a known good link # if we can, then merge the two folders (TODO: if not, move it to lost & found) # delete empty folders
archive_path
links