-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
137 lines (115 loc) · 5.31 KB
/
config.py
File metadata and controls
137 lines (115 loc) · 5.31 KB
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
import argparse
import configparser
import os
import sys
import cfg
def _parse_command_line():
parser = argparse.ArgumentParser(
description='Open IAR Embedded Workbench',
prog=cfg.exec_name)
if cfg.console:
parser.add_argument('--debug',
action='store_true',
help='print debug messages')
subp = parser.add_subparsers(help='see "ewlaunch [sub-command] --help"',
dest='subparser_name')
def opt_installations(p):
p.add_argument(
'--installations',
metavar='FILE',
help='Specify the name of an installations file.')
p.add_argument('--reg', action='store_true',
help='with --installations file: look also in registry')
def opt_open_and_shell(p):
p.add_argument('--select',
action='store_true',
help='always show selection dialog')
p.add_argument('workspace',
nargs='?',
default='',
help='path to workspace/directory')
p.add_argument('--version',
help='version (no selection dialog)')
p.add_argument('--wait',
action='store_true',
help='Wait around until launched EW/shell exits')
if not cfg.console:
p.add_argument('--log',
action='store_true',
help='Always show log when done')
opt_installations(p)
p = subp.add_parser(
'open', help='open an existing workspace, or create a new one')
opt_open_and_shell(p)
p = subp.add_parser('shell', help='open a cmd.exe shell')
opt_open_and_shell(p)
if cfg.console:
p = subp.add_parser(
'command', help='run a command on selected version(s)')
opt_installations(p)
p.add_argument('filter', help='regex that selects EW versions')
p.add_argument('command', nargs='*',
help='command. If not specified, prints EW versions')
p.add_argument('--noheading', action='store_true',
help="don't print EW version before command output")
p = subp.add_parser('dump', help='write known installations to a file')
p.add_argument('--output', nargs='?', metavar='FILE',
default='dump.ini',
help='output file or "-" for stdout'
', default is "dump.ini"')
opt_installations(p)
p = subp.add_parser('scan', help='scan directories for installations')
p.add_argument('directories', metavar='DIR', nargs='+',
help='directory to search for installations')
p.add_argument('--output', nargs='?', metavar='FILE',
default='scan.ini', help='output file or "-" for stdout'
', default is "scan.ini"')
argv = sys.argv[1:]
# pylint: disable=protected-access
root_cmds = ['-h', '--help'] + list(subp._name_parser_map.keys())
if len(argv) < 1 or argv[0] not in root_cmds:
argv.insert(0, 'open')
return parser.parse_args(argv)
def _multiline(s):
return (s.replace(s[0], '') if s[0] == '|' else s) + '\n'
def read():
args = _parse_command_line()
cfg.ewlaunch_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
ini = configparser.ConfigParser()
ini.read(os.path.join(cfg.ewlaunch_dir, 'ewlaunch.ini'))
def getarg(name, fallback=None):
v = getattr(args, name) if name in args else None
return v if v else fallback
def getflag(name, fallback=False):
return getarg(name, ini.getboolean('args', name, fallback=fallback))
def getstr(name, fallback=None):
return getarg(name, ini.get('args', name, fallback=fallback))
cfg.always_show_dialog = getflag('select')
cfg.always_show_log = getflag('log')
cfg.wait_after_launch = getflag('wait')
cfg.installations = getstr('installations')
cfg.reg = getflag('reg', fallback=cfg.installations is None)
cfg.default_version = ini['gui']['default_selected_version']
cfg.default_save = ini.getboolean(
'gui', 'default_selected_save_in_project')
cfg.list_box_lines = ini.getint('gui', 'list_box_lines', fallback=10)
cfg.min_window_width = ini.getint('gui', 'min_window_width', fallback=500)
cfg.info_pane = ini.getboolean('gui', 'info_pane', fallback=True)
cfg.ttk_style = ini.get('gui', 'ttk_style', fallback=None)
cfg.template_header = _multiline(ini['argvars']['template_header'])
cfg.template = _multiline(ini['argvars']['template'])
cfg.template_footer = _multiline(ini['argvars']['template_footer'])
cfg.argvars_path = ini['argvars']['path']
cfg.argvars_version_re = ini['argvars']['version_re']
cfg.workspace_template = _multiline(ini['workspace']['template'])
cfg.shortname = ini['shortname'] if 'shortname' in ini else {}
# command line args:
cfg.subcmd = args.subparser_name
cfg.ws = getarg('workspace', '')
cfg.version = getarg('version')
cfg.out_file = getarg('output')
cfg.rest_args = getarg('directories')
cfg.version_filter = getarg('filter')
if cfg.subcmd == 'command':
cfg.rest_args = getarg('command')
cfg.noheading = getarg('noheading')