5
5
from pythonforandroid .logger import (info , info_notify , warning ,
6
6
Err_Style , Err_Fore , error )
7
7
from pythonforandroid .util import current_directory
8
+ from os .path import exists
9
+ from shutil import rmtree
8
10
9
11
10
12
class Distribution (object ):
@@ -46,7 +48,8 @@ def get_distribution(cls, ctx, name=None, recipes=[],
46
48
ndk_api = None ,
47
49
force_build = False ,
48
50
extra_dist_dirs = [],
49
- require_perfect_match = False ):
51
+ require_perfect_match = False ,
52
+ allow_replace_dist = True ):
50
53
'''Takes information about the distribution, and decides what kind of
51
54
distribution it will be.
52
55
@@ -70,6 +73,10 @@ def get_distribution(cls, ctx, name=None, recipes=[],
70
73
require_perfect_match : bool
71
74
If True, will only match distributions with precisely the
72
75
correct set of recipes.
76
+ allow_replace_dist : bool
77
+ If True, will allow an existing dist with the specified
78
+ name but incompatible requirements to be overwritten by
79
+ a new one with the current requirements.
73
80
'''
74
81
75
82
existing_dists = Distribution .get_distributions (ctx )
@@ -123,7 +130,7 @@ def get_distribution(cls, ctx, name=None, recipes=[],
123
130
# If there was a name match but we didn't already choose it,
124
131
# then the existing dist is incompatible with the requested
125
132
# configuration and the build cannot continue
126
- if name_match_dist is not None :
133
+ if name_match_dist is not None and not allow_replace_dist :
127
134
error ('Asked for dist with name {name} with recipes ({req_recipes}) and '
128
135
'NDK API {req_ndk_api}, but a dist '
129
136
'with this name already exists and has either incompatible recipes '
@@ -154,6 +161,12 @@ def get_distribution(cls, ctx, name=None, recipes=[],
154
161
155
162
return dist
156
163
164
+ def folder_exists (self ):
165
+ return exists (self .dist_dir )
166
+
167
+ def delete (self ):
168
+ rmtree (self .dist_dir )
169
+
157
170
@classmethod
158
171
def get_distributions (cls , ctx , extra_dist_dirs = []):
159
172
'''Returns all the distributions found locally.'''
0 commit comments