[4239] | 1 | import sys |
---|
| 2 | import platform |
---|
[3910] | 3 | import subprocess |
---|
| 4 | |
---|
| 5 | def 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 |
---|
| 24 | svn = 'svn' # assume in path |
---|
| 25 | cmd = [svn,'info','https://subversion.xray.aps.anl.gov/pyGSAS/trunk'] |
---|
| 26 | s = subprocess.Popen(cmd, |
---|
| 27 | stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
| 28 | out,err = MakeByte2str(s.communicate()) |
---|
| 29 | if err: |
---|
| 30 | print ('subversion error!\nout=%s'%out) |
---|
| 31 | print ('err=%s'%err) |
---|
| 32 | sys.exit(1) |
---|
| 33 | for line in out.split('\n'): |
---|
| 34 | if line.startswith('Rev'): |
---|
| 35 | version = line.split()[1].strip() |
---|
| 36 | break |
---|
| 37 | else: |
---|
| 38 | print ('Version not found!\nout=%s'%out) |
---|
| 39 | sys.exit(1) |
---|
[4710] | 40 | |
---|
| 41 | import numpy as np |
---|
| 42 | import wx |
---|
| 43 | import matplotlib as mpl |
---|
| 44 | import platform |
---|
| 45 | npversion = np.__version__[:np.__version__.find('.',2)] |
---|
| 46 | #wxversion = wx.__version__[:wx.__version__.find('.',2)] |
---|
| 47 | wxversion = wx.__version__ |
---|
| 48 | mplversion = mpl.__version__[:mpl.__version__.find('.',2)] |
---|
| 49 | pyversion = platform.python_version() |
---|
| 50 | if pyversion.find('.',2) > 0: pyversion = pyversion[:pyversion.find('.',2)] |
---|
| 51 | print ('SVN version is {}'.format(version)) |
---|
| 52 | print ('python version is {}'.format(pyversion)) |
---|
| 53 | print ('numpy version is {}'.format(npversion)) |
---|
| 54 | print ('wx version is {}'.format(wxversion)) |
---|
| 55 | print ('MPL version is {}'.format(mplversion)) |
---|
| 56 | |
---|
| 57 | for fil in ('g2complete/meta.yaml','g2complete/build.sh', |
---|
| 58 | 'g2complete/bld.bat', |
---|
| 59 | 'g2full/construct.yaml', |
---|
[4749] | 60 | 'g2full/g2postinstall.bat', |
---|
| 61 | 'g2full/g2postinstall.sh', |
---|
[4710] | 62 | ): |
---|
| 63 | try: |
---|
| 64 | fp = open(fil+'.template','r') |
---|
| 65 | out = fp.read().replace('**Version**',version) |
---|
| 66 | fp.close() |
---|
| 67 | except FileNotFoundError: |
---|
| 68 | print('Skipping ',fil) |
---|
| 69 | continue |
---|
[4239] | 70 | if sys.platform == "win32" and platform.architecture()[0] != '64bit': |
---|
[4713] | 71 | if 'win-64' in out: |
---|
| 72 | print('changing for 32-bit windows') |
---|
| 73 | out = out.replace('win-64','win-32') |
---|
| 74 | if sys.platform.startswith("linux") and platform.architecture()[0] != '64bit': |
---|
| 75 | if 'linux-64' in out: |
---|
| 76 | print('changing for 32-bit linux') |
---|
| 77 | out = out.replace('linux-64','linux-32') |
---|
[4710] | 78 | out = out.replace('**pyversion**',pyversion) |
---|
| 79 | out = out.replace('**npversion**',npversion) |
---|
| 80 | out = out.replace('**wxversion**',wxversion) |
---|
| 81 | out = out.replace('**mplversion**',mplversion) |
---|
[4759] | 82 | if sys.platform == "darwin": out.replace('#MACOnly#','') |
---|
[3912] | 83 | print('Creating',fil) |
---|
[3910] | 84 | fp = open(fil,'w') |
---|
| 85 | fp.write(out) |
---|
| 86 | fp.close() |
---|
| 87 | |
---|