-
Notifications
You must be signed in to change notification settings - Fork 1
/
sorter.py
executable file
·137 lines (112 loc) · 5.05 KB
/
sorter.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
# vim: set expandtab tabstop=4 shiftwidth=4:
# Copyright 2019-2022 Christopher J. Kucera
# <http://apocalyptech.com/contact.php>
#
# This file is part of Wonderlands ModCabinet Sorter.
#
# Wonderlands ModCabinet Sorter 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.
#
# Wonderlands ModCabinet Sorter 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 Wonderlands ModCabinet Sorter. If not, see
# <https://www.gnu.org/licenses/>.
import os
import sys
import appdirs
import argparse
from wlcabinetsorter.app import App
if __name__ == '__main__':
# Figure out a default INI file location if we weren't passed anything
default_config_file = os.path.join(
appdirs.user_config_dir('wlcabinetsorter', 'Apocalyptech'),
'wlcabinetsorter.ini',
)
parser = argparse.ArgumentParser(
description='BLCM WL ModCabinet Auto-Sorter',
# The "defaults" formatter ends up being weird since most of our
# booleans are setting False rather than True, so don't use it.
#formatter_class=argparse.ArgumentDefaultsHelpFormatter,
# Note that all text will get mashed together in a single paragraph
# regardless of formatting here, so don't sweat that too much.
epilog="""
Use the -g/--no-git or -c/--no-commit options to avoid
git integration, which can be quite useful when you're
iterating through code/template changes but probably not of
much use otherwise.
The -i/--initial argument will also do an initial
"first-time-run" task of looping through the github repo
setting all file mtimes to be equal to their most-
recently-updated timestamp in the git tree.
By default the app will quit early when no update is found in
the mods repo, but -f/--force can be used to force it to
continue regardless.
-q/--quiet and -v/--verbose can be used to control how much
information is printed on the console while running. With
quiet mode, only critical errors will be printed.
The default config file location is at `{}`. To specify an
alternate config file, use -o/--config. Use the file
`wlcabinetsorter.ini.example` as a basis for the file.
To ignore any existing caches and make a run from scratch,
specify -x/--ignore-cache.
""".format(default_config_file)
)
parser.add_argument('-g', '--no-git',
dest='do_git',
action='store_false',
help='Don\'t interact with git in any way while running (implies --no-commit)',
)
parser.add_argument('-c', '--no-commit',
dest='do_git_commit',
action='store_false',
help='Don\'t do any git commit actions after processing.',
)
parser.add_argument('-i', '--initial',
dest='do_initial_tasks',
action='store_true',
help='Do some first-time-run initial tasks to get the github repo dir ready',
)
parser.add_argument('-f', '--force',
action='store_true',
help='Force update of wiki even if there have not been any repo changes',
)
parser.add_argument('-o', '--config',
default=default_config_file,
help='Specify a path to a configuration INI file',
)
parser.add_argument('-x', '--ignore-cache',
dest='load_cache',
action='store_false',
help='Ignore any existing cache files and load everything from scratch.',
)
loggroup = parser.add_mutually_exclusive_group()
loggroup.add_argument('-q', '--quiet',
action='store_true',
help='Supress all but critical error messages',
)
loggroup.add_argument('-v', '--verbose',
action='store_true',
help='Print as much information as possible',
)
args = parser.parse_args()
# Check to make sure our config file exists
if not os.path.exists(args.config):
raise Exception('Could not find config file {}'.format(args.config))
app = App(args.config)
sys.exit(app.run(
do_git=args.do_git,
do_git_commit=args.do_git_commit,
do_initial_tasks=args.do_initial_tasks,
force_run=args.force,
quiet=args.quiet,
verbose=args.verbose,
load_cache=args.load_cache,
))