Exemplo n.º 1
0
def import_file(from_path, date, home, index, dry_run, mv):
    ym = date[:7]
    dir = path.join(home, ym, date)
    to_path = path.join(dir, path.basename(from_path))
    rel_path = path.relpath(to_path, home)

    logging.info('importing %s to %s (date %s)' % (from_path, rel_path, date))
    if dry_run: return

    if not path.exists(dir):
        makedirs(dir)
    if mv:
        move(from_path, dir)
    else:
        copy(from_path, dir)

    original_path = autorotate(to_path)
    if original_path:
        logging.info('auto rotated %s. original at %s' % (to_path, original_path))
        md5_original = md5(original_path)
    else:
        md5_original = None
    
    mtime, size = stat(to_path)
    index.add(from_path, rel_path, md5(to_path), mtime, size, date,
              md5_original=md5_original)
Exemplo n.º 2
0
from lib.index import Index
from lib.image_utils import autorotate
from lib.fs_utils import stat, md5

with open('errors.txt', 'w') as errors:
    with Index('/Volumes/Passport/pictures-backup/pictures.db', autocommit=True) as index:
        all = index.get()

        for i, a in enumerate(sorted(all, key=lambda p: p['path'])):
            if i % 100 == 99: print i, '/', len(all), '..', a['path']
            pth = '/Volumes/Passport/pictures-backup/' + a['path']
            try:
                if autorotate(pth):
                    mtime, size = stat(pth)
                    hash = md5(pth)
                    index.set(a['rowid'], mtime=mtime, filesize=size, md5=hash)
                    print 'updated', pth
            except:
                errors.write('%s\n' % pth.encode('utf-8'))