source: trunk/makeBat.py @ 1858

Last change on this file since 1858 was 1858, checked in by toby, 7 years ago

add windows installer

  • Property svn:eol-style set to native
File size: 3.8 KB
RevLine 
[1858]1# creates Windows files to aid in running GSAS-II
2#   creates RunGSASII.bat and a desktop shortcut to that file
3#   registers the filetype .gpx so that the GSAS-II project files exhibit the
4#     GSAS-II icon and so that double-clicking on them opens them in GSAS-II
5import os, sys
6import datetime
7try:
8    import _winreg as winreg
9except ImportError:
10    import winreg
11
12Script = '''@echo ========================================================================
13@echo                General Structure Analysis System-II
14@echo              by Robert B. Von Dreele and Brian H. Toby
15@echo                Argonne National Laboratory(C), 2010
16@echo  This product includes software developed by the UChicago Argonne, LLC,
17@echo             as Operator of Argonne National Laboratory.
18@echo                            Please cite:
19@echo      B.H. Toby and R.B. Von Dreele, J. Appl. Cryst. 46, 544-549 (2013)
20@echo                   for small angle use also cite:
21@echo      R.B. Von Dreele, J. Appl. Cryst. 47, 1784-9 (2014)
22@echo ========================================================================
23@
24{:s} {:s} %1
25@REM To keep the window from disappearing with any error messages
26pause
27
28'''
29gsaspath = os.path.split(sys.argv[0])[0]
30if not gsaspath: gsaspath = os.path.curdir
31gsaspath = os.path.abspath(os.path.expanduser(gsaspath))
32G2script = os.path.join(gsaspath,'GSASII.py')
33G2bat = os.path.join(gsaspath,'RunGSASII.bat')
34G2icon = os.path.join(gsaspath,'gsas2.ico')
35pythonexe = os.path.realpath(sys.executable)
36# create a GSAS-II script
37fp = open(os.path.join(G2bat),'w')
38fp.write("@REM created by run of bootstrap.py on {:%d %b %Y %H:%M}\n".format(
39    datetime.datetime.now()))
40pexe = pythonexe
41if ' ' in pythonexe: pexe = '"'+pythonexe+'"'
42G2s = G2script
43if ' ' in G2s: G2script = '"'+G2script+'"'
44fp.write(Script.format(pexe,G2s))
45fp.close()
46print '\nCreated GSAS-II batch file RunGSASII.bat in '+gsaspath
47
48# Associate a script and icon with .gpx files
49#gpxkey = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, '.gpx')
50gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\.gpx')
51winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II.project')
52winreg.CloseKey(gpxkey)
53gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\GSAS-II.project')
54winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II project')
55iconkey = winreg.CreateKey(gpxkey, 'DefaultIcon')
56winreg.SetValue(iconkey, None, winreg.REG_SZ, G2icon)
57openkey = winreg.CreateKey(gpxkey, r'shell\open\command')
58winreg.SetValue(openkey, None, winreg.REG_SZ, G2bat+" %1")
59winreg.CloseKey(iconkey)
60winreg.CloseKey(openkey)
61winreg.CloseKey(gpxkey)
62print 'Assigned icon and batch file to .gpx files'
63
64try:
65    import win32com.shell.shell, win32com.shell.shellcon
66    win32com.shell.shell.SHChangeNotify(
67        win32com.shell.shellcon.SHCNE_ASSOCCHANGED, 0, None, None)
68except ImportError:
69    print 'Module pywin32 not present, login again to see file types properly'
70except:
71    print 'Unexpected error on explorer refresh. Please report:'
72    import traceback
73    print traceback.format_exc()
74
75# make a desktop shortcut to GSAS-II
76try:
77    import win32com.shell.shell, win32com.shell.shellcon, win32com.client
78    desktop = win32com.shell.shell.SHGetFolderPath(
79        0, win32com.shell.shellcon.CSIDL_DESKTOP, None, 0)
80    shortcut = os.path.join(desktop, "GSAS-II.lnk")
81    shell = win32com.client.Dispatch('WScript.Shell')
82    shobj = shell.CreateShortCut(shortcut)
83    shobj.Targetpath = G2bat
84    #shobj.WorkingDirectory = wDir # could specify a default project location here
85    shobj.IconLocation = G2icon
86    shobj.save()
87    print 'Created shortcut to start GSAS-II on desktop'
88except ImportError:
89    print 'Module pywin32 not present, will not make desktop shortcut'
90except:
91    print 'Unexpected error making desktop shortcut. Please report:'
92    import traceback
93    print traceback.format_exc()
94   
Note: See TracBrowser for help on using the repository browser.