forked from dominions-tools/dominions-tools
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdominions-data-tool
executable file
·117 lines (96 loc) · 4.36 KB
/
dominions-data-tool
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python
###############################################################################
# dominions #
#-----------------------------------------------------------------------------#
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# #
###############################################################################
"""
Extract all relevant data from a Dominions executable and dump into a
database for further processing.
"""
__docformat__ = "reStructuredText"
import sys as _sys
import os
from os.path import (
extsep as _path_extsep,
curdir as _path_curdir,
join as _path_join,
exists as _path_exists,
isdir as _path_is_directory,
dirname as _path_dirname,
)
import argparse as _argparse
from sqlalchemy import (
create_engine as _SQLA_create_engine,
)
from dominions.utils import (
PrettyFormatConfig as _PrettyFormatConfig,
)
from dominions.DominionsData import (
DominionsData as _DominionsData,
)
if "__main__" == __name__:
rc = 0
clargs_parser = _argparse.ArgumentParser(
description = \
"""Dumps information baked into a Dominions game executable."""
)
clargs_parser.add_argument(
"-I", "--input-directory-path", metavar = "DIRECTORY", type = str,
default = _path_join( _path_dirname( _sys.argv[ 0 ] ), "data"),
)
clargs_parser.add_argument(
"-O", "--output-directory-path", metavar = "DIRECTORY", type = str,
default = _path_curdir,
)
clargs_parser.add_argument(
"dominions_program_path", metavar = "FILE", type = str,
)
clargs = clargs_parser.parse_args( )
output_directory_path = clargs.output_directory_path
if not _path_exists( output_directory_path ):
os.mkdir( output_directory_path, 0o700 )
else:
if not _path_is_directory( output_directory_path ):
raise IOError( "Not a directory: {0}".format(
output_directory_path
) )
if not os.access( output_directory_path, os.R_OK | os.W_OK | os.X_OK ):
raise IOError( "Could not access directory: {0}".format(
output_directory_path
) )
input_directory_path = clargs.input_directory_path
if not os.access( input_directory_path, os.R_OK | os.X_OK ):
raise IOError( "Could not access directory: {0}".format(
input_directory_path
) )
dominions_program_path = clargs.dominions_program_path
pformat_config = _PrettyFormatConfig( )
dominions_data = _DominionsData.from_program_and_data_files(
dominions_program_path, input_directory_path
)
# TODO: Control kinds of output from command line arguments.
dominions_data.pprint(
output_directory_path, pformat_config = pformat_config
)
# TEMP: Hardwire to SQLite3 database.
db_engine = _SQLA_create_engine( "sqlite:///{0}".format( _path_join(
output_directory_path,
"Dominions" + _path_extsep + "sqlite"
) ), echo = False )
dominions_data.persist_in_database( db_engine )
raise SystemExit( rc )
###############################################################################
# vim: set ft=python ts=4 sts=4 sw=4 et tw=79: #