Changeset 1087 for framspy/frams.py
- Timestamp:
- 02/19/21 03:14:41 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/frams.py
r1085 r1087 23 23 24 24 _reInsideParens = re.compile('\((.*)\)') 25 _reservedWords = ['import'] # this list is scanned during every attribute access, only add what is really clashing with framsticks properties25 _reservedWords = ['import'] # this list is scanned during every attribute access, only add what is really clashing with Framsticks properties 26 26 _reservedXWords = ['x' + word for word in _reservedWords] 27 27 _encoding = 'utf-8' … … 252 252 Initializes the connection to Framsticks dll/so. 253 253 254 Python programs do not have to know the framstics path but if they know, just pass the path as the first argument.255 Similarly '-dPATH' and '-DPATH' needed by framsticks are optional and derived from the first path, unless they are specified as args in init().256 '- lNAME' is the optional library name (full name including the file name extension), default is 'frams-objects.dll/.so' depending on the platform.257 All other arguments are passed to framsticks and not interpreted by this function.254 Python programs do not have to know the Framstics path but if they know, just pass the path as the first argument. 255 Similarly '-dPATH' and '-DPATH' needed by Framsticks are optional and derived from the first path, unless they are specified as args in init(). 256 '-LNAME' is the optional library name (full name including the file name extension), default is 'frams-objects.dll/.so' depending on the platform. 257 All other arguments are passed to Framsticks and not interpreted by this function. 258 258 259 259 """ 260 260 # goals: 261 frams_d =None262 frams_D =None263 lib_path =None264 lib_name ='frams-objects.so' if os.name == 'posix' else 'frams-objects.dll'265 initargs =[]261 frams_d = None 262 frams_D = None 263 lib_path = None 264 lib_name = 'frams-objects.so' if os.name == 'posix' else 'frams-objects.dll' 265 initargs = [] 266 266 for a in args: 267 if a[:2] =='-d':268 frams_d =a269 elif a[:2] =='-D':270 frams_D =a271 elif a[:2] =='-l':272 lib_name =a[2:]273 elif lib_path ==None:274 lib_path =a267 if a[:2] == '-d': 268 frams_d = a 269 elif a[:2] == '-D': 270 frams_D = a 271 elif a[:2] == '-L': 272 lib_name = a[2:] 273 elif lib_path is None: 274 lib_path = a 275 275 else: 276 276 initargs.append(a) 277 if lib_path ==None:278 # todo: use envvariable and/or the zip distribution we are in when the path is not specified in arg279 # for now just assume the current dir is framsticks280 lib_path ='.'277 if lib_path is None: 278 # TODO: use environment variable and/or the zip distribution we are in when the path is not specified in arg 279 # for now just assume the current dir is Framsticks 280 lib_path = '.' 281 281 282 282 original_dir = os.getcwd() 283 os.chdir(lib_path) # because under Windows, frams .dll requires other dll's which reside in the same directory, so we must change current dir for them to be found while loading the main dll284 abs_data =os.path.abspath('data') #use absolute path for -d and -D so python is free to cd anywhere without confusing the frams283 os.chdir(lib_path) # because under Windows, frams-objects.dll requires other dll's which reside in the same directory, so we must change current dir for them to be found while loading the main dll 284 abs_data = os.path.abspath('data') # use absolute path for -d and -D so python is free to cd anywhere without confusing Framsticks 285 285 # for the hypothetical case without lib_path the abs_data must be obtained from somewhere else 286 if frams_d ==None:287 frams_d ='-d'+abs_data288 if frams_D ==None:289 frams_D ='-D'+abs_data290 initargs.insert(0, frams_d)291 initargs.insert(0, frams_D)292 initargs.insert(0, 'dummy.exe')293 286 if frams_d is None: 287 frams_d = '-d' + abs_data 288 if frams_D is None: 289 frams_D = '-D' + abs_data 290 initargs.insert(0, frams_d) 291 initargs.insert(0, frams_D) 292 initargs.insert(0, 'dummy.exe') # as an offset, 0th arg is by convention app name 293 294 294 global c_api # access global variable 295 if lib_path !=None and os.name == 'posix':296 lib_name = './' +lib_name #currently we always have lib_path (even if it is incorrect) but hypothetically it could work with lib_path==None and load .so from some default system path without './'295 if lib_path is not None and os.name == 'posix': 296 lib_name = './' + lib_name # currently we always have lib_path (even if it is incorrect) but hypothetically it could work with lib_path==None and load .so from some default system path without './' 297 297 c_api = ctypes.CDLL(lib_name) 298 298 os.chdir(original_dir) 299 299 300 300 c_api.init.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)] 301 301 c_api.init.restype = None
Note: See TracChangeset
for help on using the changeset viewer.