Esempio n. 1
0
 def config_loading_test(self):
     """Check that the map config can be succesfully loaded"""
     confs = configs.Configs(default_configs_dir=self._defaults_path, configs_dir=self._profile_path)
     # check if modRana correctly copies the default config files to the
     # profile directory if none are found there
     loaded_configs = confs.check_config_files_exist()
     self.assertTrue(configs.MAP_CONFIG_FILE in loaded_configs)
     self.assertTrue(configs.USER_CONFIG_FILE in loaded_configs)
     self.assertTrue(confs.load_all())
     self.assertTrue(confs.load_user_config())
     self.assertTrue(confs.load_map_config())
     # check map config contents
     user_config = confs.user_config
     map_config = confs.map_config
     # the parsed config should contain something
     self.assertTrue(user_config)
     self.assertTrue(map_config)
     # check if user config contains what we expect
     self.assertTrue(user_config["enabled"])
     self.assertGreater(int(user_config["revision"]), 0)
     self.assertTrue("cycle" in user_config)
     self.assertTrue("car" in user_config)
     self.assertTrue("train" in user_config)
     self.assertTrue("foot" in user_config)
     self.assertTrue("bus" in user_config)
     # check if map config contains what we expect
     self.assertGreater(int(map_config["revision"]), 0)
     # do we have some layers & layer groups ?
     # - we need at least one layer & one group
     self.assertGreater(len(map_config["layers"]), 0)
     self.assertTrue(map_config["layers"]["mapnik"])
     self.assertGreater(len(map_config["groups"]), 0)
     self.assertTrue(map_config["groups"]["osm"])
Esempio n. 2
0
 def missing_default_configs_test(self):
     """Check that missing default configs raise an error"""
     with tempfile.TemporaryDirectory() as temp_dir:
         confs = configs.Configs(default_configs_dir=temp_dir, configs_dir=temp_dir)
         self.assertEqual(confs.check_config_files_exist(), [])
         self.assertFalse(confs.load_all())
         self.assertFalse(confs.load_user_config())
         self.assertFalse(confs.load_map_config())
Esempio n. 3
0
    def config_upgrade_test(self):
        """Check that config file upgrades work"""
        confs = configs.Configs(default_configs_dir=self._defaults_path, configs_dir=self._profile_path)
        # NOTE: just testing the map config file as that's
        #       what gets updated the most often

        # overwrite the actual default file with a custom one with revision == 2
        with open(os.path.join(self._defaults_path, configs.MAP_CONFIG_FILE), "wt") as f:
             f.write(MAP_CONFIG_R2)

        # also place another custom config with revision == 1 to the profile folder
        config_path = os.path.join(self._profile_path, configs.MAP_CONFIG_FILE)
        with open(config_path, "wt") as f:
             f.write(MAP_CONFIG_R1)

        # check the file before upgrade
        conf_r1 = ConfigObj(config_path)
        self.assertEqual(int(conf_r1["revision"]), 1)
        self.assertTrue("mapnik" in conf_r1["layers"])
        self.assertTrue("osm_landscape" in conf_r1["layers"])
        self.assertTrue("mapnik_bw" not in conf_r1["layers"])
        self.assertTrue("osm" in conf_r1["groups"])

        # trigger the upgrade
        confs.upgrade_config_files()

        # check if the old file has been renamed & is the revision 1 file
        renamed_map_config_path = os.path.join(self._profile_path, configs.MAP_CONFIG_FILE + "_old_revision_1")
        self.assertTrue(os.path.isfile(renamed_map_config_path))
        conf_renamed = ConfigObj(renamed_map_config_path)
        self.assertEqual(int(conf_renamed["revision"]), 1)
        self.assertTrue("mapnik" in conf_renamed["layers"])
        self.assertTrue("osm_landscape" in conf_renamed["layers"])
        self.assertTrue("mapnik_bw" not in conf_renamed["layers"])
        self.assertTrue("osm" in conf_renamed["groups"])

        # check content of the upgraded file
        conf_r2 = ConfigObj(config_path)
        self.assertEqual(int(conf_r2["revision"]), 2)
        self.assertTrue("mapnik" in conf_r2["layers"])
        self.assertTrue("osm_landscape" not in conf_r2["layers"])
        self.assertTrue("mapnik_bw" in conf_r2["layers"])
        self.assertTrue("osm" in conf_r2["groups"])
Esempio n. 4
0
    def __init__(self):
        singleton.modrana = self

        self.timing = []
        self.addCustomTime("modRana start", startTimestamp)
        self.addCustomTime("imports done", importsDoneTimestamp)

        # constants & variable initialization
        self.dmod = None  # device specific module
        self.gui = None
        self.GUIString = ""
        self.optLoadingOK = None

        self.d = {}  # persistent dictionary of data
        self.m = {}  # dictionary of loaded modules
        self.watches = {}  # List of data change watches
        self.maxWatchId = 0

        self.initInfo = {
            'modrana': self,
            'device': None,  # TODO: do this directly
            'name': ""
        }

        # signals
        self.notificationTriggered = Signal()
        self.shutdown_signal = Signal()

        self.mapRotationAngle = 0  # in radians
        self.notMovingSpeed = 1  # in m/s

        # per mode options
        # NOTE: this variable is automatically saved by the
        # options module
        self.keyModifiers = {}

        # initialize threading
        threads.initThreading()

        # start timing modRana launch
        self.addTime("GUI creation")

        # add the startup handling core module
        self.startup = startup.Startup(self)
        self.args = self.startup.getArgs()

        # handle any early tasks specified from CLI
        self.startup.handleEarlyTasks()

        # early CLI tasks might need a "silent" modRana
        # so the startup announcement is here
        log.info(" == modRana Starting == ")
        # load the version string (needs to be done here
        # as PWD might change after the paths module is
        # imported, for example when running
        # with the Qt 5 GUI)
        paths.load_version_string()
        version = paths.VERSION_STRING
        if version is None:
            version = "unknown version"
        log.info("  %s" % version)
        log.info("  Python %s" % platform.python_version())
        os_release = self._get_os_release()
        if os_release:
            log.info("  %s", os_release)

        # load the device module now as it might override
        # the default profile directory, so it needs to be
        # before ve init the core paths module
        self._load_device_module()

        # initialize the paths handling core module
        self.paths = paths.Paths(self)

        # add the configs handling core module
        self.configs = configs.Configs(configs_dir=self.paths.profile_path)

        # load persistent options
        self.optLoadingOK = self._load_options()
        self._options_loaded()

        # check if upgrade took place

        if self.optLoadingOK:
            savedVersionString = self.get('modRanaVersionString', "")
            versionStringFromFile = paths.VERSION_STRING
            if savedVersionString != versionStringFromFile:
                log.info("possible upgrade detected")
                self._post_upgrade_check()

        # save current version string
        self.set('modRanaVersionString', paths.VERSION_STRING)

        # load all configuration files
        self.configs.load_all()

        # start loading other modules

        # handle tasks that require the device
        # module but not GUI
        self.startup.handle_non_gui_tasks()

        # then the GUI module
        self._load_gui_module()

        # and all other modules
        self._load_modules()

        # startup done, log some statistics
        self._startup_done()