def test_clean_single_field(self): tmp = helper.get_tmpfile_path("meta-all-values.mscx") mscxyz.execute(["meta", "--clean", "vbox_title", tmp]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.vbox_title, None, "vbox_title") self.assertEqual(iface.vbox_composer, "vbox_composer", "vbox_composer")
def test_delete_duplicates_move_subtitle(self): tmp = helper.get_tmpfile_path("meta-duplicates-move-subtitle.mscx") mscxyz.execute(["meta", "--delete-duplicates", tmp]) meta = Meta(tmp) self.assertFalse(meta.interface.combined_lyricist) self.assertFalse(meta.interface.combined_subtitle) self.assertEqual(meta.interface.combined_title, "Title")
def test_clean_single_field(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute(['meta', '--clean', 'vbox_title', tmp]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.vbox_title, None, 'vbox_title') self.assertEqual(iface.vbox_composer, 'vbox_composer', 'vbox_composer')
def test_clean_all(self): tmp = helper.get_tmpfile_path("meta-all-values.mscx") mscxyz.execute(["meta", "--clean", "all", tmp]) meta = Meta(tmp) iface = meta.interface_read_write for field in iface.fields: self.assertEqual(getattr(iface, field), None, field)
def test_set_field_with_templating(self): tmp = helper.get_tmpfile_path("meta-all-values.mscx") mscxyz.execute([ "meta", "--set-field", "vbox_title", "$vbox_title ($vbox_composer)", tmp ]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, "vbox_title (vbox_composer)")
def test_set_field_with_templating(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute([ 'meta', '--set-field', 'vbox_title', '$vbox_title ($vbox_composer)', tmp ]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, 'vbox_title (vbox_composer)')
def test_set_field_multiple_times(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute([ 'meta', '--set-field', 'vbox_title', 'lol', '--set-field', 'vbox_composer', 'troll', tmp ]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, 'lol') self.assertEqual(meta.interface.vbox_composer, 'troll')
def test_distribute_field_multple_source_fields(self): tmp = helper.get_tmpfile_path('Title - Composer.mscx') mscxyz.execute([ 'meta', '--distribute-field', 'vbox_title,readonly_basename', '$combined_title - $combined_composer', tmp ]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.vbox_composer, 'Composer') self.assertEqual(iface.metatag_composer, 'Composer') self.assertEqual(iface.vbox_title, 'Title') self.assertEqual(iface.metatag_work_title, 'Title')
def rename_filename(source: str) -> Meta: args = get_args() meta = Meta(source) meta_values = meta.interface.export_to_dict() target_filename = apply_format_string(meta_values) if args.rename_skip: skips = args.rename_skip.split(",") for skip in skips: if not meta_values[skip]: print( color("Field “{}” is empty! Skipping".format(skip), "red")) return meta if args.rename_target: target_base = os.path.abspath(args.rename_target) else: target_base = os.getcwd() target = os.path.join(target_base, target_filename + "." + meta.extension) if os.path.exists(target): target_format = target.replace(".mscx", "{}.mscx") i = "" while os.path.exists(target_format.format(i)): target = target_format.format(i) if get_checksum(source) == get_checksum(target): print( color( "The file “{}” with the same checksum (sha1) " "already exists in the target path “{}”!".format( source, target), "red", )) return meta if i == "": i = 1 i += 1 target = target_format.format(i) show(source, target) if not args.general_dry_run: create_dir(target) # Invalid cross-device link: # os.rename(source, target) shutil.move(source, target) return meta
def test_distribute_field_multiple_values(self): tmp = helper.get_tmpfile_path('meta-distribute-field.mscx') mscxyz.execute([ 'meta', '--distribute-field', 'vbox_title', '$metatag_work_title - $metatag_composer', '--distribute-field', 'vbox_title', '$metatag_movement_title - $metatag_lyricist', tmp ]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.metatag_lyricist, 'Composer') self.assertEqual(iface.metatag_composer, 'Composer') self.assertEqual(iface.metatag_movement_title, 'Title') self.assertEqual(iface.metatag_work_title, 'Title')
def test_set_field_multiple_times(self): tmp = helper.get_tmpfile_path("meta-all-values.mscx") mscxyz.execute([ "meta", "--set-field", "vbox_title", "lol", "--set-field", "vbox_composer", "troll", tmp, ]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, "lol") self.assertEqual(meta.interface.vbox_composer, "troll")
def test_distribute_field_multple_source_fields(self): tmp = helper.get_tmpfile_path("Title - Composer.mscx") mscxyz.execute([ "meta", "--distribute-field", "vbox_title,readonly_basename", "$combined_title - $combined_composer", tmp, ]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.vbox_composer, "Composer") self.assertEqual(iface.metatag_composer, "Composer") self.assertEqual(iface.vbox_title, "Title") self.assertEqual(iface.metatag_work_title, "Title")
def test_distribute_field_multiple_values(self): tmp = helper.get_tmpfile_path("meta-distribute-field.mscx") mscxyz.execute([ "meta", "--distribute-field", "vbox_title", "$metatag_work_title - $metatag_composer", "--distribute-field", "vbox_title", "$metatag_movement_title - $metatag_lyricist", tmp, ]) meta = Meta(tmp) iface = meta.interface self.assertEqual(iface.metatag_lyricist, "Composer") self.assertEqual(iface.metatag_composer, "Composer") self.assertEqual(iface.metatag_movement_title, "Title") self.assertEqual(iface.metatag_work_title, "Title")
def execute(args: typing.Sequence = None): args = cli.parser.parse_args(args) config = parse_config_ini(args.general_config_file) if config: args = merge_config_into_args(config, args) set_args(args) if args.subcommand == "help": show_all_help(args) sys.exit() files = list_scores(path=args.path, glob=args.general_glob) for file in files: print("\n" + color(file, "red")) if args.general_backup: from mscxyz.score_file_classes import MscoreFile score = MscoreFile(file) score.backup() if args.subcommand == "clean": score = MscoreXmlTree(file) print(score.filename) score.clean() if args.clean_style: score.merge_style(styles=args.clean_style.name) score.save(mscore=args.general_mscore) elif args.subcommand == "lyrics": score = MscoreLyricsInterface(file) if args.lyrics_remap: score.remap(remap_string=args.lyrics_remap, mscore=args.general_mscore) elif args.lyrics_fix: score.fix_lyrics(mscore=args.general_mscore) else: score.extract_lyrics(number=args.lyrics_extract, mscore=args.general_mscore) elif args.subcommand == "meta": score = Meta(file) if no_error(lxml.etree.XMLSyntaxError, score.errors): pre = score.interface.export_to_dict() if args.meta_clean: score.clean(fields=args.meta_clean) if args.meta_json: score.export_json() if args.meta_dist: for a in args.meta_dist: score.distribute_field(source_fields=a[0], format_string=a[1]) if args.meta_set: for a in args.meta_set: score.set_field(destination_field=a[0], format_string=a[1]) if args.meta_delete: score.delete_duplicates() if args.meta_sync: score.sync_fields() if args.meta_log: score.write_to_log_file(args.meta_log[0], args.meta_log[1]) post = score.interface.export_to_dict() score.show(pre, post) if not args.general_dry_run and not score.errors and pre != post: score.save(mscore=args.general_mscore) elif args.subcommand == "rename": score = rename_filename(file) elif args.subcommand == "export": from mscxyz.score_file_classes import MscoreFile score = MscoreFile(file) score.export(extension=args.export_extension) report_errors(score.errors)
def test_set_field_simple_string(self): tmp = helper.get_tmpfile_path('meta-all-values.mscx') mscxyz.execute(['meta', '--set-field', 'vbox_title', 'lol', tmp]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, 'lol')
def test_delete_duplicates(self): tmp = helper.get_tmpfile_path('meta-duplicates.mscx') mscxyz.execute(['meta', '--delete-duplicates', tmp]) meta = Meta(tmp) self.assertFalse(meta.interface.combined_lyricist) self.assertFalse(meta.interface.combined_subtitle)
def test_set_field_simple_string(self): tmp = helper.get_tmpfile_path("meta-all-values.mscx") mscxyz.execute(["meta", "--set-field", "vbox_title", "lol", tmp]) meta = Meta(tmp) self.assertEqual(meta.interface.vbox_title, "lol")