source: install/setversion.py @ 4201

Last change on this file since 4201 was 3912, checked in by toby, 4 years ago

updates for packaging

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.4 KB
Line 
1import subprocess
2
3def MakeByte2str(arg):
4    '''Convert output from subprocess pipes (bytes) to str (unicode) in Python 3.
5    In Python 2: Leaves output alone (already str).
6    Leaves stuff of other types alone (including unicode in Py2)
7    Works recursively for string-like stuff in nested loops and tuples.
8
9    typical use::
10        out = MakeByte2str(out)
11    or::
12        out,err = MakeByte2str(s.communicate())
13   
14    '''
15    if isinstance(arg,str): return arg
16    if isinstance(arg,bytes): return arg.decode()
17    if isinstance(arg,list):
18        return [MakeByte2str(i) for i in arg]
19    if isinstance(arg,tuple):
20        return tuple([MakeByte2str(i) for i in arg])
21    return arg
22svn = 'svn' # assume in path
23cmd = [svn,'info','https://subversion.xray.aps.anl.gov/pyGSAS/trunk']
24s = subprocess.Popen(cmd,
25                    stdout=subprocess.PIPE,stderr=subprocess.PIPE)
26out,err = MakeByte2str(s.communicate())
27if err:
28    print ('subversion error!\nout=%s'%out)
29    print ('err=%s'%err)
30    sys.exit(1)
31for line in out.split('\n'):
32    if line.startswith('Rev'):
33        version = line.split()[1].strip()
34        break
35else:
36    print ('Version not found!\nout=%s'%out)
37    sys.exit(1)
38for fil in 'g2complete/meta.yaml','g2full/construct.yaml':
39    fp = open(fil+'.template','r')
40    out = fp.read().replace('**Version**',version)
41    fp.close()
42    print('Creating',fil)
43    fp = open(fil,'w')
44    fp.write(out)
45    fp.close()
46   
Note: See TracBrowser for help on using the repository browser.