Code Duplication    Length = 36-36 lines in 2 locations

elodie/elodie.py 1 location

@@ 36-71 (lines=36) @@
33
FILESYSTEM = FileSystem()
34
35
36
def import_file(_file, destination, album_from_folder, trash, allow_duplicates):
37
    
38
    _file = _decode(_file)
39
    destination = _decode(destination)
40
41
    """Set file metadata and move it to destination.
42
    """
43
    if not os.path.exists(_file):
44
        log.warn('Could not find %s' % _file)
45
        log.all('{"source":"%s", "error_msg":"Could not find %s"}' %
46
                  (_file, _file))
47
        return
48
    # Check if the source, _file, is a child folder within destination
49
    elif destination.startswith(os.path.abspath(os.path.dirname(_file))+os.sep):
50
        log.all('{"source": "%s", "destination": "%s", "error_msg": "Source cannot be in destination"}' % (
51
            _file, destination))
52
        return
53
54
55
    media = Media.get_class_by_file(_file, get_all_subclasses())
56
    if not media:
57
        log.warn('Not a supported file (%s)' % _file)
58
        log.all('{"source":"%s", "error_msg":"Not a supported file"}' % _file)
59
        return
60
61
    if album_from_folder:
62
        media.set_album_from_folder()
63
64
    dest_path = FILESYSTEM.process_file(_file, destination,
65
        media, allowDuplicate=allow_duplicates, move=False)
66
    if dest_path:
67
        log.all('%s -> %s' % (_file, dest_path))
68
    if trash:
69
        send2trash(_file)
70
71
    return dest_path or None
72
73
74
@click.command('import')

elodie.py 1 location

@@ 36-71 (lines=36) @@
33
FILESYSTEM = FileSystem()
34
35
36
def import_file(_file, destination, album_from_folder, trash, allow_duplicates):
37
    
38
    _file = _decode(_file)
39
    destination = _decode(destination)
40
41
    """Set file metadata and move it to destination.
42
    """
43
    if not os.path.exists(_file):
44
        log.warn('Could not find %s' % _file)
45
        log.all('{"source":"%s", "error_msg":"Could not find %s"}' %
46
                  (_file, _file))
47
        return
48
    # Check if the source, _file, is a child folder within destination
49
    elif destination.startswith(os.path.abspath(os.path.dirname(_file))+os.sep):
50
        log.all('{"source": "%s", "destination": "%s", "error_msg": "Source cannot be in destination"}' % (
51
            _file, destination))
52
        return
53
54
55
    media = Media.get_class_by_file(_file, get_all_subclasses())
56
    if not media:
57
        log.warn('Not a supported file (%s)' % _file)
58
        log.all('{"source":"%s", "error_msg":"Not a supported file"}' % _file)
59
        return
60
61
    if album_from_folder:
62
        media.set_album_from_folder()
63
64
    dest_path = FILESYSTEM.process_file(_file, destination,
65
        media, allowDuplicate=allow_duplicates, move=False)
66
    if dest_path:
67
        log.all('%s -> %s' % (_file, dest_path))
68
    if trash:
69
        send2trash(_file)
70
71
    return dest_path or None
72
73
74
@click.command('import')