def process_file(self, input_path, output_dir): fmt_klass = get_metadata_handler(input_path) with fmt_klass(input_path) as file_fmt: creation_date = file_fmt.creation_date rule = self._get_matching_rule(creation_date) if rule: org_format = rule.format % {'default': self._default_format} else: org_format = self._default_format metadata = {} directives = ('Y', 'm', 'B', 'H', 'M', 'S') for d in directives: metadata[d] = datetime.strftime(creation_date, '%' + d) org_dir = org_format % metadata _, filename = os.path.split(input_path) output_dir = os.path.join(output_dir, org_dir) from shotclock import mkdir_p mkdir_p(output_dir) output_path = os.path.join(output_dir, filename) import shutil # shutil.copy2(input_path, output_path) print '%s -> %s' % (input_path, output_path)
def process_file(self, input_path, output_dir): # Get the creation date and shift it fmt_klass = get_metadata_handler(input_path) with fmt_klass(input_path) as file_fmt: dt = file_fmt.creation_date shifted_dt = self._shift_time(dt) # Update the metadata and persist to output path _, input_filename = os.path.split(input_path) output_path = os.path.join(output_dir, input_filename) file_fmt.creation_date = shifted_dt file_fmt.save_as(unicode(output_path)) print "%s: %s -> %s (h:%s m:%s)" % \ (input_filename, dt, shifted_dt, self.hours, self.minutes)
def process_file(self, input_path, output_dir): # Get the creation date from the working copy fmt_klass = get_metadata_handler(input_path) with fmt_klass(input_path) as file_fmt: creation_dt = file_fmt.creation_date # Format the output path _, input_filename = os.path.split(input_path) output_filename = self._get_output_filename(input_filename, creation_dt) output_filename = self._get_unique_filename(output_dir, output_filename) output_path = os.path.join(output_dir, output_filename) # Rename the working copy to the new filename shutil.copy2(input_path, output_path) print '%s -> %s' % (input_path, output_path)
def _get_files(self): files = [] for filename in os.listdir(self._dir): try: path = os.path.join(self._dir, filename) # Get each file's byte size and metadata creation date # If same size and within date tolerance, consider them # duplicates byte_size = os.path.getsize(path) fmt_klass = get_metadata_handler(path) with fmt_klass(path) as file_fmt: creation_dt = file_fmt.creation_date files.append(File(filename, byte_size, creation_dt)) except Exception as e: print e print "skipping", path print "SORTING %s files" % len(files) files = sorted(files, lambda a, b: a.byte_size < b.byte_size) return files
def process_file(self, input_path, output_dir): fmt_klass = get_metadata_handler(input_path) with fmt_klass(input_path) as file_fmt: creation_date = file_fmt.creation_date rule = self._get_matching_rule(creation_date) metadata = {} directives = ('Y', 'm', 'B', 'H', 'M', 'S') for d in directives: metadata[d] = datetime.strftime(creation_date, '%' + d) target_path = rule.path_format % metadata _, filename = os.path.split(input_path) output_dir = os.path.join(output_dir, target_path) from shotclock import mkdir_p mkdir_p(output_dir) output_path = os.path.join(output_dir, filename) import shutil # shutil.copy2(input_path, output_path) print '%s -> %s' % (input_path, output_path)