36
36
intver = lambda vs : sum ([int (i ) for i in vs .split ('.' )[0 :2 ]]* np .array ((1000 ,1 )))
37
37
38
38
def GetConfigValue (key ,default = None ,getDefault = False ):
39
- '''Return the configuration file value for key or a default value
39
+ '''Return the configuration file value for key or a default value
40
40
if not specified.
41
-
41
+
42
42
:param str key: a value to be found in the configuration settings
43
- :param any default: a value to be supplied if a value for key is
44
- not specified in the config file or the config file is not found.
43
+ :param any default: a value to be supplied if a value for key is
44
+ not specified in the config file or the config file is not found.
45
45
Defaults to None.
46
- :param bool getDefault: If True looks up the default value from the
47
- config_example.py file (default value is False). Do not specify a
48
- getDefault=True if a value is provided for default.
46
+ :param bool getDefault: If True looks up the default value from the
47
+ config_example.py file (default value is False). Do not specify a
48
+ getDefault=True if a value is provided for default.
49
49
:returns: the value found or the default.
50
50
'''
51
51
if getDefault :
@@ -58,11 +58,11 @@ def GetConfigValue(key,default=None,getDefault=False):
58
58
return None
59
59
60
60
def SetConfigValue (parmdict ):
61
- '''Set configuration variables. Note that parmdict is a dictionary
62
- from :func:`GSASIIctrlGUI.GetConfigValsDocs` where each element is a
63
- lists. The first item in list is the default value, the second is
64
- the value to use for that configuration variable. Most of the
65
- information gathered in GetConfigValsDocs is no longer used.
61
+ '''Set configuration variables. Note that parmdict is a dictionary
62
+ from :func:`GSASIIctrlGUI.GetConfigValsDocs` where each element is a
63
+ lists. The first item in list is the default value, the second is
64
+ the value to use for that configuration variable. Most of the
65
+ information gathered in GetConfigValsDocs is no longer used.
66
66
'''
67
67
global configDict
68
68
for var in parmdict :
@@ -924,7 +924,7 @@ def runScript(cmds=[], wait=False, G2frame=None):
924
924
projectfile = ''
925
925
if G2frame .GSASprojectfile :
926
926
projectfile = os .path .realpath (G2frame .GSASprojectfile )
927
- main = os .path .join (path2GSAS2 ,'GSASII .py' )
927
+ main = os .path .join (path2GSAS2 ,'G2 .py' )
928
928
ex = sys .executable
929
929
if sys .platform == "darwin" : # mac requires pythonw which is not always reported as sys.executable
930
930
if os .path .exists (ex + 'w' ): ex += 'w'
@@ -946,7 +946,7 @@ def runScript(cmds=[], wait=False, G2frame=None):
946
946
947
947
def IPyBreak_base (userMsg = None ):
948
948
'''A routine that invokes an IPython session at the calling location
949
- This routine is only used when debug=True is set in the configuration
949
+ This routine is only used when debug=True is set in the configuration
950
950
settings
951
951
'''
952
952
savehook = sys .excepthook # save the exception hook
@@ -979,7 +979,7 @@ def exceptHook(*args):
979
979
'''A routine to be called when an exception occurs. It prints the traceback
980
980
with fancy formatting and then calls an IPython shell with the environment
981
981
of the exception location.
982
-
982
+
983
983
This routine is only used when debug=True is set in the configuration settings
984
984
'''
985
985
try :
@@ -1026,7 +1026,7 @@ def DoNothing():
1026
1026
pass
1027
1027
1028
1028
def InvokeDebugOpts ():
1029
- 'Called in GSASII.py to set up debug options'
1029
+ 'Called to set up debug options'
1030
1030
if any ('SPYDER' in name for name in os .environ ):
1031
1031
print ('Running from Spyder, keeping breakpoint() active & skipping exception trapping' )
1032
1032
elif GetConfigValue ('debug' ):
@@ -1136,13 +1136,13 @@ def SetBinaryPath(showConfigMsg=False):
1136
1136
BinaryPathFailed = pathHacking ._path_discovery (showConfigMsg )
1137
1137
1138
1138
def WriteConfig (configDict ):
1139
- '''Write the configDict information to the GSAS-II ini settings
1140
- into file ~/.GSASII/config.ini. Called from
1139
+ '''Write the configDict information to the GSAS-II ini settings
1140
+ into file ~/.GSASII/config.ini. Called from
1141
1141
:func:`GSASIIctrlGUI.SaveConfigVars`.
1142
1142
'''
1143
1143
import configparser
1144
-
1145
- localdir = os .path .expanduser ('~/.GSASII' )
1144
+
1145
+ localdir = os .path .expanduser (os . path . normpath ( '~/.GSASII' ) )
1146
1146
if not os .path .exists (localdir ):
1147
1147
try :
1148
1148
os .mkdir (g2local )
@@ -1166,13 +1166,37 @@ def LoadConfig(printInfo=True):
1166
1166
:param bool printInfo: if printInfo is True (default) then a message
1167
1167
is shown with the number of settings read (upon startup).
1168
1168
'''
1169
+ def XferConfigIni ():
1170
+ '''copy the contents of the config.py file to file ~/.GSASII/config.ini.
1171
+ This "patch code" used for master->develop transition and can eventually
1172
+ be removed.
1173
+ '''
1174
+ import types
1175
+ configDict = {}
1176
+ try :
1177
+ import config
1178
+ #import config_example as config
1179
+ for i in config .__dict__ :
1180
+ if i .startswith ('__' ) and i .endswith ('__' ): continue
1181
+ if isinstance (config .__dict__ [i ],types .ModuleType ): continue
1182
+ configDict .update ({i :str (config .__dict__ [i ])})
1183
+ except ImportError as err :
1184
+ print ("Error importing config.py file\n " ,err )
1185
+ return
1186
+ except Exception as err :
1187
+ print ("Error reading config.py file\n " ,err )
1188
+ return
1189
+ print (f"Contents of { config .__file__ } to be written..." )
1190
+ WriteIniConfi (configDict )
1191
+
1169
1192
import configparser
1170
1193
global configDict
1171
1194
configDict = {}
1172
- cfgfile = os .path .expanduser ('~/.GSASII/config.ini' )
1195
+ cfgfile = os .path .expanduser (os . path . normpath ( '~/.GSASII/config.ini' ) )
1173
1196
if not os .path .exists (cfgfile ):
1174
1197
print (f'N.B. Configuration file { cfgfile } does not exist' )
1175
- return
1198
+ # patch 2/7/25: transform GSAS-II config.py contents to config.ini
1199
+ XferConfigIni ()
1176
1200
try :
1177
1201
from . import config_example
1178
1202
except ImportError as err :
@@ -1201,7 +1225,7 @@ def LoadConfig(printInfo=True):
1201
1225
try :
1202
1226
if cfgG [key ] == 'None' :
1203
1227
configDict [capKey ] = None
1204
- elif key .endswith ('_pos' ) or key .endswith ('_size' ): # list of integers
1228
+ elif key .endswith ('_pos' ) or key .endswith ('_size' ): # list of integers
1205
1229
configDict [capKey ] = tuple ([int (i ) for i in
1206
1230
cfgG [key ].strip ('()' ).split (',' )])
1207
1231
elif key .endswith ('_location' ) or key .endswith ('_directory' ) or key .endswith ('_exec' ): # None (above) or str
@@ -1212,7 +1236,7 @@ def LoadConfig(printInfo=True):
1212
1236
res = []
1213
1237
else :
1214
1238
res = [i .strip ("'" ).replace (r'\\' ,'\\ ' ) for i in s .split (', ' )]
1215
- configDict [capKey ] = res
1239
+ configDict [capKey ] = res
1216
1240
elif isinstance (config_example .__dict__ [capKey ],bool ):
1217
1241
configDict [capKey ] = cfgG .getboolean (key )
1218
1242
elif isinstance (config_example .__dict__ [capKey ],float ):
@@ -1230,41 +1254,6 @@ def LoadConfig(printInfo=True):
1230
1254
print (f'{ len (configDict )} values read from { cfgfile } ' )
1231
1255
# make sure this value is set
1232
1256
configDict ['Clip_on' ] = configDict .get ('Clip_on' ,True )
1233
-
1234
- # def MacStartGSASII(g2script,project=''):
1235
- # '''Start a new instance of GSAS-II by opening a new terminal window and starting
1236
- # a new GSAS-II process. Used on Mac OS X only.
1237
-
1238
- # :param str g2script: file name for the GSASII.py script
1239
- # :param str project: GSAS-II project (.gpx) file to be opened, default is blank
1240
- # which opens a new project
1241
- # '''
1242
- # if project and os.path.splitext(project)[1] != '.gpx':
1243
- # print(f'file {project} cannot be used. Not GSAS-II project (.gpx) file')
1244
- # return
1245
- # if project and not os.path.exists(project):
1246
- # print(f'file {project} cannot be found.')
1247
- # return
1248
- # elif project:
1249
- # project = os.path.abspath(project)
1250
- # if not os.path.exists(project):
1251
- # print(f'lost project {project} with abspath')
1252
- # raise Exception(f'lost project {project} with abspath')
1253
- # g2script = os.path.abspath(g2script)
1254
- # pythonapp = sys.executable
1255
- # if os.path.exists(pythonapp+'w'): pythonapp += 'w'
1256
- # script = f'''
1257
- # set python to "{pythonapp}"
1258
- # set appwithpath to "{g2script}"
1259
- # set filename to "{project}"
1260
- # set filename to the quoted form of the POSIX path of filename
1261
-
1262
- # tell application "Terminal"
1263
- # activate
1264
- # do script python & " " & appwithpath & " " & filename & "; exit"
1265
- # end tell
1266
- # '''
1267
- # subprocess.Popen(["osascript","-e",script])
1268
1257
1269
1258
def MacRunScript (script ):
1270
1259
'''Start a bash script in a new terminal window.
@@ -1944,7 +1933,7 @@ def postURL(URL,postdict,getcookie=None,usecookie=None,
1944
1933
1945
1934
if gitUpdate :
1946
1935
# now restart GSAS-II with the new version
1947
- # G2scrpt = os.path.join(path2GSAS2,'GSASII .py')
1936
+ # G2scrpt = os.path.join(path2GSAS2,'G2 .py')
1948
1937
if project :
1949
1938
print (f"Restart GSAS-II with project file { project !r} " )
1950
1939
# subprocess.Popen([sys.executable,G2scrpt,project])
0 commit comments