Browse Source

Revert "Add an option to remember the confirmation choice with a *"

This reverts commit 0ea1cde0e0.

This feature can be done using the [coreutils yes
command](https://www.gnu.org/software/coreutils/manual/html_node/yes-invocation.html).
pull/118/head
Louis 9 years ago
parent
commit
aeb10c3c2a
  1. 23
      patacrep/songs/convert/__main__.py

23
patacrep/songs/convert/__main__.py

@ -17,14 +17,11 @@ def __usage():
def yesno(prompt): def yesno(prompt):
while True: while True:
answer = input("{} [yn](append * to remember) ".format(prompt)).strip().lower() answer = input("{} [yn] ".format(prompt))
remember = (answer[-1] == "*") if answer.strip().lower() == "y":
if remember: return True
answer = answer[0:-1] if answer.strip().lower() == "n":
if answer == "y": return False
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))
@ -53,19 +50,15 @@ 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:
destname = "{}.{}".format(".".join(file.split(".")[:-1]), dest) destname = "{}.{}".format(".".join(file.split(".")[:-1]), dest)
dest_exists = os.path.exists(destname) if os.path.exists(destname):
if dest_exists and not remember: if not confirm(destname):
overwrite, remember = confirm(destname)
if dest_exists and not overwrite:
continue continue
converted = song.render(dest)
with open(destname, "w") as destfile: with open(destname, "w") as destfile:
destfile.write(converted) destfile.write(song.render(dest))
except NotImplementedError: except NotImplementedError:
LOGGER.error("Cannot convert to format '%s'.", dest) LOGGER.error("Cannot convert to format '%s'.", dest)

Loading…
Cancel
Save