def do_clean(namespace): """Execute the `patatools cache clean` command.""" for datadir in open_songbook(namespace.songbook)['_datadir']: cachedir = os.path.join(datadir, ".cache") LOGGER.info("Deleting cache directory '{}'...".format(cachedir)) if os.path.isdir(cachedir): shutil.rmtree(cachedir)
def do_content_items(namespace): """Execute the `patatools content items` command.""" config = open_songbook(namespace.songbook) config['_cache'] = True config['_error'] = "fix" songbook = Songbook(config, config['_outputname']) _, content_items = songbook.get_content_items() yaml_dir = os.path.dirname(os.path.abspath(namespace.songbook)) ref_dir = os.path.join(yaml_dir, 'songs') content_items = [ normalize_song_path(item.to_dict(), ref_dir) for item in content_items ] sys.stdout.write(yaml.safe_dump(content_items, allow_unicode=True, default_flow_style=False))
def do_content_items(namespace): """Execute the `patatools content items` command.""" config = open_songbook(namespace.songbook) config['_cache'] = True config['_error'] = "fix" songbook = Songbook(config, config['_outputname']) _, content_items = songbook.get_content_items() yaml_dir = os.path.dirname(os.path.abspath(namespace.songbook)) ref_dir = os.path.join(yaml_dir, 'songs') content_items = [ normalize_song_path(item.to_dict(), ref_dir) for item in content_items ] sys.stdout.write( yaml.safe_dump(content_items, allow_unicode=True, default_flow_style=False))
def main(args=None): """Main function:""" if args is None: args = sys.argv # set script locale to match user's try: locale.setlocale(locale.LC_ALL, '') except locale.Error as error: # Locale is not installed on user's system, or wrongly configured. LOGGER.error("Locale error: {}\n".format(str(error))) options = argument_parser(args[1:]) songbook_path = options.book[-1] # Load the user songbook config try: songbook = open_songbook(songbook_path) # Command line options if options.datadir: for datadir in reversed(options.datadir): songbook['datadir'].insert(0, datadir) songbook['_cache'] = options.cache[0] songbook['_error'] = options.error[0] sb_builder = SongbookBuilder(songbook) sb_builder.unsafe = True sb_builder.build_steps(options.steps) except errors.SongbookError as error: LOGGER.error(error) if LOGGER.level >= logging.INFO: LOGGER.error( "Running again with option '-v' may give more information." ) sys.exit(1) except KeyboardInterrupt: LOGGER.warning("Aborted by user.") sys.exit(1) sys.exit(0)
def main(args=None): """Main function:""" if args is None: args = sys.argv # set script locale to match user's try: locale.setlocale(locale.LC_ALL, '') except locale.Error as error: # Locale is not installed on user's system, or wrongly configured. LOGGER.error("Locale error: {}\n".format(str(error))) options = argument_parser(args[1:]) songbook_path = options.book[-1] # Load the user songbook config try: songbook = open_songbook(songbook_path) # Command line options if options.datadir: for datadir in reversed(options.datadir): songbook['datadir'].insert(0, datadir) songbook['_cache'] = options.cache[0] songbook['_error'] = options.error[0] sb_builder = SongbookBuilder(songbook) sb_builder.unsafe = True sb_builder.build_steps(options.steps) except errors.SongbookError as error: LOGGER.error(error) if LOGGER.level >= logging.INFO: LOGGER.error( "Running again with option '-v' may give more information.") sys.exit(1) except KeyboardInterrupt: LOGGER.warning("Aborted by user.") sys.exit(1) sys.exit(0)