From b50fc181692867e32c30c40c8e31d2b6ea75f084 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Sun, 18 Nov 2018 17:55:13 +0000 Subject: [PATCH 1/2] Allowed dists to be overwritten by default --- pythonforandroid/toolchain.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 7fbea5afea..f7d708a151 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -142,6 +142,8 @@ def wrapper_func(self, args): user_ndk_api=self.ndk_api) dist = self._dist if dist.needs_build: + if dist.folder_exists(): # possible if the dist is being replaced + dist.delete() info_notify('No dist exists that meets your requirements, ' 'so one will be built.') build_dist_from_args(ctx, dist, args) @@ -158,7 +160,8 @@ def dist_from_args(ctx, args): name=args.dist_name, ndk_api=args.ndk_api, recipes=split_argument_list(args.requirements), - require_perfect_match=args.require_perfect_match) + require_perfect_match=args.require_perfect_match, + allow_replace_dist=args.allow_replace_dist) def build_dist_from_args(ctx, dist, args): @@ -316,6 +319,12 @@ def __init__(self): description=('Whether the dist recipes must perfectly match ' 'those requested')) + add_boolean_option( + generic_parser, ["allow-replace-dist"], + default=True, + description='Whether existing dist names can be automatically replaced' + ) + generic_parser.add_argument( '--local-recipes', '--local_recipes', dest='local_recipes', default='./p4a-recipes', @@ -921,10 +930,11 @@ def distributions(self, _args): def delete_dist(self, _args): dist = self._dist - if dist.needs_build: + if not dist.folder_exists(): info('No dist exists that matches your specifications, ' 'exiting without deleting.') - shutil.rmtree(dist.dist_dir) + return + dist.delete() def sdk_tools(self, args): """Runs the android binary from the detected SDK directory, passing From 1f2291e58b53cefcd3616147834ad7da9b363549 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Sun, 18 Nov 2018 17:56:01 +0000 Subject: [PATCH 2/2] Allowed dists to be overwritten by default --- pythonforandroid/build.py | 2 +- pythonforandroid/distribution.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pythonforandroid/build.py b/pythonforandroid/build.py index 83966b7f91..9aa7212559 100644 --- a/pythonforandroid/build.py +++ b/pythonforandroid/build.py @@ -130,7 +130,7 @@ def android_api(self, value): def ndk_api(self): '''The API number compile against''' if self._ndk_api is None: - raise ValueError('Tried to access ndk_api_api but it has not ' + raise ValueError('Tried to access ndk_api but it has not ' 'been set - this should not happen, something ' 'went wrong!') return self._ndk_api diff --git a/pythonforandroid/distribution.py b/pythonforandroid/distribution.py index 11eedf0871..10644710d4 100644 --- a/pythonforandroid/distribution.py +++ b/pythonforandroid/distribution.py @@ -5,6 +5,7 @@ from pythonforandroid.logger import (info, info_notify, warning, Err_Style, Err_Fore, error) from pythonforandroid.util import current_directory +from shutil import rmtree class Distribution(object): @@ -46,7 +47,8 @@ def get_distribution(cls, ctx, name=None, recipes=[], ndk_api=None, force_build=False, extra_dist_dirs=[], - require_perfect_match=False): + require_perfect_match=False, + allow_replace_dist=True): '''Takes information about the distribution, and decides what kind of distribution it will be. @@ -70,6 +72,10 @@ def get_distribution(cls, ctx, name=None, recipes=[], require_perfect_match : bool If True, will only match distributions with precisely the correct set of recipes. + allow_replace_dist : bool + If True, will allow an existing dist with the specified + name but incompatible requirements to be overwritten by + a new one with the current requirements. ''' existing_dists = Distribution.get_distributions(ctx) @@ -123,7 +129,7 @@ def get_distribution(cls, ctx, name=None, recipes=[], # If there was a name match but we didn't already choose it, # then the existing dist is incompatible with the requested # configuration and the build cannot continue - if name_match_dist is not None: + if name_match_dist is not None and not allow_replace_dist: error('Asked for dist with name {name} with recipes ({req_recipes}) and ' 'NDK API {req_ndk_api}, but a dist ' 'with this name already exists and has either incompatible recipes ' @@ -154,6 +160,12 @@ def get_distribution(cls, ctx, name=None, recipes=[], return dist + def folder_exists(self): + return exists(self.dist_dir) + + def delete(self): + rmtree(self.dist_dir) + @classmethod def get_distributions(cls, ctx, extra_dist_dirs=[]): '''Returns all the distributions found locally.'''