Browse Source

Add an option to remember the confirmation choice with a *

pull/108/head
Oliverpool 9 years ago
parent
commit
0ea1cde0e0
  1. 21
      patacrep/songs/convert/__main__.py

21
patacrep/songs/convert/__main__.py

@ -17,11 +17,14 @@ def __usage():
def yesno(prompt): def yesno(prompt):
while True: while True:
answer = input("{} [yn] ".format(prompt)) answer = input("{} [yn](folllow with * to remember) ".format(prompt)).strip().lower()
if answer.strip().lower() == "y": remember = (answer[-1] == "*")
return True if remember:
if answer.strip().lower() == "n": answer = answer[0:-1]
return False if answer == "y":
return True, remember
if answer == "n":
return False, remember
def confirm(destname): def confirm(destname):
return yesno("File '{}' already exist. Overwrite?".format(destname)) return yesno("File '{}' already exist. Overwrite?".format(destname))
@ -50,14 +53,16 @@ if __name__ == "__main__":
) )
sys.exit(1) sys.exit(1)
remember = False
for file in song_files: for file in song_files:
song = song_parsers[source]("", file, DEFAULT_CONFIG) song = song_parsers[source]("", file, DEFAULT_CONFIG)
try: try:
converted = song.render(dest) converted = song.render(dest)
destname = "{}.{}".format(".".join(file.split(".")[:-1]), dest) destname = "{}.{}".format(".".join(file.split(".")[:-1]), dest)
if os.path.exists(destname): if os.path.exists(destname) and not remember:
if not confirm(destname): overwrite, remember = confirm(destname)
continue if not overwrite:
continue
with open(destname, "w") as destfile: with open(destname, "w") as destfile:
destfile.write(converted) destfile.write(converted)

Loading…
Cancel
Save