Changeset 3303


Ignore:
Timestamp:
Mar 2, 2018 2:11:37 PM (4 years ago)
Author:
toby
Message:

Py3 fixes for svn self-update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpath.py

    r3251 r3303  
    120120svnLocCache = None
    121121'Cached location of svn to avoid multiple searches for it'
     122
     123def 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               
    122146def getsvnProxy():
    123147    '''Loads a proxy for subversion from the file created by bootstrap.py
     
    202226    s = subprocess.Popen(cmd,
    203227                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    204     out,err = s.communicate()
     228    out,err = MakeByte2str(s.communicate())
    205229    if err:
    206230        print ('subversion error!\nout=%s'%out)
    207231        print ('err=%s'%err)
    208232        return None
    209     return out.strip().decode()
     233    return out.strip()
    210234
    211235def svnVersionNumber(svn=None):
     
    244268    s = subprocess.Popen(cmd,
    245269                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    246     out,err = s.communicate()
     270    out,err = MakeByte2str(s.communicate())
    247271    if err:
    248272        print ('out=%s'%out)
     
    286310    if proxycmds: cmd += proxycmds
    287311    s = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    288     out,err = s.communicate()
     312    out,err = MakeByte2str(s.communicate())
    289313    if err:
    290314        print ('svn failed\n%s'%out)
     
    316340    s = subprocess.Popen(cmd,
    317341                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    318     out,err = s.communicate()
     342    out,err = MakeByte2str(s.communicate())
    319343    if err: return None
    320344    x = ET.fromstring(out)
     
    353377        print(s)
    354378    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    355     out,err = s.communicate()
     379    out,err = MakeByte2str(s.communicate())
    356380    if err:
    357381        print(60*"=")
     
    375399    if proxycmds: cmd += proxycmds
    376400    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    377     out,err = s.communicate()
     401    out,err = MakeByte2str(s.communicate())
    378402    if err:
    379403        print("svn upgrade did not happen (this is probably OK). Messages:")
    380404        print (err)
    381            
     405
    382406def svnUpdateProcess(version=None,projectfile=None,branch=None):
    383407    '''perform an update of GSAS-II in a separate python process'''
     
    426450    if verbose: print(u"Loading files to "+fpath+u"\n  from "+URL)
    427451    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    428     out,err = s.communicate()
     452    out,err = MakeByte2str(s.communicate())
    429453    if err:
    430454        print(60*"=")
     
    454478    if proxycmds: cmd += proxycmds
    455479    s = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    456     out,err = s.communicate()   #this fails too easily
     480    out,err = MakeByte2str(s.communicate())   #this fails too easily
    457481    if err:
    458482        print(60*"=")
     
    500524        print(s)
    501525    p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    502     res,err = p.communicate()
     526    res,err = MakeByte2str(p.communicate())
    503527    return res
    504528
     
    523547        print(s)
    524548    p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    525     res,err = p.communicate()
     549    res,err = MakeByte2str(p.communicate())
    526550    versions = {}
    527     for d in res.decode().split():
     551    for d in res.split():
    528552        if d.startswith(bindir):
    529553            v = intver(d.rstrip('/').split('_')[3].lstrip('n'))
     
    570594#     if proxycmds: cmd += proxycmds
    571595#     p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    572 #     res,err = p.communicate()
     596#     res,err = MakeByte2str(p.communicate())
    573597#     for l in res.split('\n'):
    574598#         if "Relative URL:" in l: break
Note: See TracChangeset for help on using the changeset viewer.