Skip to content

Commit 54714ef

Browse files
authored
Merge pull request #1469 from inclement/allow_dist_overwrite
Allow dist overwrite by default
2 parents 5fc5241 + 1f2291e commit 54714ef

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

pythonforandroid/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def android_api(self, value):
130130
def ndk_api(self):
131131
'''The API number compile against'''
132132
if self._ndk_api is None:
133-
raise ValueError('Tried to access ndk_api_api but it has not '
133+
raise ValueError('Tried to access ndk_api but it has not '
134134
'been set - this should not happen, something '
135135
'went wrong!')
136136
return self._ndk_api

pythonforandroid/distribution.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pythonforandroid.logger import (info, info_notify, warning,
66
Err_Style, Err_Fore, error)
77
from pythonforandroid.util import current_directory
8+
from shutil import rmtree
89

910

1011
class Distribution(object):
@@ -46,7 +47,8 @@ def get_distribution(cls, ctx, name=None, recipes=[],
4647
ndk_api=None,
4748
force_build=False,
4849
extra_dist_dirs=[],
49-
require_perfect_match=False):
50+
require_perfect_match=False,
51+
allow_replace_dist=True):
5052
'''Takes information about the distribution, and decides what kind of
5153
distribution it will be.
5254
@@ -70,6 +72,10 @@ def get_distribution(cls, ctx, name=None, recipes=[],
7072
require_perfect_match : bool
7173
If True, will only match distributions with precisely the
7274
correct set of recipes.
75+
allow_replace_dist : bool
76+
If True, will allow an existing dist with the specified
77+
name but incompatible requirements to be overwritten by
78+
a new one with the current requirements.
7379
'''
7480

7581
existing_dists = Distribution.get_distributions(ctx)
@@ -123,7 +129,7 @@ def get_distribution(cls, ctx, name=None, recipes=[],
123129
# If there was a name match but we didn't already choose it,
124130
# then the existing dist is incompatible with the requested
125131
# configuration and the build cannot continue
126-
if name_match_dist is not None:
132+
if name_match_dist is not None and not allow_replace_dist:
127133
error('Asked for dist with name {name} with recipes ({req_recipes}) and '
128134
'NDK API {req_ndk_api}, but a dist '
129135
'with this name already exists and has either incompatible recipes '
@@ -154,6 +160,12 @@ def get_distribution(cls, ctx, name=None, recipes=[],
154160

155161
return dist
156162

163+
def folder_exists(self):
164+
return exists(self.dist_dir)
165+
166+
def delete(self):
167+
rmtree(self.dist_dir)
168+
157169
@classmethod
158170
def get_distributions(cls, ctx, extra_dist_dirs=[]):
159171
'''Returns all the distributions found locally.'''

pythonforandroid/toolchain.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def wrapper_func(self, args):
142142
user_ndk_api=self.ndk_api)
143143
dist = self._dist
144144
if dist.needs_build:
145+
if dist.folder_exists(): # possible if the dist is being replaced
146+
dist.delete()
145147
info_notify('No dist exists that meets your requirements, '
146148
'so one will be built.')
147149
build_dist_from_args(ctx, dist, args)
@@ -158,7 +160,8 @@ def dist_from_args(ctx, args):
158160
name=args.dist_name,
159161
ndk_api=args.ndk_api,
160162
recipes=split_argument_list(args.requirements),
161-
require_perfect_match=args.require_perfect_match)
163+
require_perfect_match=args.require_perfect_match,
164+
allow_replace_dist=args.allow_replace_dist)
162165

163166

164167
def build_dist_from_args(ctx, dist, args):
@@ -316,6 +319,12 @@ def __init__(self):
316319
description=('Whether the dist recipes must perfectly match '
317320
'those requested'))
318321

322+
add_boolean_option(
323+
generic_parser, ["allow-replace-dist"],
324+
default=True,
325+
description='Whether existing dist names can be automatically replaced'
326+
)
327+
319328
generic_parser.add_argument(
320329
'--local-recipes', '--local_recipes',
321330
dest='local_recipes', default='./p4a-recipes',
@@ -929,10 +938,11 @@ def distributions(self, _args):
929938

930939
def delete_dist(self, _args):
931940
dist = self._dist
932-
if dist.needs_build:
941+
if not dist.folder_exists():
933942
info('No dist exists that matches your specifications, '
934943
'exiting without deleting.')
935-
shutil.rmtree(dist.dist_dir)
944+
return
945+
dist.delete()
936946

937947
def sdk_tools(self, args):
938948
"""Runs the android binary from the detected SDK directory, passing

0 commit comments

Comments
 (0)