Changeset 3303
- Timestamp:
- Mar 2, 2018 2:11:37 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIpath.py
r3251 r3303 120 120 svnLocCache = None 121 121 'Cached location of svn to avoid multiple searches for it' 122 123 def MakeByte2str(arg): 124 '''Convert output from subprocess pipes (bytes) to str (unicode) in Python 3. 125 In Python 2: Leaves output alone (already str). 126 Leaves stuff of other types alone (including unicode in Py2) 127 Works recursively for string-like stuff in nested loops and tuples. 128 129 typical use:: 130 131 out = MakeByte2str(out) 132 133 or:: 134 135 out,err = MakeByte2str(s.communicate()) 136 137 ''' 138 if isinstance(arg,str): return arg 139 if isinstance(arg,bytes): return arg.decode() 140 if isinstance(arg,list): 141 return [MakeByte2str(i) for i in arg] 142 if isinstance(arg,tuple): 143 return tuple([MakeByte2str(i) for i in arg]) 144 return arg 145 122 146 def getsvnProxy(): 123 147 '''Loads a proxy for subversion from the file created by bootstrap.py … … 202 226 s = subprocess.Popen(cmd, 203 227 stdout=subprocess.PIPE,stderr=subprocess.PIPE) 204 out,err = s.communicate()228 out,err = MakeByte2str(s.communicate()) 205 229 if err: 206 230 print ('subversion error!\nout=%s'%out) 207 231 print ('err=%s'%err) 208 232 return None 209 return out.strip() .decode()233 return out.strip() 210 234 211 235 def svnVersionNumber(svn=None): … … 244 268 s = subprocess.Popen(cmd, 245 269 stdout=subprocess.PIPE,stderr=subprocess.PIPE) 246 out,err = s.communicate()270 out,err = MakeByte2str(s.communicate()) 247 271 if err: 248 272 print ('out=%s'%out) … … 286 310 if proxycmds: cmd += proxycmds 287 311 s = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE) 288 out,err = s.communicate()312 out,err = MakeByte2str(s.communicate()) 289 313 if err: 290 314 print ('svn failed\n%s'%out) … … 316 340 s = subprocess.Popen(cmd, 317 341 stdout=subprocess.PIPE,stderr=subprocess.PIPE) 318 out,err = s.communicate()342 out,err = MakeByte2str(s.communicate()) 319 343 if err: return None 320 344 x = ET.fromstring(out) … … 353 377 print(s) 354 378 s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 355 out,err = s.communicate()379 out,err = MakeByte2str(s.communicate()) 356 380 if err: 357 381 print(60*"=") … … 375 399 if proxycmds: cmd += proxycmds 376 400 s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 377 out,err = s.communicate()401 out,err = MakeByte2str(s.communicate()) 378 402 if err: 379 403 print("svn upgrade did not happen (this is probably OK). Messages:") 380 404 print (err) 381 405 382 406 def svnUpdateProcess(version=None,projectfile=None,branch=None): 383 407 '''perform an update of GSAS-II in a separate python process''' … … 426 450 if verbose: print(u"Loading files to "+fpath+u"\n from "+URL) 427 451 s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 428 out,err = s.communicate()452 out,err = MakeByte2str(s.communicate()) 429 453 if err: 430 454 print(60*"=") … … 454 478 if proxycmds: cmd += proxycmds 455 479 s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 456 out,err = s.communicate() #this fails too easily480 out,err = MakeByte2str(s.communicate()) #this fails too easily 457 481 if err: 458 482 print(60*"=") … … 500 524 print(s) 501 525 p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 502 res,err = p.communicate()526 res,err = MakeByte2str(p.communicate()) 503 527 return res 504 528 … … 523 547 print(s) 524 548 p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 525 res,err = p.communicate()549 res,err = MakeByte2str(p.communicate()) 526 550 versions = {} 527 for d in res. decode().split():551 for d in res.split(): 528 552 if d.startswith(bindir): 529 553 v = intver(d.rstrip('/').split('_')[3].lstrip('n')) … … 570 594 # if proxycmds: cmd += proxycmds 571 595 # p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 572 # res,err = p.communicate()596 # res,err = MakeByte2str(p.communicate()) 573 597 # for l in res.split('\n'): 574 598 # if "Relative URL:" in l: break
Note: See TracChangeset
for help on using the changeset viewer.