Skip to content

Commit 2b90cde

Browse files
author
James Boulton
committedApr 26, 2023
Tidy up c64_decode
1 parent 0a1c9e3 commit 2b90cde

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed
 

‎setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="dashio",
8-
version="3.3.5",
8+
version="3.3.6",
99
description="DashIO interface library",
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",

‎utilities/c64_decode

+38-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
11
#!/usr/bin/env python3
22
import dashio
33
import json
4-
import sys
54
import os
5+
import argparse
66

7-
c64_filename = sys.argv[1]
8-
json_filename = os.path.splitext(c64_filename)[0] + ".json"
9-
try:
10-
with open(c64_filename, mode="r") as fp:
11-
cfg64 = fp.read()
127

13-
except FileNotFoundError:
14-
print("File not found")
8+
def parse_commandline_arguments():
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument('file', help="Input file name.")
11+
parser.add_argument("-p", "--print", dest="print", action='store_true', help="Print output.")
12+
parser.add_argument("-o", "--out", dest="out_file", default="", help="output filename.")
13+
parser.add_argument("-i", "--indent", dest="indent", type=int, default=4, help="Indent depth (Default 4).")
1514

16-
# Remove formatting for different languages
17-
cfg64 = cfg64.translate({ord(i): None for i in '"\n \\;'})
15+
args = parser.parse_args()
16+
return args
1817

19-
print(cfg64)
20-
config_dict = dashio.decode_cfg64(cfg64)
21-
cfg_json = json.dumps(config_dict, indent=4)
22-
print(cfg_json)
18+
def main():
19+
args = parse_commandline_arguments()
2320

24-
json_file = open(json_filename, "w")
25-
json_file.write(cfg_json)
26-
json_file.close()
21+
c64_filename = args.file
22+
json_filename = os.path.splitext(c64_filename)[0] + ".json"
23+
24+
if args.out_file:
25+
json_filename = args.out_file
26+
try:
27+
with open(c64_filename, mode="r") as fp:
28+
cfg64 = fp.read()
29+
except FileNotFoundError:
30+
print("File not found")
31+
32+
# Remove formatting for different languages
33+
cfg64 = cfg64.translate({ord(i): None for i in '"\n \\;'})
34+
35+
config_dict = dashio.decode_cfg64(cfg64)
36+
cfg_json = json.dumps(config_dict, indent=args.indent)
37+
38+
if args.print:
39+
print(cfg_json)
40+
41+
json_file = open(json_filename, "w")
42+
json_file.write(cfg_json)
43+
json_file.close()
44+
45+
46+
if __name__ == "__main__":
47+
main()

0 commit comments

Comments
 (0)
Please sign in to comment.