(orig, move=False)
| 94 | return False |
| 95 | |
| 96 | def import_photos_from_dir(orig, move=False): |
| 97 | imported = 0 |
| 98 | were_duplicates = 0 |
| 99 | were_bad = 0 |
| 100 | |
| 101 | for r, d, f in os.walk(orig): |
| 102 | if SYNOLOGY_THUMBNAILS_DIR_NAME in r: |
| 103 | continue |
| 104 | for fn in sorted(f): |
| 105 | filepath = os.path.join(r, fn) |
| 106 | dest = determine_destination(filepath) |
| 107 | if blacklisted_type(fn): |
| 108 | # Blacklisted type |
| 109 | were_bad += 1 |
| 110 | elif not dest: |
| 111 | # No filters match this file type |
| 112 | pass |
| 113 | else: |
| 114 | t = get_datetime(filepath) |
| 115 | if t: |
| 116 | destpath = '%02d/%02d/%02d' % (t.year, t.month, t.day) |
| 117 | destpath = os.path.join(dest, destpath) |
| 118 | mkdir_p(destpath) |
| 119 | destpath = os.path.join(destpath, fn) |
| 120 | |
| 121 | if filepath == destpath: |
| 122 | # File is already in the right place so be very careful not to do anything like delete it |
| 123 | pass |
| 124 | elif not os.path.exists(destpath): |
| 125 | if move: |
| 126 | shutil.move(filepath, destpath) |
| 127 | else: |
| 128 | shutil.copyfile(filepath, destpath) |
| 129 | record_photo(destpath) |
| 130 | imported += 1 |
| 131 | print('IMPORTED {} -> {}'.format(filepath, destpath)) |
| 132 | else: |
| 133 | print('PATH EXISTS {} -> {}'.format(filepath, destpath)) |
| 134 | same = determine_same_file(filepath, destpath) |
| 135 | print('PHOTO IS THE SAME') |
| 136 | if same: |
| 137 | if move: |
| 138 | os.remove(filepath) |
| 139 | were_duplicates += 1 |
| 140 | print('DELETED FROM SOURCE') |
| 141 | else: |
| 142 | print('NEED TO IMPORT UNDER DIFFERENT NAME') |
| 143 | exit(1) |
| 144 | destpath = find_new_file_name(destpath) |
| 145 | shutil.move(filepath, destpath) |
| 146 | record_photo(destpath) |
| 147 | imported += 1 |
| 148 | # print 'IMPORTED {} -> {}'.format(filepath, destpath) |
| 149 | |
| 150 | else: |
| 151 | print('ERROR READING DATE: {}'.format(filepath)) |
| 152 | were_bad += 1 |
| 153 |
no test coverage detected