def test_load_save(self): System() prefs = System.get_preferences() PreferencesPersistence.save(prefs, "/tmp") PreferencesPersistence.save(prefs, "/etc") PreferencesPersistence.load("/tmp") PreferencesPersistence.load("/not") os.remove("/tmp/" + prefs.conf_file_path) code_template = self.create_code_template() code_template.name = "configuration" CodeTemplatePersistence.save_xml(code_template, "/tmp/") result = PreferencesPersistence.load("/tmp") file_name = "/tmp/" + code_template.name + ".xml" os.remove(file_name)
def __init__(self): self.Log = None self.__code_templates = {} self.__blocks = {} self.__ports = {} self.list_of_examples = [] self.plugins = [] self.properties = PreferencesPersistence.load( System.get_user_dir())
def __init__(self): self.Log = None self.__code_templates = {} self.__blocks = {} self.__ports = {} self.list_of_examples = [] self.plugins = [] self.properties = PreferencesPersistence.load() self.__load_examples() self.__load_libs() self.__load_plugins()
class TestPreferencesPersistence(TestCase): def setUp(self): """Do the test basic setup.""" self.preferencespersistence = PreferencesPersistence() # ----------------------------------------------------------------------x def test_load(self): self.assertIsNotNone(self.preferencespersistence.load()) # ----------------------------------------------------------------------x def test_save(self): preferences = Preferences() self.assertTrue(self.preferencespersistence.save(preferences)) preferences.type = "teste_preferencespersistence" self.assertTrue(self.preferencespersistence.save(preferences))
def __init__(self): self.Log = None self.__code_templates = {} self.__blocks = {} self.__ports = {} self.list_of_examples = [] # Create user directory if does not exist directories = ["extensions", "images", "code-gen"] for name in directories: path = os.path.join(System.get_user_dir(), name) if not os.path.isdir(path): try: os.makedirs(path) except Exception as error: System.log(error) self.__preferences = PreferencesPersistence.load( System.get_user_dir())
def __init__(self): self.Log = None self.__code_templates = {} self.__blocks = {} self.__ports = {} self.list_of_examples = [] self.__plugins = [] # Create user directory if does not exist directories = [ "/extensions/", "/examples/", "/images/", "/diagrams/", "/code-gen/" ] for name in directories: if not os.path.isdir(System.get_user_dir() + name): try: os.makedirs(System.get_user_dir() + name) except Exception as error: System.log(error) self.__preferences = PreferencesPersistence.load( System.get_user_dir())
def get_preferences(self): if self.__preferences is None: self.__preferences = PreferencesPersistence.load(self.user_dir) return self.__preferences
def __load(self): # Create user directory if does not exist if not os.path.isdir(System.get_user_dir() + "/extensions/"): try: os.makedirs(System.get_user_dir() + "/extensions/") except: pass # Load the preferences self.properties = PreferencesPersistence.load() # Load Examples examples = glob(System.DATA_DIR + "examples/*") for example in examples: self.list_of_examples.append(example) self.list_of_examples.sort() # Load CodeTemplates, Plugins and Ports self.code_templates.clear() self.ports.clear() self.plugins.clear() # First load ports on python classes. # They are installed with mosaicode as root def my_walk_packages(path=None, name_par=""): for importer, name, ispkg in pkgutil.iter_modules( path, name_par + "."): if name.startswith(System.APP + "_") or name_par.startswith(System.APP + "_"): if ispkg: if name_par is not "": name = name_par + "." + name __import__(name) path = getattr(sys.modules[name], '__path__', None) or [] my_walk_packages(path, name) else: module = __import__(name, fromlist="dummy") print name for class_name, obj in inspect.getmembers(module): if not inspect.isclass(obj): continue modname = inspect.getmodule(obj).__name__ if not modname.startswith(System.APP + "_"): continue instance = obj() if isinstance(instance, CodeTemplate): self.code_templates[ instance.type] = instance if isinstance(instance, Port): instance.source = "Python" self.ports[instance.type] = instance if isinstance(instance, Plugin): if instance.label != "": self.plugins[instance.type] = instance my_walk_packages(None, "") # Load XML files in application space self.__load_xml(System.DATA_DIR + "extensions/") # Load XML files in user space self.__load_xml(System.get_user_dir() + "/extensions/")