source: install/setversion.py @ 4748

Last change on this file since 4748 was 4713, checked in by toby, 10 months ago

more installer work; xmgrace enhance from Carlo

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.9 KB
Line 
1import sys
2import platform
3import subprocess
4
5def MakeByte2str(arg):
6    '''Convert output from subprocess pipes (bytes) to str (unicode) in Python 3.
7    In Python 2: Leaves output alone (already str).
8    Leaves stuff of other types alone (including unicode in Py2)
9    Works recursively for string-like stuff in nested loops and tuples.
10
11    typical use::
12        out = MakeByte2str(out)
13    or::
14        out,err = MakeByte2str(s.communicate())
15   
16    '''
17    if isinstance(arg,str): return arg
18    if isinstance(arg,bytes): return arg.decode()
19    if isinstance(arg,list):
20        return [MakeByte2str(i) for i in arg]
21    if isinstance(arg,tuple):
22        return tuple([MakeByte2str(i) for i in arg])
23    return arg
24svn = 'svn' # assume in path
25cmd = [svn,'info','https://subversion.xray.aps.anl.gov/pyGSAS/trunk']
26s = subprocess.Popen(cmd,
27                    stdout=subprocess.PIPE,stderr=subprocess.PIPE)
28out,err = MakeByte2str(s.communicate())
29if err:
30    print ('subversion error!\nout=%s'%out)
31    print ('err=%s'%err)
32    sys.exit(1)
33for line in out.split('\n'):
34    if line.startswith('Rev'):
35        version = line.split()[1].strip()
36        print ('Version is {}'.format(out))
37        break
38else:
39    print ('Version not found!\nout=%s'%out)
40    sys.exit(1)
41
42import numpy as np
43import wx
44import matplotlib as mpl
45import platform
46npversion = np.__version__[:np.__version__.find('.',2)]
47#wxversion = wx.__version__[:wx.__version__.find('.',2)]
48wxversion = wx.__version__
49mplversion = mpl.__version__[:mpl.__version__.find('.',2)]
50pyversion = platform.python_version()
51if pyversion.find('.',2) > 0: pyversion = pyversion[:pyversion.find('.',2)]
52print ('SVN version is    {}'.format(version))
53print ('python version is {}'.format(pyversion))
54print ('numpy version is  {}'.format(npversion))
55print ('wx version is     {}'.format(wxversion))
56print ('MPL version is    {}'.format(mplversion))
57
58for fil in ('g2complete/meta.yaml','g2complete/build.sh',
59                'g2complete/bld.bat',
60                'g2full/construct.yaml',
61                ):
62    try:
63        fp = open(fil+'.template','r')
64        out = fp.read().replace('**Version**',version)
65        fp.close()
66    except FileNotFoundError:
67        print('Skipping ',fil)
68        continue
69    if sys.platform == "win32" and platform.architecture()[0] != '64bit':
70        if 'win-64' in out:
71            print('changing for 32-bit windows')
72            out = out.replace('win-64','win-32')
73    if sys.platform.startswith("linux") and platform.architecture()[0] != '64bit':
74        if 'linux-64' in out:
75            print('changing for 32-bit linux')
76            out = out.replace('linux-64','linux-32')
77    out = out.replace('**pyversion**',pyversion)
78    out = out.replace('**npversion**',npversion)
79    out = out.replace('**wxversion**',wxversion)
80    out = out.replace('**mplversion**',mplversion)
81    print('Creating',fil)
82    fp = open(fil,'w')
83    fp.write(out)
84    fp.close()
85   
Note: See TracBrowser for help on using the repository browser.