22
22
23
23
import argparse
24
24
import sh
25
-
25
+ from appdirs import user_data_dir
26
26
27
27
from pythonforandroid .recipe import (Recipe , PythonRecipe , CythonRecipe ,
28
28
CompiledComponentsPythonRecipe ,
@@ -171,8 +171,6 @@ def split_argument_list(l):
171
171
class ToolchainCL (object ):
172
172
173
173
def __init__ (self ):
174
- self ._ctx = None
175
-
176
174
parser = argparse .ArgumentParser (
177
175
description = "Tool for managing the Android / Python toolchain" ,
178
176
usage = """toolchain <command> [<args>]
@@ -206,18 +204,23 @@ def __init__(self):
206
204
'--debug' , dest = 'debug' , action = 'store_true' ,
207
205
help = 'Display debug output and all build info' )
208
206
parser .add_argument (
209
- '--sdk_dir' , dest = 'sdk_dir' , default = '' ,
207
+ '--sdk-dir' , '-- sdk_dir' , dest = 'sdk_dir' , default = '' ,
210
208
help = 'The filepath where the Android SDK is installed' )
211
209
parser .add_argument (
212
- '--ndk_dir' , dest = 'ndk_dir' , default = '' ,
210
+ '--ndk-dir' , '-- ndk_dir' , dest = 'ndk_dir' , default = '' ,
213
211
help = 'The filepath where the Android NDK is installed' )
214
212
parser .add_argument (
215
- '--android_api' , dest = 'android_api' , default = 0 , type = int ,
213
+ '--android-api' , '-- android_api' , dest = 'android_api' , default = 0 , type = int ,
216
214
help = 'The Android API level to build against.' )
217
215
parser .add_argument (
218
- '--ndk_version' , dest = 'ndk_version' , default = '' ,
216
+ '--ndk-version' , '-- ndk_version' , dest = 'ndk_version' , default = '' ,
219
217
help = ('The version of the Android NDK. This is optional, '
220
218
'we try to work it out automatically from the ndk_dir.' ))
219
+ parser .add_argument (
220
+ '--storage-dir' , dest = 'storage_dir' ,
221
+ default = self .default_storage_dir ,
222
+ help = ('Primary storage directory for downloads and builds '
223
+ '(default: {})' .format (self .default_storage_dir )))
221
224
222
225
# AND: This option doesn't really fit in the other categories, the
223
226
# arg structure needs a rethink
@@ -228,7 +231,7 @@ def __init__(self):
228
231
229
232
# Options for specifying the Distribution
230
233
parser .add_argument (
231
- '--dist_name' ,
234
+ '--dist-name' , '-- dist_name' ,
232
235
help = 'The name of the distribution to use or create' ,
233
236
default = '' )
234
237
parser .add_argument (
@@ -291,6 +294,10 @@ def __init__(self):
291
294
292
295
if args .debug :
293
296
logger .setLevel (logging .DEBUG )
297
+
298
+ self .ctx = Context ()
299
+ self .storage_dir = args .storage_dir
300
+ self .ctx .setup_dirs (self .storage_dir )
294
301
self .sdk_dir = args .sdk_dir
295
302
self .ndk_dir = args .ndk_dir
296
303
self .android_api = args .android_api
@@ -322,6 +329,13 @@ def __init__(self):
322
329
323
330
getattr (self , args .command )(unknown )
324
331
332
+ @property
333
+ def default_storage_dir (self ):
334
+ udd = user_data_dir ('python-for-android' )
335
+ if ' ' in udd :
336
+ udd = '~/.python-for-android'
337
+ return udd
338
+
325
339
def _read_configuration (self ):
326
340
# search for a .p4a configuration file in the current directory
327
341
if not exists (".p4a" ):
@@ -335,12 +349,6 @@ def _read_configuration(self):
335
349
for arg in line :
336
350
sys .argv .append (arg )
337
351
338
- @property
339
- def ctx (self ):
340
- if self ._ctx is None :
341
- self ._ctx = Context ()
342
- return self ._ctx
343
-
344
352
def recipes (self , args ):
345
353
parser = argparse .ArgumentParser (
346
354
description = "List all the available recipes" )
@@ -409,7 +417,7 @@ def clean_dists(self, args):
409
417
parser = argparse .ArgumentParser (
410
418
description = "Delete any distributions that have been built." )
411
419
args = parser .parse_args (args )
412
- ctx = Context ()
420
+ ctx = self . ctx
413
421
if exists (ctx .dist_dir ):
414
422
shutil .rmtree (ctx .dist_dir )
415
423
@@ -424,7 +432,7 @@ def clean_builds(self, args):
424
432
parser = argparse .ArgumentParser (
425
433
description = "Delete all build files (but not download caches)" )
426
434
args = parser .parse_args (args )
427
- ctx = Context ()
435
+ ctx = self . ctx
428
436
# if exists(ctx.dist_dir):
429
437
# shutil.rmtree(ctx.dist_dir)
430
438
if exists (ctx .build_dir ):
@@ -462,7 +470,7 @@ def clean_download_cache(self, args):
462
470
parser = argparse .ArgumentParser (
463
471
description = "Delete all download caches" )
464
472
args = parser .parse_args (args )
465
- ctx = Context ()
473
+ ctx = self . ctx
466
474
if exists (ctx .packages_path ):
467
475
shutil .rmtree (ctx .packages_path )
468
476
@@ -627,7 +635,7 @@ def print_context_info(self, args):
627
635
python-for-android will internally use for package building, along
628
636
with information about where the Android SDK and NDK will be called
629
637
from.'''
630
- ctx = Context ()
638
+ ctx = self . ctx
631
639
for attribute in ('root_dir' , 'build_dir' , 'dist_dir' , 'libs_dir' ,
632
640
'ccache' , 'cython' , 'sdk_dir' , 'ndk_dir' ,
633
641
'ndk_platform' , 'ndk_ver' , 'android_api' ):
@@ -647,7 +655,7 @@ def dists(self, args):
647
655
def distributions (self , args ):
648
656
'''Lists all distributions currently available (i.e. that have already
649
657
been built).'''
650
- ctx = Context ()
658
+ ctx = self . ctx
651
659
dists = Distribution .get_distributions (ctx )
652
660
653
661
if dists :
0 commit comments