26
26
import sys
27
27
import json
28
28
import polib
29
+ import argparse
29
30
30
31
if sys .version_info [0 ] < 3 :
31
32
raise Exception ("Please use Python 3 (current is {})" .format (
40
41
common_names = set ()
41
42
cons_ast_names = set ()
42
43
44
+ def ensure_dir (file_path ):
45
+ '''Create a directory for a path if it doesn't exist yet'''
46
+ directory = os .path .dirname (file_path )
47
+ if not os .path .exists (directory ):
48
+ os .makedirs (directory )
49
+
43
50
def is_sky_culture_dir (d ):
44
51
if not os .path .isdir (os .path .join (SCDIR , d )):
45
52
return False
@@ -65,22 +72,7 @@ def load_common_names():
65
72
common_names .add (match .group (1 ))
66
73
print (f"Loaded { len (common_names )} common names" , file = sys .stderr )
67
74
68
- def update_descriptions_pot ():
69
- sclist = [d for d in os .listdir (SCDIR ) if is_sky_culture_dir (d )]
70
- sclist .sort ()
71
-
72
- pot = polib .POFile (encoding = 'utf-8' , check_for_duplicates = True )
73
- pot .metadata = {
74
- 'Project-Id-Version' : 'PACKAGE VERSION' ,
75
- 'Report-Msgid-Bugs-To' :
'[email protected] ' ,
76
- 'Last-Translator' : 'FULL NAME <EMAIL@ADDRESS>' ,
77
- 'Language-Team' :
'LANGUAGE <[email protected] >' ,
78
- 'Language' : '' ,
79
- 'MIME-Version' : '1.0' ,
80
- 'Content-Type' : 'text/plain; charset=UTF-8' ,
81
- 'Content-Transfer-Encoding' : '8bit'
82
- }
83
-
75
+ def update_descriptions_pot (sclist , pot ):
84
76
for sky_culture in sclist :
85
77
data_path = os .path .join (SCDIR , sky_culture )
86
78
description_file = os .path .join (data_path , 'description.md' )
@@ -142,24 +134,7 @@ def update_descriptions_pot():
142
134
else :
143
135
pot .append (entry )
144
136
145
- pot .save (DESCPOTFILE )
146
-
147
- def update_cultures_pot ():
148
- sclist = [d for d in os .listdir (SCDIR ) if is_sky_culture_dir (d )]
149
- sclist .sort ()
150
-
151
- pot = polib .POFile (encoding = 'utf-8' , check_for_duplicates = True )
152
- pot .metadata = {
153
- 'Project-Id-Version' : 'PACKAGE VERSION' ,
154
- 'Report-Msgid-Bugs-To' :
'[email protected] ' ,
155
- 'Last-Translator' : 'FULL NAME <EMAIL@ADDRESS>' ,
156
- 'Language-Team' :
'LANGUAGE <[email protected] >' ,
157
- 'Language' : '' ,
158
- 'MIME-Version' : '1.0' ,
159
- 'Content-Type' : 'text/plain; charset=UTF-8' ,
160
- 'Content-Transfer-Encoding' : '8bit'
161
- }
162
-
137
+ def update_cultures_pot (sclist , pot ):
163
138
def process_cons_or_asterism (array , obj_type , pot , sc_name ):
164
139
for obj in array :
165
140
assert 'id' in obj
@@ -313,13 +288,50 @@ def process_names(objects, pot, sc_name):
313
288
if 'common_names' in data :
314
289
process_names (data ['common_names' ], pot , sc_name )
315
290
316
- pot .save (SCPOTFILE )
291
+ if __name__ == '__main__' :
292
+ parser = argparse .ArgumentParser ()
293
+ parser .add_argument ("-s" , "--sky-culture" , help = "Process only the specified sky culture" )
294
+ args = parser .parse_args ()
295
+ metadata_template = {
296
+ 'Project-Id-Version' : 'PACKAGE VERSION' ,
297
+ 'Report-Msgid-Bugs-To' :
'[email protected] ' ,
298
+ 'Last-Translator' : 'FULL NAME <EMAIL@ADDRESS>' ,
299
+ 'Language-Team' :
'LANGUAGE <[email protected] >' ,
300
+ 'Language' : '' ,
301
+ 'MIME-Version' : '1.0' ,
302
+ 'Content-Type' : 'text/plain; charset=UTF-8' ,
303
+ 'Content-Transfer-Encoding' : '8bit'
304
+ }
305
+ if args .sky_culture :
306
+ sclist = [args .sky_culture ]
307
+ desc_pot = polib .POFile (encoding = 'utf-8' , check_for_duplicates = True )
308
+ desc_pot .metadata = metadata_template
309
+ sc_pot = desc_pot # same file for everything
310
+ desc_pot_file_path = None
311
+ sc_pot_file_path = None
312
+ common_pot_file_path = os .path .join (SCDIR , args .sky_culture , 'po' , args .sky_culture + '.pot' )
313
+ ensure_dir (common_pot_file_path )
314
+ else :
315
+ sclist = [d for d in os .listdir (SCDIR ) if is_sky_culture_dir (d )]
316
+ sclist .sort ()
317
+ desc_pot = polib .POFile (encoding = 'utf-8' , check_for_duplicates = True )
318
+ desc_pot .metadata = metadata_template
319
+ sc_pot = polib .POFile (encoding = 'utf-8' , check_for_duplicates = True )
320
+ sc_pot .metadata = metadata_template
321
+ desc_pot_file_path = DESCPOTFILE
322
+ sc_pot_file_path = SCPOTFILE
323
+ common_pot_file_path = None
317
324
318
325
319
- if __name__ == '__main__' :
320
326
print ("Loading common names..." , file = sys .stderr )
321
327
load_common_names ()
322
328
print ("Updating descriptions .pot file..." , file = sys .stderr )
323
- update_descriptions_pot ()
329
+ update_descriptions_pot (sclist , desc_pot )
330
+ if desc_pot_file_path :
331
+ desc_pot .save (desc_pot_file_path )
324
332
print ("Updating SC index .pot file..." , file = sys .stderr )
325
- update_cultures_pot ()
333
+ update_cultures_pot (sclist , sc_pot )
334
+ if sc_pot_file_path :
335
+ sc_pot .save (sc_pot_file_path )
336
+ if common_pot_file_path :
337
+ sc_pot .save (common_pot_file_path )
0 commit comments