Skip to content

Commit 35f87d2

Browse files
authored
Add files via upload
1 parent 3686aae commit 35f87d2

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

mamexmlsplitter.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# MAME XML Splitter
2+
# Author: NebularNerd Version 1.0 (2022)
3+
# https://github.com/NebularNerd/mamexmlsplitter
4+
# Import required packages
5+
import sys
6+
import os
7+
import os.path
8+
9+
# Setup argparse
10+
import argparse
11+
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,description='Split MAME.xml into custom .xml, Great for Neo-Geo, Naomi, AtomisWave etc...\nVisit https://github.com/NebularNerd/mamexmlsplitter for more information')
12+
parser.add_argument("--file", "-f", type=str, required=True, help='Path to MAME.xml file, enclose in quotes if path has spaces')
13+
parser.add_argument("--sourcefile", "-src", type=str, required=True, help='Name of system sourcefile, e.g. naomi.cpp')
14+
args = parser.parse_args()
15+
# Setup some basic file wrangling stuff
16+
inputfile = os.path.normpath(args.file)
17+
inputdirectory = os.path.dirname(args.file)
18+
outputfile = os.path.join(inputdirectory +"\\mame-"+ args.sourcefile[:-4]+".xml")
19+
print('MAME.xml Splitter 1.0\n')
20+
print('Input .xml file : ',args.file)
21+
print('String to search for : ',args.sourcefile)
22+
print('Output .xml file : ',outputfile,"\n\n")
23+
24+
# Now we do stuff
25+
# Parts adapted from https://stackoverflow.com/questions/55264953/copy-lines-between-two-strings-to-another-file and https://stackoverflow.com/questions/58773880/str-contains-pandas-returns-str-object-has-no-attribute-contains
26+
answer = None
27+
while answer not in ("y","n"):
28+
answer = input("Shall we proceed? ")
29+
if answer == "y":
30+
textfile = open(inputfile, 'r', encoding="utf8")
31+
writing = False
32+
linecount = 0
33+
firstline = 0
34+
line1 = '<?xml version="1.0"?>\n<mame>\n'
35+
lastline = "</mame>"
36+
with open(inputfile, 'r', encoding="utf8") as original, open(outputfile, 'w', encoding="utf8") as new:
37+
for line in original:
38+
if firstline == 0:
39+
new.write(line1)
40+
firstline = firstline+1
41+
if args.sourcefile in line:
42+
writing = True
43+
elif '</machine>' in line and linecount > 1:
44+
new.write(line)
45+
writing = False
46+
linecount = 0
47+
elif '</machine>' in line:
48+
writing = False
49+
50+
if writing:
51+
new.write(line)
52+
linecount = linecount+1
53+
new.write(lastline)
54+
55+
elif answer == "n":
56+
print ("OK, bye for now...\n\n")
57+
else:
58+
print("Please enter y or n.")
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+

0 commit comments

Comments
 (0)