Skip to content

Commit

Permalink
Merge pull request #2 from colton22/master
Browse files Browse the repository at this point in the history
Added --dry option to show what will be done without doing it
  • Loading branch information
rieck authored May 12, 2018
2 parents 9596b54 + d5ba9eb commit b7833f9
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions perplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,27 @@ def build_map(movies, dest, mapping=[]):
return mapping


def copy_rename(mapping, dest):
def copy_rename(mapping, dest, dry):
""" Copy and rename files to destination """

widgets = [pb.Percentage(), ' ', pb.Bar(), ' ', pb.ETA()]
if dry:
widgets = ['']
else:
widgets = [pb.Percentage(), ' ', pb.Bar(), ' ', pb.ETA()]
pbar = pb.ProgressBar(widgets=widgets)

for old_name, new_name in pbar(mapping):
dp = os.path.join(dest, os.path.dirname(new_name))
fp = os.path.join(dp, os.path.basename(new_name))

try:
if not os.path.exists(dp):
os.makedirs(dp)
if not dry:
os.makedirs(dp)

if not os.path.exists(fp):
shutil.copy(old_name, fp)
if dry:
print "%s\n %s" % (old_name,fp)
else:
shutil.copy(old_name, fp)

except Exception, e:
print str(e)
Expand All @@ -111,7 +116,9 @@ def copy_rename(mapping, dest):
help='save database of movie titles and files')
parser.add_argument('--load', metavar='<file>', type=str,
help='load database of movie titles and files')

parser.add_argument('--dry', action='store_true',
help='show dry run of what will happen')
parser.set_defaults(dry=False)
args = parser.parse_args()

if args.plex:
Expand All @@ -131,6 +138,6 @@ def copy_rename(mapping, dest):
if args.dest:
print "Building file mapping for " + args.dest
mapping = build_map(movies, args.dest)

print "Copying renamed files to " + args.dest
copy_rename(mapping, args.dest)
copy_rename(mapping, args.dest,args.dry)

0 comments on commit b7833f9

Please sign in to comment.