33from __future__ import print_function
44
55from os .path import dirname , join , isfile , realpath , relpath , split , exists
6+ from os import makedirs
67import os
78import tarfile
89import time
@@ -59,6 +60,10 @@ def render(template, dest, **kwargs):
5960 keyword arguments as template parameters.
6061 '''
6162
63+ dest_dir = dirname (dest )
64+ if dest_dir and not exists (dest_dir ):
65+ makedirs (dest_dir )
66+
6267 template = environment .get_template (template )
6368 text = template .render (** kwargs )
6469
@@ -95,7 +100,7 @@ def listfiles(d):
95100 if isfile (fn ):
96101 yield fn
97102 else :
98- subdirlist .append (os . path . join (basedir , item ))
103+ subdirlist .append (join (basedir , item ))
99104 for subdir in subdirlist :
100105 for fn in listfiles (subdir ):
101106 yield fn
@@ -112,7 +117,7 @@ def make_python_zip():
112117 print ('No compiled python is present to zip, skipping.' )
113118 print ('this should only be the case if you are using the CrystaX python' )
114119 return
115-
120+
116121 global python_files
117122 d = realpath (join ('private' , 'lib' , 'python2.7' ))
118123
@@ -214,10 +219,10 @@ def make_package(args):
214219 # sys.exit(-1)
215220
216221 # Delete the old assets.
217- if os . path . exists ('assets/public.mp3' ):
222+ if exists ('assets/public.mp3' ):
218223 os .unlink ('assets/public.mp3' )
219224
220- if os . path . exists ('assets/private.mp3' ):
225+ if exists ('assets/private.mp3' ):
221226 os .unlink ('assets/private.mp3' )
222227
223228 # In order to speedup import and initial depack,
@@ -262,7 +267,7 @@ def make_package(args):
262267 # If extra Java jars were requested, copy them into the libs directory
263268 if args .add_jar :
264269 for jarname in args .add_jar :
265- if not os . path . exists (jarname ):
270+ if not exists (jarname ):
266271 print ('Requested jar does not exist: {}' .format (jarname ))
267272 sys .exit (- 1 )
268273 shutil .copy (jarname , 'libs' )
@@ -283,14 +288,27 @@ def make_package(args):
283288
284289 service = False
285290 service_main = join (realpath (args .private ), 'service' , 'main.py' )
286- if os . path . exists (service_main ) or os . path . exists (service_main + 'o' ):
291+ if exists (service_main ) or exists (service_main + 'o' ):
287292 service = True
288293
294+ service_names = []
295+ for entrypoint in args .services :
296+ name , entrypoint = entrypoint .split (":" , 1 )
297+ service_names .append (name )
298+ render (
299+ 'Service.tmpl.java' ,
300+ 'src/{}/Service{}.java' .format (args .package .replace ("." , "/" ), name .capitalize ()),
301+ name = name ,
302+ entrypoint = entrypoint ,
303+ args = args
304+ )
305+
289306 render (
290307 'AndroidManifest.tmpl.xml' ,
291308 'AndroidManifest.xml' ,
292309 args = args ,
293310 service = service ,
311+ service_names = service_names ,
294312 )
295313
296314 render (
@@ -390,6 +408,8 @@ def parse_args(args=None):
390408 'directory' ))
391409 ap .add_argument ('--with-billing' , dest = 'billing_pubkey' ,
392410 help = 'If set, the billing service will be added (not implemented)' )
411+ ap .add_argument ('--service' , dest = 'services' , action = 'append' ,
412+ help = 'Declare a new service entrypoint: NAME:PATH_TO_PY' )
393413
394414 if args is None :
395415 args = sys .argv [1 :]
0 commit comments