-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagic.py
50 lines (42 loc) · 1.38 KB
/
magic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import argparse
import mvalid
import magicplaytest
import msewriter
parser = argparse.ArgumentParser(description='Validate magic files')
parser.add_argument('filename', help='the file to validate')
parser.add_argument('-m', '--make-playtest', action='store_true')
parser.add_argument('-e', '--make-mse-set', action='store_true')
parser.add_argument('-s', '--show', action='store_true')
parser.add_argument('-d', '--directory', action='store_true')
parser.add_argument('-o', '--out-file')
args = parser.parse_args()
def parse_file(filename):
file = open(filename)
cards = mvalid.mvalid(file.read())
file.close()
return cards
if args.directory:
cards = []
import os
for (dirpath, dirnames, filenames) in os.walk(args.filename):
for filename in filenames:
if filename.endswith(".txt"):
cards.extend(parse_file(os.path.join(dirpath, filename)))
else:
cards = parse_file(args.filename)
if args.show:
print cards
if args.make_playtest:
if hasattr(args, 'outfile'):
outfile = args.outfile
else:
outfile = args.filename + ".pdf"
magicplaytest.make_playtest(cards, outfile)
if args.make_mse_set:
if hasattr(args, 'outfile'):
outfile = args.outfile
else:
outfile = args.filename + ".mse-set"
set_writer = msewriter.MseWriter(outfile)
set_writer.writeset(cards)
set_writer.finalize()