-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapset.py
executable file
·407 lines (314 loc) · 10.8 KB
/
mapset.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import configparser
import os
import argparse
import build_config
import time
WORK_DIR = os.path.expanduser('~') + "/map_build/"
# set prefix for messages
def info(msg):
print("II: " + msg)
def warn(msg):
print("WW: " + msg)
def error(msg):
print("EE: " + msg)
if not os.path.exists(WORK_DIR):
error("Please create" + WORK_DIR)
quit()
os.chdir(WORK_DIR)
# configparser
def write_config():
with open('pygmap3.cfg', 'w') as configfile:
config.write(configfile)
config = configparser.ConfigParser()
if not os.path.exists("pygmap3.cfg"):
build_config.create()
else:
build_config.update()
config.read('pygmap3.cfg')
# argparse
parser = argparse.ArgumentParser(
prog='PROG',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=('''\
This program create mapsets for different regions for Garmin PNA
'''))
# mapsets
parser.add_argument('-am', '--add_mapset', default=0, nargs='*',
help="add a space separated list of mapsets")
parser.add_argument('-af', '--all_folder', action="store_true",
help="add all folder in " +
WORK_DIR + "gps_ready/zipped" +
" to the mapset list")
parser.add_argument('-ap', '--all_poly', action="store_true",
help="same as before with the poly files in " +
WORK_DIR + "poly")
parser.add_argument('-ao', '--all_o5m', action="store_true",
help="same as before with the o5m files in " +
WORK_DIR + "o5m")
parser.add_argument('-em', '--enable_mapset', default=0, nargs='*',
help="enable a space separated list of mapsets")
parser.add_argument('-ea', '--enable_all', action="store_true",
help="enable all mapsets")
parser.add_argument('-rst', '--restore', action="store_true",
help="restore mapsets from mapset_backup")
parser.add_argument('-dm', '--disable_mapset', default=0, nargs='*',
help="disable a space separated list of mapsets")
parser.add_argument('-da', '--disable_all', action="store_true",
help="disable all mapsets")
parser.add_argument('-rm', '--remove_mapset', default=0, nargs='*',
help="delete a space separated list of mapsets," +
" ALL for all mapsets on the list")
parser.add_argument('-lm', '--list_mapset', action="store_true",
help="print out the mapset list")
parser.add_argument('-fb', '--fastbuild', default=0, nargs='*',
help="a space separated list of mapsets")
parser.add_argument('-fs', '--faststyle', default=0, nargs='*',
help="a space separated list of styles for the default " +
"region, to set the region, us 'pygmap3.py -s $REGION' ")
parser.add_argument('-ba', '--break_after', default=0,
help="break mapset creating after this" +
" changeset, use '-lm' for the list")
# pygmap3
parser.add_argument('-nz', '--no_zip', action="store_true",
help="don't zip the images after build")
parser.add_argument('-c', '--contourlines', action="store_true",
help="enable countourlines layer creation")
parser.add_argument('-st', '--stop_after', default=0,
help="build process stop after" +
" [tests|contourlines|mapdata|splitter|mkgmap]")
parser.add_argument('-l', '--log', action="store_true",
help="enable splitter and mkgmap logging")
parser.add_argument('-v', '--verbose', action="store_true",
help="increase verbosity")
parser.add_argument('-mt', '--test', action="store_true",
help="use a svn version of mkgmap like housenumbers2")
parser.add_argument('-so', '--spec_opts', action="store_true",
help="use some special opts to test the raw data")
args = parser.parse_args()
def mapset_backup():
if not config.has_section('mapset_backup'):
config.add_section('mapset_backup')
for key in (config['mapset']):
config.set('mapset_backup', key, config['mapset'][key])
config.set('mapset', key, 'no')
def mapset_restore():
if config.has_section('mapset'):
config.remove_section('mapset')
config.add_section('mapset')
for key in (config['mapset_backup']):
config.set('mapset', key, config['mapset_backup'][key])
config.remove_option('mapset_backup', key)
config.remove_section('mapset_backup')
if config.has_option('runtime', 'fix_mapset'):
config.remove_option('runtime', 'fix_mapset')
if args.faststyle:
if not args.fastbuild:
mapset_backup()
config.set('mapset', config['runtime']['default_region'], 'yes')
if not config.has_section('faststyle'):
config.add_section('faststyle')
for style in args.faststyle:
if not config.has_section('mapstyles'):
config.add_section('mapstyles')
if os.path.exists("styles/" + style + "_style"):
config.set('mapstyles', style, 'yes')
config.set('faststyle', style, 'yes')
else:
print()
warn("Style " + style + " not found")
print()
config.set('runtime', 'faststyle', '1')
if args.fastbuild:
mapset_backup()
for region in args.fastbuild:
if os.path.exists("poly/" + region + ".poly" or
"o5m/" + region + ".o5m"):
config.set('mapset', region, 'yes')
else:
print()
warn("Neither " + region + ".poly nor " + region + ".o5m found!")
print()
# set, edit or delete mapset list
if args.all_poly:
path = WORK_DIR + "poly"
dir = sorted(os.listdir(path))
for file in dir:
file = os.path.splitext(file)[0]
if config.has_option('mapset', file):
continue
else:
config.set('mapset', file, 'no')
write_config()
print()
warn("ALL poly files added to mapset list but not enabled!")
print()
quit()
if args.all_o5m:
path = WORK_DIR + "o5m"
dir = sorted(os.listdir(path))
for file in dir:
file = os.path.splitext(file)[0]
if config.has_option('mapset', file):
continue
else:
config.set('mapset', file, 'no')
write_config()
print()
warn("ALL o5m files added to mapset list but not enabled!!")
print()
quit()
if args.all_folder:
path = WORK_DIR + "gps_ready/zipped"
dir = sorted(os.listdir(path))
for folder in dir:
if not config.has_option('mapset', folder):
config.set('mapset', folder, 'yes')
for key in dir:
config.set('mapset', key, 'yes')
if args.add_mapset:
for region in args.add_mapset:
file = os.path.splitext(os.path.basename(region))[0]
if not config.has_option('mapset', region):
if not os.path.exists("poly/" + region + ".poly"):
print()
error(WORK_DIR + "poly/" + file + ".poly not found... ")
print("please create or download " + file + ".poly")
print()
quit()
config.set('mapset', region, 'yes')
if not config.has_section(region):
config.add_section(region)
config.set(region, 'new_region', 'yes')
write_config()
print()
info("please check the options for this mapset with: pygmap3.py -e")
print()
quit()
if args.restore:
if config.has_section('mapset_backup'):
mapset_restore()
write_config()
quit()
if args.enable_mapset:
for region in args.enable_mapset:
config.set('mapset', region, 'yes')
write_config()
quit()
# 'fix_mapset' to prevent overwriting mapset_backup
# if 'args.enable_all' is used twice or more
if args.enable_all:
if config.has_option('runtime', 'fix_mapset'):
quit()
mapset_backup()
for region in (config['mapset']):
config.set('mapset', region, 'yes')
config.set('runtime', 'fix_mapset', '1')
write_config()
quit()
if args.disable_mapset:
for region in args.disable_mapset:
config.set('mapset', region, 'no')
write_config()
quit()
if args.disable_all:
mapset_backup()
for region in (config['mapset']):
config.set('mapset', region, 'no')
write_config()
quit()
if args.remove_mapset:
if args.remove_mapset == "ALL":
config.remove_section('mapset')
else:
for region in args.remove_mapset:
config.remove_option('mapset', region)
write_config()
quit()
if args.list_mapset:
if config.has_section('mapset'):
print()
info("mapset list includes: ")
print()
print(" enabled:")
for key in (config['mapset']):
if config['mapset'][key] == "yes":
print(" " + key)
print()
print(" disabled:")
for key in config['mapset']:
if config['mapset'][key] == "no":
print(" " + key)
else:
print()
info("mapset list didn't exist")
print()
quit()
write_config()
# build or additional option for pygmap3
if args.stop_after:
stop = "-st " + args.stop_after + " "
else:
stop = ""
if args.contourlines:
cl = "-c "
else:
cl = ""
if args.test and config.has_option('runtime', 'test'):
test = "-mt "
else:
test = ""
if args.no_zip:
zip = ""
else:
zip = "-z "
if args.verbose:
verbose = "-v "
else:
verbose = ""
if args.log:
log = "--log "
else:
log = ""
if args.spec_opts:
so = " -so "
else:
so = " "
command_line = ("pygmap3.py -kg " +
verbose + stop + cl + test + log + zip)
config.set('runtime', 'mapset', "1")
write_config()
for region in config['mapset']:
if config['mapset'][region] == "yes":
print()
info("next mapset to create is " + region)
print()
print(" In the next 5 seconds you can stop ")
print(" building the maps with STRG+C ")
print()
print(" continue?")
counter = 5
while counter > 0:
counter -= 1
time.sleep(1)
if region == args.break_after:
print()
warn("Stopping creating mapsets after this mapset")
os.system(command_line + "-r " + region)
if region == args.break_after:
quit()
if config.has_section('mapset_backup'):
mapset_restore()
if config.has_section('faststyle'):
for key in (config['faststyle']):
config.remove_option('faststyle', key)
config.remove_section('faststyle')
if config.has_option('runtime', 'faststyle'):
config.remove_option('runtime', 'faststyle')
config.set('runtime', 'mapset', "0")
write_config()
print()
print("###### all mapsets successfully build! #######")
print()
quit()