Changeset 2802 for trunk/makeBat.py
- Timestamp:
- Apr 23, 2017 9:30:38 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/makeBat.py
r2187 r2802 1 ''' 2 *makeBat: Create GSAS-II Batch File* 3 ==================================== 4 5 This script creates a filen named ``RunGSASII.bat`` and a desktop shortcut to that file. 6 It registers the filetype .gpx so that the GSAS-II project files exhibit the 7 GSAS-II icon and so that double-clicking on them opens them in GSAS-II. 8 9 Run this script with no arguments; the path to the ``GSASII.py`` file 10 is assumed to be the the same as the path to the ``makeBat.py`` file 11 and the path to Python is determined from the version of Python 12 used to run this script. 13 14 ''' 1 15 # creates Windows files to aid in running GSAS-II 2 16 # creates RunGSASII.bat and a desktop shortcut to that file … … 30 44 31 45 ''' 32 gsaspath = os.path.split(sys.argv[0])[0]33 if not gsaspath: gsaspath = os.path.curdir34 gsaspath = os.path.abspath(os.path.expanduser(gsaspath))35 G2script = os.path.join(gsaspath,'GSASII.py')36 G2bat = os.path.join(gsaspath,'RunGSASII.bat')37 G2icon = os.path.join(gsaspath,'gsas2.ico')38 pythonexe = os.path.realpath(sys.executable)39 # Bob reports a problem using pythonw.exe w/Canopy on Windows, so change that if used40 if pythonexe.lower().endswith('pythonw.exe'):41 print " using python.exe rather than "+pythonexe42 pythonexe = os.path.join(os.path.split(pythonexe)[0],'python.exe')43 print " now pythonexe="+pythonexe44 # create a GSAS-II script45 fp = open(os.path.join(G2bat),'w')46 fp.write("@REM created by run of bootstrap.py on {:%d %b %Y %H:%M}\n".format(47 datetime.datetime.now()))48 pexe = pythonexe49 if ' ' in pythonexe: pexe = '"'+pythonexe+'"'50 G2s = G2script51 if ' ' in G2s: G2s = '"'+G2script+'"'52 fp.write(Script.format(pexe,G2s))53 fp.close()54 print '\nCreated GSAS-II batch file RunGSASII.bat in '+gsaspath55 46 56 # Associate a script and icon with .gpx files 57 #gpxkey = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, '.gpx') 58 gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\.gpx') 59 winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II.project') 60 winreg.CloseKey(gpxkey) 61 gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\GSAS-II.project') 62 winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II project') 63 iconkey = winreg.CreateKey(gpxkey, 'DefaultIcon') 64 winreg.SetValue(iconkey, None, winreg.REG_SZ, G2icon) 65 openkey = winreg.CreateKey(gpxkey, r'shell\open\command') 66 winreg.SetValue(openkey, None, winreg.REG_SZ, G2bat+' "%1"') 67 winreg.CloseKey(iconkey) 68 winreg.CloseKey(openkey) 69 winreg.CloseKey(gpxkey) 70 print 'Assigned icon and batch file to .gpx files' 47 if __name__ == '__main__': 48 gsaspath = os.path.split(sys.argv[0])[0] 49 if not gsaspath: gsaspath = os.path.curdir 50 gsaspath = os.path.abspath(os.path.expanduser(gsaspath)) 51 G2script = os.path.join(gsaspath,'GSASII.py') 52 G2bat = os.path.join(gsaspath,'RunGSASII.bat') 53 G2icon = os.path.join(gsaspath,'gsas2.ico') 54 pythonexe = os.path.realpath(sys.executable) 55 # Bob reports a problem using pythonw.exe w/Canopy on Windows, so change that if used 56 if pythonexe.lower().endswith('pythonw.exe'): 57 print " using python.exe rather than "+pythonexe 58 pythonexe = os.path.join(os.path.split(pythonexe)[0],'python.exe') 59 print " now pythonexe="+pythonexe 60 # create a GSAS-II script 61 fp = open(os.path.join(G2bat),'w') 62 fp.write("@REM created by run of bootstrap.py on {:%d %b %Y %H:%M}\n".format( 63 datetime.datetime.now())) 64 pexe = pythonexe 65 if ' ' in pythonexe: pexe = '"'+pythonexe+'"' 66 G2s = G2script 67 if ' ' in G2s: G2s = '"'+G2script+'"' 68 fp.write(Script.format(pexe,G2s)) 69 fp.close() 70 print '\nCreated GSAS-II batch file RunGSASII.bat in '+gsaspath 71 71 72 try: 73 import win32com.shell.shell, win32com.shell.shellcon 74 win32com.shell.shell.SHChangeNotify( 75 win32com.shell.shellcon.SHCNE_ASSOCCHANGED, 0, None, None) 76 except ImportError: 77 print 'Module pywin32 not present, login again to see file types properly' 78 except: 79 print 'Unexpected error on explorer refresh. Please report:' 80 import traceback 81 print traceback.format_exc() 72 # Associate a script and icon with .gpx files 73 #gpxkey = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, '.gpx') 74 gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\.gpx') 75 winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II.project') 76 winreg.CloseKey(gpxkey) 77 gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\GSAS-II.project') 78 winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II project') 79 iconkey = winreg.CreateKey(gpxkey, 'DefaultIcon') 80 winreg.SetValue(iconkey, None, winreg.REG_SZ, G2icon) 81 openkey = winreg.CreateKey(gpxkey, r'shell\open\command') 82 winreg.SetValue(openkey, None, winreg.REG_SZ, G2bat+' "%1"') 83 winreg.CloseKey(iconkey) 84 winreg.CloseKey(openkey) 85 winreg.CloseKey(gpxkey) 86 print 'Assigned icon and batch file to .gpx files' 82 87 83 # make a desktop shortcut to GSAS-II 84 try: 85 import win32com.shell.shell, win32com.shell.shellcon, win32com.client 86 desktop = win32com.shell.shell.SHGetFolderPath( 87 0, win32com.shell.shellcon.CSIDL_DESKTOP, None, 0) 88 shortcut = os.path.join(desktop, "GSAS-II.lnk") 89 shell = win32com.client.Dispatch('WScript.Shell') 90 shobj = shell.CreateShortCut(shortcut) 91 shobj.Targetpath = G2bat 92 #shobj.WorkingDirectory = wDir # could specify a default project location here 93 shobj.IconLocation = G2icon 94 shobj.save() 95 print 'Created shortcut to start GSAS-II on desktop' 96 except ImportError: 97 print 'Module pywin32 not present, will not make desktop shortcut' 98 except: 99 print 'Unexpected error making desktop shortcut. Please report:' 100 import traceback 101 print traceback.format_exc() 88 try: 89 import win32com.shell.shell, win32com.shell.shellcon 90 win32com.shell.shell.SHChangeNotify( 91 win32com.shell.shellcon.SHCNE_ASSOCCHANGED, 0, None, None) 92 except ImportError: 93 print 'Module pywin32 not present, login again to see file types properly' 94 except: 95 print 'Unexpected error on explorer refresh. Please report:' 96 import traceback 97 print traceback.format_exc() 98 99 # make a desktop shortcut to GSAS-II 100 try: 101 import win32com.shell.shell, win32com.shell.shellcon, win32com.client 102 desktop = win32com.shell.shell.SHGetFolderPath( 103 0, win32com.shell.shellcon.CSIDL_DESKTOP, None, 0) 104 shortcut = os.path.join(desktop, "GSAS-II.lnk") 105 shell = win32com.client.Dispatch('WScript.Shell') 106 shobj = shell.CreateShortCut(shortcut) 107 shobj.Targetpath = G2bat 108 #shobj.WorkingDirectory = wDir # could specify a default project location here 109 shobj.IconLocation = G2icon 110 shobj.save() 111 print 'Created shortcut to start GSAS-II on desktop' 112 except ImportError: 113 print 'Module pywin32 not present, will not make desktop shortcut' 114 except: 115 print 'Unexpected error making desktop shortcut. Please report:' 116 import traceback 117 print traceback.format_exc() 102 118
Note: See TracChangeset
for help on using the changeset viewer.