source: trunk/makeBat.py @ 2133

Last change on this file since 2133 was 2133, checked in by toby, 6 years ago

fix svn settings for revisions & line ends

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 4.1 KB
Line 
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# Bob reports a problem using pythonw.exe w/Canopy on Windows, so change that if used
37if pythonexe.lower().endswith('pythonw.exe'):
38    print "  using python.exe rather than "+pythonexe
39    pythonexe = os.path.join(os.path.split(pythonexe)[0],'python.exe')
40    print "  now pythonexe="+pythonexe
41# create a GSAS-II script
42fp = open(os.path.join(G2bat),'w')
43fp.write("@REM created by run of bootstrap.py on {:%d %b %Y %H:%M}\n".format(
44    datetime.datetime.now()))
45pexe = pythonexe
46if ' ' in pythonexe: pexe = '"'+pythonexe+'"'
47G2s = G2script
48if ' ' in G2s: G2s = '"'+G2script+'"'
49fp.write(Script.format(pexe,G2s))
50fp.close()
51print '\nCreated GSAS-II batch file RunGSASII.bat in '+gsaspath
52
53# Associate a script and icon with .gpx files
54#gpxkey = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, '.gpx')
55gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\.gpx')
56winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II.project')
57winreg.CloseKey(gpxkey)
58gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\GSAS-II.project')
59winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II project')
60iconkey = winreg.CreateKey(gpxkey, 'DefaultIcon')
61winreg.SetValue(iconkey, None, winreg.REG_SZ, G2icon)
62openkey = winreg.CreateKey(gpxkey, r'shell\open\command')
63winreg.SetValue(openkey, None, winreg.REG_SZ, G2bat+' "%1"')
64winreg.CloseKey(iconkey)
65winreg.CloseKey(openkey)
66winreg.CloseKey(gpxkey)
67print 'Assigned icon and batch file to .gpx files'
68
69try:
70    import win32com.shell.shell, win32com.shell.shellcon
71    win32com.shell.shell.SHChangeNotify(
72        win32com.shell.shellcon.SHCNE_ASSOCCHANGED, 0, None, None)
73except ImportError:
74    print 'Module pywin32 not present, login again to see file types properly'
75except:
76    print 'Unexpected error on explorer refresh. Please report:'
77    import traceback
78    print traceback.format_exc()
79
80# make a desktop shortcut to GSAS-II
81try:
82    import win32com.shell.shell, win32com.shell.shellcon, win32com.client
83    desktop = win32com.shell.shell.SHGetFolderPath(
84        0, win32com.shell.shellcon.CSIDL_DESKTOP, None, 0)
85    shortcut = os.path.join(desktop, "GSAS-II.lnk")
86    shell = win32com.client.Dispatch('WScript.Shell')
87    shobj = shell.CreateShortCut(shortcut)
88    shobj.Targetpath = G2bat
89    #shobj.WorkingDirectory = wDir # could specify a default project location here
90    shobj.IconLocation = G2icon
91    shobj.save()
92    print 'Created shortcut to start GSAS-II on desktop'
93except ImportError:
94    print 'Module pywin32 not present, will not make desktop shortcut'
95except:
96    print 'Unexpected error making desktop shortcut. Please report:'
97    import traceback
98    print traceback.format_exc()
99   
Note: See TracBrowser for help on using the repository browser.