class TestDataRegistry(unittest.TestCase): def setUp(self): self.base_temp_dir = tempfile.mkdtemp() self.dirs = [ ("TEST1", os.path.join(self.base_temp_dir, "test1/"), None), ("TEST2", "test2/", "TEST1"), ] self.files = [ ("ROOTFILE", "root.txt", None), ("TEST1_FILE", "test1file.txt", "TEST1"), ("TEST2_FILE", "test2file.txt", "TEST2"), ] self.data_reg = DataRegistry(dirs=self.dirs, files=self.files) pass def tearDown(self): shutil.rmtree(self.base_temp_dir) del self.data_reg pass def test_exceptions(self): with self.assertRaises(NotRegistered): self.data_reg.get_directory_path("TEST3") with self.assertRaises(AlreadyRegistered): self.data_reg.register_data_directory("TEST1", "false_test1/", None) def test_iter(self): for path in self.data_reg.get_all_files(): self.assertNotIn(path, [None, ""]) pass # end of class
def setUp(self): self.base_temp_dir = tempfile.mkdtemp() self.dirs = [ ("TEST1", os.path.join(self.base_temp_dir, "test1/"), None), ("TEST2", "test2/", "TEST1"), ] self.files = [ ("ROOTFILE", "root.txt", None), ("TEST1_FILE", "test1file.txt", "TEST1"), ("TEST2_FILE", "test2file.txt", "TEST2"), ] self.data_reg = DataRegistry(dirs=self.dirs, files=self.files) pass
def apply_runtime_settings(override_debug=False): """Apply runtime settings, can and needs to be called only once""" global __apply_lock__, SETTINGS_APPLIED if not __apply_lock__ and not SETTINGS_APPLIED: __apply_lock__ = True # Get command line arguments global ARGS ARGS = _parse_args() # Set gui flag global GUI_MODE GUI_MODE = not bool(ARGS.script) # Set debug flag global DEBUG DEBUG = ARGS.debug or override_debug # Setup data registry: global DATA_REG, DATA_DIRS, DATA_FILES from pyxrd.generic.io.data_registry import DataRegistry DATA_REG = DataRegistry(dirs=DATA_DIRS, files=DATA_FILES) # If we are running in GUI mode, setup GUI stuff: if GUI_MODE: import matplotlib import gtk # Setup matplotlib fonts: font = { 'weight' : 'heavy', 'size': 14, 'family' : 'sans-serif', } if sys.platform == "win32": font['sans-serif'] = 'Verdana, Arial, Helvetica, sans-serif' matplotlib.rc('font', **font) mathtext = {'default': 'regular', 'fontset': 'stixsans'} matplotlib.rc('mathtext', **mathtext) # matplotlib.rc('text', **{'usetex':True}) # Load our own icons: iconfactory = gtk.IconFactory() icons_path = DATA_REG.get_directory_path("APPLICATION_ICONS") for root, dirnames, filenames in os.walk(icons_path): for filename in filenames: if filename.endswith(".png"): stock_id = filename[:-4] # remove extensions filename = "%s/%s" % (icons_path, filename) pixbuf = gtk.gdk.pixbuf_new_from_file(filename) # @UndefinedVariable iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default() # Make sure default directories exist: for path in DATA_REG.get_all_directories(): try: os.makedirs(path) except OSError: pass # Register file parsers: for name in PARSER_MODULES: if not name.startswith('.'): # do not import relative paths! __import__(name) # Free some memory at this point: import gc gc.collect() # Log that we did all of this: import logging logger = logging.getLogger(__name__) logger.info("Runtime settings applied") __apply_lock__ = False SETTINGS_APPLIED = True
def initialize(override_debug=DEBUG): """Apply runtime settings, can and needs to be called only once""" global __apply_lock__, SETTINGS_APPLIED if not __apply_lock__ and not SETTINGS_APPLIED: __apply_lock__ = True # Get command line arguments global ARGS ARGS = _parse_args() # Set gui flag global GUI_MODE GUI_MODE = not bool(ARGS.script) # Set debug flag global DEBUG DEBUG = ARGS.debug or override_debug # Setup data registry: global DATA_REG, DATA_DIRS, DATA_FILES from pyxrd.generic.io.data_registry import DataRegistry DATA_REG = DataRegistry(dirs=DATA_DIRS, files=DATA_FILES) # If we are running in GUI mode, setup GUI stuff: if GUI_MODE: import matplotlib import gtk # Setup matplotlib fonts: font = { 'weight': 'heavy', 'size': 14, 'sans-serif': 'Helvetica, Arial, sans-serif', 'family': 'sans-serif', } matplotlib.rc('font', **font) mathtext = { 'default': 'regular', 'fontset': 'stixsans', } matplotlib.rc('mathtext', **mathtext) # matplotlib.rc('text', **{'usetex':True}) # Load our own icons: iconfactory = gtk.IconFactory() icons_path = DATA_REG.get_directory_path("APPLICATION_ICONS") for root, dirnames, filenames in os.walk(icons_path): for filename in filenames: if filename.endswith(".png"): stock_id = filename[:-4] # remove extensions filename = "%s/%s" % (icons_path, filename) pixbuf = gtk.gdk.pixbuf_new_from_file( filename) # @UndefinedVariable iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default() # Make sure default directories exist: for path in DATA_REG.get_all_directories(): try: os.makedirs(path) except OSError: pass # Free some memory at this point: import gc gc.collect() # Log that we did all of this: import logging logger = logging.getLogger(__name__) logger.info("Runtime settings applied") __apply_lock__ = False SETTINGS_APPLIED = True