Skip to content

Commit

Permalink
Added --always option (when used, will not prompt y/n before copying)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbr committed Nov 8, 2008
1 parent 28340f8 commit 2f07fa1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions autoPathTv.py
Expand Up @@ -224,12 +224,15 @@ def processNames(names, verbose=False):
def confirm(question="Rename files?"):
ans = None
while ans not in ["q", "quit"]:
print "y/n/q?",
print "y/n/a/q?",
ans = raw_input()
print ans
if ans.lower() in ["y", "yes"]:
return True
elif ans.lower() in ["n", "no"]:
return False
elif ans.lower() in ["a", "always"]:
return "always"
else:
sys.exit(1)
#end confirm
Expand Down Expand Up @@ -257,15 +260,18 @@ def same_partition(f1, f2):


def main():

parser = OptionParser(usage="%prog [options] <file or directories>")
parser.add_option("-a", "--always", dest = "always",
action="store_true", default = False,
help="Do not ask for confirmation before copying")

opts, args = parser.parse_args()

files = findFiles(args)
files = processNames(files)

# Warn if no files are found, then exit
if files.__len__() == 0:
if len(files) == 0:
print colour('No files found','red')
sys.exit(1)
#end if files == 0
Expand All @@ -278,7 +284,9 @@ def main():
print "Old path:", oldfile
print "New path:", newfile
ans=confirm()
if ans:
if ans == "always": opts.always = True

if ans or opts.always:
make_path(newpath)
file_exists = does_file_exist(newfile)
if file_exists:
Expand Down

0 comments on commit 2f07fa1

Please sign in to comment.