def loadConfig(defaultsOnly=False): """ loadConfig(defaultsOnly=False) Load default configuration file and that of the user (if it exists). Any missing fields in the user config are set to the defaults. """ # Function to insert names from one config in another def replaceFields(base, new): for key in new: if key in base and isinstance(base[key], ssdf.Struct): replaceFields(base[key], new[key]) else: base[key] = new[key] # Reset our pyzo.config structure ssdf.clear(config) # Load default and inject in the pyzo.config fname = os.path.join(pyzoDir, 'resources', 'defaultConfig.ssdf') defaultConfig = ssdf.load(fname) replaceFields(config, defaultConfig) # Platform specific keybinding: on Mac, Ctrl+Tab (actually Cmd+Tab) is a system shortcut if sys.platform == 'darwin': config.shortcuts2.view__select_previous_file = 'Alt+Tab,' # Load user config and inject in pyzo.config fname = os.path.join(appDataDir, "config.ssdf") if os.path.isfile(fname): userConfig = ssdf.load(fname) replaceFields(config, userConfig)
def resetConfig(preserveState=True): """ resetConfig() Replaces the config fyle with the default and prevent Pyzo from storing its config on the next shutdown. """ # Get filenames configFileName1 = os.path.join(pyzoDir, 'resources', 'defaultConfig.ssdf') configFileName2 = os.path.join(appDataDir, 'config.ssdf') # Read, edit, write tmp = ssdf.load(configFileName1) if preserveState: tmp.state = config.state ssdf.save(configFileName2, tmp) global _saveConfigFile _saveConfigFile = False print("Replaced config file. Restart Pyzo to revert to the default config.")
def run(self, amount=100000): self._stop = False t0 = time.time() maxtests = amount while len(self._tests) < maxtests and not self._stop: # Create struct s = Generator.create_struct() n = ssdf.count(s) self._s = s # times times = [] sizes = [] # Test text t1 = time.time() text = ssdf.saves(s) times.append(time.time()-t1) # t1 = time.time() s2 = ssdf.loads(text) times.append(time.time()-t1) # if not compare(s, s2): print('Test text failed after %i iterations.' % len(self._tests)) break # Test binary t1 = time.time() bb = ssdf.saveb(s) times.append(time.time()-t1) # t1 = time.time() s2 = ssdf.loadb(bb) times.append(time.time()-t1) # if not compare(s, s2): print('Test bin failed after %i iterations.' % len(self._tests)) break # Test text file fname = homedir+'projects/ssdftest.ssdf' t1 = time.time() ssdf.save(fname, s) times.append(time.time()-t1) # t1 = time.time() s2 = ssdf.load(fname) times.append(time.time()-t1) sizes.append(os.stat(fname).st_size) # if not compare(s, s2): print('Test text-file failed after %i iterations.' % len(self._tests)) break # Test binary file fname = homedir+'projects/ssdftest.bsdf' t1 = time.time() ssdf.save(fname, s) times.append(time.time()-t1) # t1 = time.time() s2 = ssdf.load(fname) times.append(time.time()-t1) sizes.append(os.stat(fname).st_size) # if not compare(s, s2): print('Test bin-file failed after %i iterations.' % len(self._tests)) break # Success self._tests.append( (n, times, sizes) ) print('%i tests successfull' % len(self._tests)) time.sleep(0.001)