예제 #1
0
def _import(destination, source, file, album_from_folder, trash,
            allow_duplicates, debug, paths, move):
    """Import files or directories by reading their EXIF and organizing them accordingly.
    """
    constants.debug = debug
    has_errors = False
    result = Result()
    move = move
    destination = _decode(destination)
    destination = os.path.abspath(os.path.expanduser(destination))

    files = set()
    paths = set(paths)
    if source:
        source = _decode(source)
        paths.add(source)
    if file:
        paths.add(file)
    for path in paths:
        path = os.path.expanduser(path)
        if os.path.isdir(path):
            files.update(FILESYSTEM.get_all_files(path, None))
        else:
            files.add(path)

    for current_file in files:
        dest_path = import_file(current_file, destination, album_from_folder,
                                trash, allow_duplicates, move)
        result.append((current_file, dest_path))
        has_errors = has_errors is True or not dest_path

    result.write()

    if has_errors:
        sys.exit(1)
예제 #2
0
def _import(destination, source, file, album_from_folder, trash, paths,
            allow_duplicates):
    """Import files or directories by reading their EXIF and organizing them accordingly.
    """
    result = Result()

    destination = _decode(destination)
    destination = os.path.abspath(os.path.expanduser(destination))

    files = set()
    paths = set(paths)
    if source:
        source = _decode(source)
        paths.add(source)
    if file:
        paths.add(file)
    for path in paths:
        path = os.path.expanduser(path)
        if os.path.isdir(path):
            files.update(FILESYSTEM.get_all_files(path, None))
        else:
            files.add(path)

    for current_file in files:
        dest_path = import_file(current_file, destination, album_from_folder,
                                trash, allow_duplicates)
        result.append((current_file, dest_path))

    result.write()
예제 #3
0
파일: elodie.py 프로젝트: evanjt/elodie
def _import(destination, source, file, album_from_folder, trash,
            allow_duplicates, debug, exclude_regex, paths):
    """Import files or directories by reading their EXIF and organizing them accordingly.
    """
    constants.debug = debug
    has_errors = False
    result = Result()

    destination = _decode(destination)
    destination = os.path.abspath(os.path.expanduser(destination))

    files = set()
    paths = set(paths)
    if source:
        source = _decode(source)
        paths.add(source)
    if file:
        paths.add(file)

    # if no exclude list was passed in we check if there's a config
    if len(exclude_regex) == 0:
        config = load_config()
        if 'Exclusions' in config:
            exclude_regex = [
                value for key, value in config.items('Exclusions')
            ]

    exclude_regex_list = set(exclude_regex)

    for path in paths:
        path = os.path.expanduser(path)
        if os.path.isdir(path):
            files.update(
                FILESYSTEM.get_all_files(path, None, exclude_regex_list))
        else:
            if not FILESYSTEM.should_exclude(path, exclude_regex_list, True):
                files.add(path)

    for current_file in files:
        dest_path = import_file(current_file, destination, album_from_folder,
                                trash, allow_duplicates)
        result.append((current_file, dest_path))
        has_errors = has_errors is True or not dest_path

    result.write()

    if has_errors:
        sys.exit(1)
예제 #4
0
파일: elodie.py 프로젝트: gmoorevt/elodie2
def _watch(destination, album_from_folder, trash, allow_duplicates, debug,
           path):
    """Watch directory and import files or directories by reading their EXIF and organizing them accordingly.
    """

    constants.debug = debug

    destination = _decode(destination)
    destination = os.path.abspath(os.path.expanduser(destination))

    OPTIONS['destination'] = destination
    if album_from_folder:
        OPTIONS['album_from_folder'] = album_from_folder
    if trash:
        OPTIONS['trash'] = trash
    if allow_duplicates:
        OPTIONS['allow_duplicates'] = allow_duplicates
    if debug:
        OPTIONS['debug'] = debug

    path = os.path.abspath(os.path.expanduser(path))
    print(path)

    if os.path.isdir(path):
        w = Watcher(path, OPTIONS)
        w.run()

    else:
        print("%s is not a directory" % (path))
        logging.warning("%s is not a directory" % (path))
예제 #5
0
def main(argv):
    filesystem = FileSystem()
    result = Result()
    subclasses = get_all_subclasses()

    paths = argv[1:]

    for path in paths:
        path = os.path.expanduser(path)
        if os.path.isdir(path):
            for source in filesystem.get_all_files(path, None):
                status = add_original_name(source, subclasses)
                result.append((_decode(source), status))
        else:
            status = add_original_name(path, subclasses)
            result.append((_decode(path), status))

    result.write()
예제 #6
0
파일: elodie.py 프로젝트: evanjt/elodie
def import_file(_file, destination, album_from_folder, trash,
                allow_duplicates):

    _file = _decode(_file)
    destination = _decode(destination)
    """Set file metadata and move it to destination.
    """
    if not os.path.exists(_file):
        log.warn('Could not find %s' % _file)
        log.all('{"source":"%s", "error_msg":"Could not find %s"}' %
                (_file, _file))
        return
    # Check if the source, _file, is a child folder within destination
    elif destination.startswith(
            os.path.abspath(os.path.dirname(_file)) + os.sep):
        log.all(
            '{"source": "%s", "destination": "%s", "error_msg": "Source cannot be in destination"}'
            % (_file, destination))
        return

    media = Media.get_class_by_file(_file, get_all_subclasses())
    if not media:
        log.warn('Not a supported file (%s)' % _file)
        log.all('{"source":"%s", "error_msg":"Not a supported file"}' % _file)
        return

    if album_from_folder:
        media.set_album_from_folder()

    dest_path = FILESYSTEM.process_file(_file,
                                        destination,
                                        media,
                                        allowDuplicate=allow_duplicates,
                                        move=False)
    if dest_path:
        log.all('%s -> %s' % (_file, dest_path))
    if trash:
        send2trash(_file)

    return dest_path or None