Example #1
0
    def watch_photos(self, paths):
        for path in paths:
            print(path)
            # TODO: Work out how to watch multiple paths at once
            i = inotify.adapters.InotifyTree(path.encode('utf-8'))

            for event in i.event_gen():
                if event is not None:
                    (header, type_names, watch_path, filename) = event
                    # if set(type_names).intersection(['IN_CLOSE_WRITE', 'IN_DELETE', 'IN_MOVED_FROM', 'IN_MOVED_TO']):  # TODO: Make moving photos really efficient by using the 'from' path
                    if set(type_names).intersection(['IN_CLOSE_WRITE', 'IN_DELETE', 'IN_MOVED_TO']):
                        photo_path = '{}/{}'.format(watch_path.decode('utf-8'), filename.decode('utf-8'))
                        record_photo(photo_path)
Example #2
0
def import_photos_in_place(orig):
    imported = 0
    were_bad = 0

    for r, d, f in os.walk(orig):
        for fn in sorted(f):
            filepath = os.path.join(r, fn)
            if os.path.getsize(filepath) < 102400:
                print(
                    'FILE VERY SMALL (<100k - PROBABLY THUMBNAIL), NOT IMPORTING {}'
                    .format(filepath))
                were_bad += 1
            else:
                modified = record_photo(filepath)
                if modified:
                    imported += 1
                    print('IMPORTED  {}'.format(filepath))

    if imported:
        print('\n{} PHOTOS IMPORTED\n{} WERE BAD'.format(imported, were_bad))
def photo_fixture_snow(db):
    from photos.utils.db import record_photo
    snow_path = str(Path(__file__).parent / 'photos' / 'snow.jpg')
    return record_photo(snow_path)
def photo_fixture_tree(db):
    from photos.utils.db import record_photo
    tree_path = str(Path(__file__).parent / 'photos' / 'tree.jpg')
    return record_photo(tree_path)
Example #5
0
def import_photos_from_dir(orig, move=False):
    imported = 0
    were_duplicates = 0
    were_bad = 0

    for r, d, f in os.walk(orig):
        for fn in sorted(f):
            filepath = os.path.join(r, fn)
            dest = determine_destination(filepath)
            if not dest:
                # No filters match this file type
                pass
            elif os.path.getsize(filepath) < 102400:
                print(
                    'FILE VERY SMALL (<100k - PROBABLY THUMBNAIL), NOT IMPORTING {}'
                    .format(filepath))
                were_bad += 1
            else:
                t = get_datetime(filepath)
                if t:
                    destpath = '%02d/%02d/%02d' % (t.year, t.month, t.day)
                    destpath = os.path.join(dest, destpath)
                    mkdir_p(destpath)
                    destpath = os.path.join(destpath, fn)

                    if filepath == destpath:
                        # File is already in the right place so be very careful not to do anything like delete it
                        pass
                    elif not os.path.exists(destpath):
                        if move:
                            shutil.move(filepath, destpath)
                        else:
                            shutil.copyfile(filepath, destpath)
                        record_photo(destpath)
                        imported += 1
                        print('IMPORTED  {} -> {}'.format(filepath, destpath))
                    else:
                        print('PATH EXISTS  {} -> {}'.format(
                            filepath, destpath))
                        same = determine_same_file(filepath, destpath)
                        print('PHOTO IS THE SAME')
                        if same:
                            if move:
                                os.remove(filepath)
                                were_duplicates += 1
                                print('DELETED FROM SOURCE')
                        else:
                            print('NEED TO IMPORT UNDER DIFFERENT NAME')
                            exit(1)
                            destpath = find_new_file_name(destpath)
                            shutil.move(filepath, destpath)
                            record_photo(destpath)
                            imported += 1
                            # print 'IMPORTED  {} -> {}'.format(filepath, destpath)

                else:
                    print('ERROR READING DATE: {}'.format(filepath))
                    were_bad += 1

    if imported or were_duplicates:
        print('\n{} PHOTOS IMPORTED\n{} WERE DUPLICATES\n{} WERE BAD'.format(
            imported, were_duplicates, were_bad))