-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
executable file
·100 lines (77 loc) · 3.2 KB
/
__main__.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
# This file is part of botwtools.
LICENSE = """
botwtools is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
botwtools is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with botwtools. If not, see <https://www.gnu.org/licenses/>.
"""
import sys
if sys.version_info < (3, 0):
raise RuntimeError("This program requires Python 3.")
import logger; logger.setup('botwtools')
log = logger.logging.getLogger()
import argparse
from app import App
import codec
arg_parser = None # declare global
def _setupArgs():
global arg_parser
parser = argparse.ArgumentParser(
description="Breath of the Wild modding tools.")
arg_parser = parser
parser.add_argument('--extract', '-x', nargs=2, action='append',
metavar=('PATH', 'DESTPATH'), default=[],
help="Extract file to specified path.")
parser.add_argument('--extract-recursive', '-X', nargs=2,
action='append', metavar=('PATH', 'DESTPATH'), default=[],
help="Extract file recursively (ie extract the extracted file).")
parser.add_argument('--dry-run', action='store_true',
help="Do not actually create any files.")
parser.add_argument('--list', '-l', nargs=1, action='append',
metavar='PATH', default=[],
help="List contents of file.")
parser.add_argument('--list-recursive', '-L', nargs=1,
action='append', metavar='PATH', default=[],
help="List contents of file recursively.")
parser.add_argument('--show-xml', nargs=1, action='append',
metavar='PATH', default=[],
help="Display XML file as tree.")
parser.add_argument('--list-codecs', action='store_true',
help="List supported file formats.")
parser.add_argument('--license', action='store_true',
help="Print this program's license.")
parser.add_argument('--debug', action='store_true',
help="Print debug messages.")
return parser.parse_args()
def main():
global arg_parser
args = _setupArgs()
if not any(vars(args).values()): # no argument given
#arg_parser.print_help()
from ui import UI
UI().run()
return 0
if not args.debug: log.setLevel(logger.logging.INFO)
if args.license: print(LICENSE)
app = App()
if args.list_codecs: app.list_codecs()
app.readOnly = args.dry_run
if app.readOnly: log.info("Dry run; not writing any files!")
for arg in args.list: app.list_file(*arg)
for arg in args.list_recursive: app.list_file_recursive(*arg)
for arg in args.extract: app.extract_file(*arg)
for arg in args.extract_recursive: app.extract_recursive(*arg)
for arg in args.show_xml: app.show_xml(*arg)
return 0
if __name__ == '__main__':
try:
sys.exit(main())
except codec.UnsupportedFileTypeError as ex:
sys.stderr.write(str(ex))