def test_property_version(self): tree = MscoreXmlTree(helper.get_tmpfile_path("simple.mscx", version=2)) self.assertEqual(tree.version, 2.06) self.assertEqual(tree.version_major, 2) tree = MscoreXmlTree(helper.get_tmpfile_path("simple.mscx", version=3)) self.assertEqual(tree.version, 3.01) self.assertEqual(tree.version_major, 3)
def assertDiff(self, filename, version=2): orig = os.path.join(os.path.expanduser("~"), filename) saved = orig.replace(".mscx", "_saved.mscx") tmp = helper.get_tmpfile_path(filename, version=version) shutil.copy2(tmp, orig) tree = MscoreXmlTree(tmp) tree.save(new_name=saved) self.assertTrue(filecmp.cmp(orig, saved)) os.remove(orig) os.remove(saved)
def setUp(self): self.fields = [ 'combined_composer', 'combined_lyricist', 'combined_subtitle', 'combined_title', 'metatag_arranger', 'metatag_composer', 'metatag_copyright', 'metatag_creation_date', 'metatag_lyricist', 'metatag_movement_number', 'metatag_movement_title', 'metatag_platform', 'metatag_poet', 'metatag_source', 'metatag_translator', 'metatag_work_number', 'metatag_work_title', 'readonly_abspath', 'readonly_basename', 'readonly_dirname', 'readonly_extension', 'readonly_filename', 'readonly_relpath', 'readonly_relpath_backup', 'vbox_composer', 'vbox_lyricist', 'vbox_subtitle', 'vbox_title', ] self.tmp = helper.get_tmpfile_path('meta-all-values.mscx') self.xml_tree = MscoreXmlTree(self.tmp) self.interface = Interface(self.xml_tree)
def setUp(self): self.fields = [ "combined_composer", "combined_lyricist", "combined_subtitle", "combined_title", "metatag_arranger", "metatag_composer", "metatag_copyright", "metatag_creation_date", "metatag_lyricist", "metatag_movement_number", "metatag_movement_title", "metatag_platform", "metatag_poet", "metatag_source", "metatag_translator", "metatag_work_number", "metatag_work_title", "readonly_abspath", "readonly_basename", "readonly_dirname", "readonly_extension", "readonly_filename", "readonly_relpath", "readonly_relpath_backup", "vbox_composer", "vbox_lyricist", "vbox_subtitle", "vbox_title", ] self.tmp = helper.get_tmpfile_path("meta-all-values.mscx") self.xml_tree = MscoreXmlTree(self.tmp) self.interface = Interface(self.xml_tree)
def test_set2(self): meta, tree, tmp = self._init_class('simple.mscx', version=2) meta.workTitle = 'WT' meta.movement_title = 'MT' tree.save() tree = MscoreXmlTree(tmp) meta = MetaTag(tree.xml_root) self.assertEqual(meta.work_title, 'WT') self.assertEqual(meta.movementTitle, 'MT') xml_string = helper.read_file(tmp) self.assertTrue('<metaTag name="workTitle">WT</metaTag>' in xml_string)
def test_set3(self): meta, tree, tmp = self._init_class("simple.mscx", version=3) meta.workTitle = "WT" meta.movement_title = "MT" tree.save() tree = MscoreXmlTree(tmp) meta = MetaTag(tree.xml_root) self.assertEqual(meta.work_title, "WT") self.assertEqual(meta.movementTitle, "MT") xml_string = helper.read_file(tmp) self.assertTrue('<metaTag name="workTitle">WT</metaTag>' in xml_string)
def setUp(self): self.fields = ( "readonly_basename", "readonly_dirname", "readonly_extension", "readonly_filename", "readonly_relpath", "readonly_relpath_backup", ) self.tmp = helper.get_tmpfile_path("simple.mscx") self.xml_tree = MscoreXmlTree(self.tmp) self.interface = InterfaceReadOnly(self.xml_tree)
def setUp(self): self.fields = ( 'readonly_basename', 'readonly_dirname', 'readonly_extension', 'readonly_filename', 'readonly_relpath', 'readonly_relpath_backup', ) self.tmp = helper.get_tmpfile_path('simple.mscx') self.xml_tree = MscoreXmlTree(self.tmp) self.interface = InterfaceReadOnly(self.xml_tree)
def test_method_merge_style(self): tree = MscoreXmlTree(helper.get_tmpfile_path("simple.mscx")) styles = """ <TextStyle> <halign>center</halign> <valign>bottom</valign> <xoffset>0</xoffset> <yoffset>-1</yoffset> <offsetType>spatium</offsetType> <name>Form Section</name> <family>Alegreya Sans</family> <size>12</size> <bold>1</bold> <italic>1</italic> <sizeIsSpatiumDependent>1</sizeIsSpatiumDependent> <frameWidthS>0.1</frameWidthS> <paddingWidthS>0.2</paddingWidthS> <frameRound>0</frameRound> <frameColor r="0" g="0" b="0" a="255"/> </TextStyle> """ tree.clean() tree.merge_style(styles) xml_tree = tree.xml_tree result = xml_tree.xpath("/museScore/Score/Style") self.assertEqual(result[0][0][0].tag, "halign") self.assertEqual(result[0][0][0].text, "center")
def test_method_clean(self): tmp = helper.get_tmpfile_path("clean.mscx", version=3) tree = MscoreXmlTree(tmp) tree.clean() tree.save() tree = MscoreXmlTree(tmp) xml_tree = tree.xml_tree self.assertEqual(xml_tree.xpath("/museScore/Score/Style"), []) self.assertEqual(xml_tree.xpath("//LayoutBreak"), []) self.assertEqual(xml_tree.xpath("//StemDirection"), []) self.assertEqual(xml_tree.xpath("//font"), []) self.assertEqual(xml_tree.xpath("//b"), []) self.assertEqual(xml_tree.xpath("//i"), []) self.assertEqual(xml_tree.xpath("//pos"), []) self.assertEqual(xml_tree.xpath("//offset"), [])
def test_method_clean(self): tmp = helper.get_tmpfile_path('clean.mscx', version=3) tree = MscoreXmlTree(tmp) tree.clean() tree.save() tree = MscoreXmlTree(tmp) xml_tree = tree.xml_tree self.assertEqual(xml_tree.xpath('/museScore/Score/Style'), []) self.assertEqual(xml_tree.xpath('//LayoutBreak'), []) self.assertEqual(xml_tree.xpath('//StemDirection'), []) self.assertEqual(xml_tree.xpath('//font'), []) self.assertEqual(xml_tree.xpath('//b'), []) self.assertEqual(xml_tree.xpath('//i'), []) self.assertEqual(xml_tree.xpath('//pos'), []) self.assertEqual(xml_tree.xpath('//offset'), [])
def _assert_set(self, filename, version=2): tmp = helper.get_tmpfile_path(filename, version) tree = MscoreXmlTree(tmp) vbox = Vbox(tree.xml_root) vbox.Title = "lol" vbox.composer = "lol" tree.save() tree = MscoreXmlTree(tmp) vbox = Vbox(tree.xml_root) self.assertEqual(vbox.title, "lol") self.assertEqual(vbox.Composer, "lol") xml_string = helper.read_file(tmp) self.assertTrue("<text>lol</text>" in xml_string)
def _test_set_all_values(self, version): interface, tree, tmp = self._init_class("meta-all-values.mscx", version) for field in self.fields: setattr(interface, field, field + "_test") self.assertEqual(getattr(interface, field), field + "_test") tree.save() tree = MscoreXmlTree(tmp) interface = InterfaceReadWrite(tree.xml_root) self.assertEqual(interface.combined_composer, "vbox_composer_test") self.assertEqual(interface.combined_lyricist, "vbox_lyricist_test") self.assertEqual(interface.combined_subtitle, "vbox_subtitle_test") self.assertEqual(interface.combined_title, "vbox_title_test") for field in self.fields[4:]: self.assertEqual(getattr(interface, field), field + "_test")
def _init_class(self, filename): tmp = helper.get_tmpfile_path(filename) tree = MscoreXmlTree(tmp) combined = Combined(tree.xml_root) return combined, tree, tmp
def test_mscz(self): tmp = helper.get_tmpfile_path("simple.mscz") tree = MscoreXmlTree(tmp) result = tree.xml_tree.xpath("/museScore/Score/Style") self.assertEqual(result[0].tag, "Style")
def test_method_save_new_name(self): tmp = helper.get_tmpfile_path("simple.mscx") tree = MscoreXmlTree(tmp) tree.save(new_name=tmp) result = helper.read_file(tmp) self.assertTrue('<metaTag name="arranger"></metaTag>' in result)
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 _init_class(self, filename, version=2): tmp = helper.get_tmpfile_path(filename, version) tree = MscoreXmlTree(tmp) interface = InterfaceReadWrite(tree.xml_root) return interface, tree, tmp
def _init_class(self, filename, version=2): tmp = helper.get_tmpfile_path(filename, version) tree = MscoreXmlTree(tmp) meta = MetaTag(tree.xml_root) return meta, tree, tmp
def _init_class(self, filename, version=2): tmp = helper.get_tmpfile_path(filename, version) tree = MscoreXmlTree(tmp) vbox = Vbox(tree.xml_root) return vbox, tree, tmp