Browse Source

Turn `patacrep.songs.convert` script into a `patatools` sub-command

pull/189/head
Louis 9 years ago
parent
commit
9be3072e4e
  1. 0
      patacrep/tools/convert/__init__.py
  2. 31
      patacrep/tools/convert/__main__.py

0
patacrep/tools/convert/__init__.py

31
patacrep/songs/convert/__main__.py → patacrep/tools/convert/__main__.py

@ -1,7 +1,4 @@
"""Conversion between formats """`patatools.convent` command: convert between song formats"""
See the :meth:`__usage` method for more information.
"""
import os import os
import logging import logging
@ -11,27 +8,32 @@ from patacrep import files
from patacrep.songs import DEFAULT_CONFIG from patacrep.songs import DEFAULT_CONFIG
from patacrep.utils import yesno from patacrep.utils import yesno
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger("patatools.convert")
SUBCOMMAND_DESCRIPTION = "Convert between song formats"
def __usage(): def _usage():
return "python3 -m patacrep.songs.convert INPUTFORMAT OUTPUTFORMAT FILES" return "patatools convert INPUTFORMAT OUTPUTFORMAT FILES"
def confirm(destname): def confirm(destname):
"""Ask whether destination name should be overwrited."""
while True: while True:
try: try:
return yesno(input("File '{}' already exist. Overwrite? [yn] ".format(destname))) return yesno(input("File '{}' already exist. Overwrite? [yn] ".format(destname)))
except ValueError: except ValueError:
continue continue
if __name__ == "__main__": def main(args=None):
if len(sys.argv) < 4: """Main function: run from command line."""
if args is None:
args = sys.argv[1:]
if len(args) < 3:
LOGGER.error("Invalid number of arguments.") LOGGER.error("Invalid number of arguments.")
LOGGER.error("Usage: %s", __usage()) LOGGER.error("Usage: %s", _usage())
sys.exit(1) sys.exit(1)
source = sys.argv[1] source = args[0]
dest = sys.argv[2] dest = args[1]
song_files = sys.argv[3:] song_files = args[2:]
renderers = files.load_plugins( renderers = files.load_plugins(
datadirs=DEFAULT_CONFIG.get('datadir', []), datadirs=DEFAULT_CONFIG.get('datadir', []),
@ -73,3 +75,6 @@ if __name__ == "__main__":
sys.exit(0) sys.exit(0)
sys.exit(0) sys.exit(0)
if __name__ == "__main__":
main()
Loading…
Cancel
Save