Skip to content

Commit

Permalink
Copy2 chmod error - Prefix and Suffix options
Browse files Browse the repository at this point in the history
  • Loading branch information
philchand committed Feb 14, 2021
1 parent 3078df1 commit b88b4fc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
18 changes: 18 additions & 0 deletions phockup.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ def main():
help="Don't move any files, just show which changes would be done.",
)

parser.add_argument(
"-p",
"--prefix",
action="store",
default='',
help="Prefix to be inserted before file name",
)

parser.add_argument(
"-s",
"--suffix",
action="store",
default='',
help="Suffix to be inserted after file name before the extension",
)

parser.add_argument(
"-r",
"--regex",
Expand Down Expand Up @@ -166,6 +182,8 @@ def main():
original_filenames=args.original_names,
timestamp=args.timestamp,
date_field=args.date_field,
prefix=args.prefix,
suffix=args.suffix,
dry_run=args.dry_run,
)

Expand Down
20 changes: 18 additions & 2 deletions src/phockup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __init__(self, input_dir, output_dir, **args):
self.timestamp = args.get('timestamp', False)
self.date_field = args.get('date_field', False)
self.dry_run = args.get('dry_run', False)
self.prefix = args.get('prefix','')
self.suffix = args.get('suffix','')

self.check_directories()
self.walk_directory()
Expand Down Expand Up @@ -111,8 +113,11 @@ def get_file_name(self, original_filename, date):
Generate file name based on exif data unless it is missing or
original filenames are required. Then use original file name
"""
local_path_filename, local_file_extension = os.path.splitext(original_filename)
local_filename = os.path.basename(local_path_filename)

if self.original_filenames:
return os.path.basename(original_filename)
return (self.prefix + local_filename + self.suffix + local_file_extension)

try:
filename = [
Expand All @@ -128,7 +133,7 @@ def get_file_name(self, original_filename, date):
if date['subseconds']:
filename.append(date['subseconds'])

return ''.join(filename) + os.path.splitext(original_filename)[1]
return self.prefix + ''.join(filename) + self.suffix + local_file_extension
except:
return os.path.basename(original_filename)

Expand Down Expand Up @@ -160,6 +165,12 @@ def process_file(self, filename):
except FileNotFoundError:
printer.line(' => skipped, no such file or directory')
break
except OSError:
if os.path.isfile(target_file):
if self.checksum(filename) == self.checksum(target_file):
printer.line('File copied, looks the same: {0}'.format(target_file))
break

elif self.link and not self.dry_run:
os.link(filename, target_file)
else:
Expand All @@ -169,6 +180,11 @@ def process_file(self, filename):
except FileNotFoundError:
printer.line(' => skipped, no such file or directory')
break

except OSError:
if os.path.isfile(target_file):
if self.checksum(filename) == self.checksum(target_file):
printer.line('File copied, looks the same: {0}'.format(target_file))

printer.line(' => %s' % target_file)
self.process_xmp(filename, target_file_name, suffix, output)
Expand Down

0 comments on commit b88b4fc

Please sign in to comment.