def get_file_name_and_path(self, file): """ Returns target file name and path """ exif_data = Exif(file).data() if exif_data and self.is_image_or_video(exif_data['MIMEType']): date = Date(file).from_exif(exif_data, self.date_regex) output = self.get_output_dir(date) target_file_name = self.get_file_name(file, date).lower() target_file_path = os.path.sep.join([output, target_file_name]) else: output = self.get_output_dir(False) target_file_name = os.path.basename(file) target_file_path = os.path.sep.join([output, target_file_name]) return output, target_file_name, target_file_path
def get_file_name_and_path(self, filename): """ Returns target file name and path """ exif_data = Exif(filename).data() target_file_type = None if exif_data and 'MIMEType' in exif_data: target_file_type = self.get_file_type(exif_data['MIMEType']) if target_file_type in ['image', 'video']: date = Date(filename).from_exif(exif_data, self.timestamp, self.date_regex, self.date_field) output = self.get_output_dir(date) target_file_name = self.get_file_name(filename, date) if not self.original_filenames: target_file_name = target_file_name.lower() target_file_path = os.path.sep.join([output, target_file_name]) else: output = self.get_output_dir(False) target_file_name = os.path.basename(filename) target_file_path = os.path.sep.join([output, target_file_name]) return output, target_file_name, target_file_path, target_file_type
def test_exif_reads_valid_file(): exif = Exif("input/exif.jpg") assert exif.data()['CreateDate'] == '2017:01:01 01:01:01'
def test_exif_handles_exception(mocker): mocker.patch('subprocess.check_output', side_effect=CalledProcessError(2, 'cmd')) exif = Exif("not-existing.jpg") assert exif.data() is None
def test_exif_reads_file_with_spaces_punctuation(): exif = Exif("input/phockup's exif test.jpg") assert exif.data()['CreateDate'] == '2017:01:01 01:01:01'
def test_exif_reads_files_with_illegal_characters(): exif = Exif("input/!#$%'+-.^_`~.jpg") assert exif.data()['CreateDate'] == '2017:01:01 01:01:01'
def test_exif_reads_valid_file(): exif = Exif("input/exif.jpg") assert exif.data()['CreateDate'] == '2017:01:01 01:01:01'
def test_exif_handles_exception(mocker): mocker.patch('subprocess.check_output', side_effect=CalledProcessError(2, 'cmd')) exif = Exif("not-existing.jpg") assert exif.data() == None