1
1
#!/usr/bin/env python
2
2
# -*- coding: utf-8 -*-
3
-
3
+ #
4
4
# The MIT License (MIT)
5
5
# Copyright © 2016, Jace Browning
6
6
#
@@ -47,11 +47,14 @@ else:
47
47
import configparser
48
48
from urllib .request import urlretrieve
49
49
50
- __version__ = '3.1.1 '
50
+ __version__ = '3.4 '
51
51
52
52
SCRIPT_URL = (
53
53
"https://raw.githubusercontent.com/jacebrowning/verchew/main/verchew/script.py"
54
54
)
55
+ WRAPPER_URL = (
56
+ "https://raw.githubusercontent.com/jacebrowning/verchew/main/verchew/wrapper.sh"
57
+ )
55
58
56
59
CONFIG_FILENAMES = ['verchew.ini' , '.verchew.ini' , '.verchewrc' , '.verchew' ]
57
60
@@ -112,7 +115,8 @@ def main():
112
115
log .debug ("PATH: %s" , os .getenv ('PATH' ))
113
116
114
117
if args .vendor :
115
- vendor_script (args .vendor )
118
+ vendor_script (SCRIPT_URL , args .vendor )
119
+ vendor_script (WRAPPER_URL , args .vendor + "-wrapper" )
116
120
sys .exit (0 )
117
121
118
122
path = find_config (args .root , generate = args .init )
@@ -171,14 +175,14 @@ def configure_logging(count=0):
171
175
logging .basicConfig (level = level , format = "%(levelname)s: %(message)s" )
172
176
173
177
174
- def vendor_script (path ):
178
+ def vendor_script (url , path ):
175
179
root = os .path .abspath (os .path .join (path , os .pardir ))
176
180
if not os .path .isdir (root ):
177
181
log .info ("Creating directory %s" , root )
178
182
os .makedirs (root )
179
183
180
- log .info ("Downloading %s to %s" , SCRIPT_URL , path )
181
- urlretrieve (SCRIPT_URL , path )
184
+ log .info ("Downloading %s to %s" , url , path )
185
+ urlretrieve (url , path )
182
186
183
187
log .debug ("Making %s executable" , path )
184
188
mode = os .stat (path ).st_mode
@@ -236,6 +240,10 @@ def parse_config(path):
236
240
data [name ]['version' ] = version
237
241
data [name ]['patterns' ] = [v .strip () for v in version .split ('||' )]
238
242
243
+ data [name ]['optional' ] = data [name ].get (
244
+ 'optional' , 'false'
245
+ ).strip ().lower () in ('true' , 'yes' , 'y' , True )
246
+
239
247
return data
240
248
241
249
@@ -260,7 +268,7 @@ def check_dependencies(config):
260
268
if "not found" in output :
261
269
actual = "Not found"
262
270
else :
263
- actual = output .split ('\n ' )[0 ].strip ('.' )
271
+ actual = output .split ('\n ' , maxsplit = 1 )[0 ].strip ('.' )
264
272
expected = settings ['version' ] or "<anything>"
265
273
print ("{0}: {1}, EXPECTED: {2}" .format (name , actual , expected ))
266
274
show (
@@ -280,30 +288,44 @@ def get_version(program, argument=None):
280
288
if argument is None :
281
289
args = [program , '--version' ]
282
290
elif argument :
283
- args = [program , argument ]
291
+ args = [program ] + argument . split ()
284
292
else :
285
293
args = [program ]
286
294
287
295
show ("$ {0}" .format (" " .join (args )))
288
296
output = call (args )
289
297
lines = output .splitlines ()
290
- show (lines [0 ] if lines else "<nothing>" )
298
+
299
+ if lines :
300
+ for line in lines :
301
+ if any (char .isdigit () for char in line ):
302
+ show (line )
303
+ break
304
+ else :
305
+ show (lines [0 ])
306
+ else :
307
+ show ("<nothing>" )
291
308
292
309
return output
293
310
294
311
295
312
def match_version (pattern , output ):
296
- if "not found" in output .split ('\n ' )[0 ]:
313
+ lines = output .splitlines ()
314
+ if "not found" in lines [0 ]:
297
315
return False
298
316
299
317
regex = pattern .replace ('.' , r'\.' ) + r'(\b|/)'
300
318
301
- log .debug ("Matching %s: %s" , regex , output )
302
- match = re .match (regex , output )
303
- if match is None :
304
- match = re .match (r'.*[^\d.]' + regex , output )
319
+ for line in lines :
320
+ log .debug ("Matching %s: %s" , regex , line )
321
+ match = re .match (regex , line )
322
+ if match is None :
323
+ log .debug ("Matching %s: %s" , regex , line )
324
+ match = re .match (r'.*[^\d.]' + regex , line )
325
+ if match :
326
+ return True
305
327
306
- return bool ( match )
328
+ return False
307
329
308
330
309
331
def call (args ):
0 commit comments