Esempio n. 1
0
 def mark_in_config(self):
     """Mark the installation as installed in the config file"""
     config = ConfigHandler().config
     config.setdefault("frameworks", {})\
           .setdefault(self.category.prog_name, {})\
           .setdefault(self.prog_name, {})["path"] = self.install_path
     ConfigHandler().config = config
Esempio n. 2
0
 def mark_in_config(self):
     """Mark the installation as installed in the config file"""
     config = ConfigHandler().config
     config.setdefault("frameworks", {})\
           .setdefault(self.category.prog_name, {})\
           .setdefault(self.prog_name, {})["path"] = self.install_path
     ConfigHandler().config = config
Esempio n. 3
0
    def test_save_new_config(self):
        """Save a new config in a vanilla directory"""
        content = {'foo': 'bar'}
        ConfigHandler().config = content

        self.assertEqual(ConfigHandler().config, content)
        with open(os.path.join(self.config_dir, settings.CONFIG_FILENAME)) as f:
            self.assertEqual(f.read(), 'foo: bar\n')
Esempio n. 4
0
    def test_save_config_existing(self):
        """Replace an existing config with a new one"""
        shutil.copy(os.path.join(self.config_dir_for_name('valid'), settings.CONFIG_FILENAME), self.config_dir)
        content = {'foo': 'bar'}
        ConfigHandler().config = content

        self.assertEqual(ConfigHandler().config, content)
        with open(os.path.join(self.config_dir, settings.CONFIG_FILENAME)) as f:
            self.assertEqual(f.read(), 'foo: bar\n')
Esempio n. 5
0
    def test_transition_old_config(self):
        """Transition udtc old config to new umake one"""
        with tempfile.TemporaryDirectory() as tmpdirname:
            shutil.copy(os.path.join(self.config_dir_for_name("old"), "udtc"),
                        tmpdirname)
            change_xdg_path('XDG_CONFIG_HOME', tmpdirname)
            self.assertEqual(
                ConfigHandler().config, {
                    'frameworks': {
                        'category-a': {
                            'framework-a': {
                                'path':
                                '/home/didrocks/quickly/ubuntu-make/adt-eclipse'
                            },
                            'framework-b': {
                                'path': '/home/didrocks/foo/bar/android-studio'
                            }
                        }
                    }
                })

            # file has been renamed
            self.assertTrue(os.path.exists(os.path.join(tmpdirname, "umake")),
                            "New umake config file exists")
            self.assertFalse(os.path.exists(os.path.join(tmpdirname, "udtc")),
                             "Old udtc config file is removed")
Esempio n. 6
0
 def test_load_config(self):
     """Valid config loads correct content"""
     change_xdg_path('XDG_CONFIG_HOME', self.config_dir_for_name("valid"))
     self.assertEqual(ConfigHandler().config,
                      {'frameworks': {
                          'category-a': {
                              'framework-a': {'path': '/home/didrocks/quickly/ubuntu-make/adt-eclipse'},
                              'framework-b': {'path': '/home/didrocks/foo/bar/android-studio'}
                          }
                      }})
Esempio n. 7
0
    def __init__(self, name, description, category, logo_path=None, is_category_default=False, install_path_dir=None,
                 only_on_archs=None, only_ubuntu_version=None, packages_requirements=None):
        self.name = name
        self.description = description
        self.logo_path = None
        self.category = category
        self.is_category_default = is_category_default
        self.only_on_archs = [] if only_on_archs is None else only_on_archs
        self.only_ubuntu_version = [] if only_ubuntu_version is None else only_ubuntu_version
        self.packages_requirements = [] if packages_requirements is None else packages_requirements
        self.packages_requirements.extend(self.category.packages_requirements)

        # don't detect anything for completion mode (as we need to be quick), so avoid opening apt cache and detect
        # if it's installed.
        if is_completion_mode():
            category.register_framework(self)
            return

        self.need_root_access = False
        with suppress(KeyError):
            self.need_root_access = not RequirementsHandler().is_bucket_installed(self.packages_requirements)

        if self.is_category_default:
            if self.category == BaseCategory.main_category:
                logger.error("Main category can't have default framework as {} requires".format(name))
                self.is_category_default = False
            elif self.category.default_framework is not None:
                logger.error("Can't set {} as default for {}: this category already has a default framework ({}). "
                             "Don't set any as default".format(category.name, name,
                                                               self.category.default_framework.name))
                self.is_category_default = False
                self.category.default_framework.is_category_default = False

        if not install_path_dir:
            install_path_dir = os.path.join("" if category.is_main_category else category.prog_name, self.prog_name)
        self.default_install_path = os.path.join(DEFAULT_INSTALL_TOOLS_PATH, install_path_dir)
        self.install_path = self.default_install_path
        # check if we have an install path previously set
        config = ConfigHandler().config
        try:
            self.install_path = config["frameworks"][category.prog_name][self.prog_name]["path"]
        except (TypeError, KeyError, FileNotFoundError):
            pass

        # This requires install_path and will register need_root or not
        if not self.is_installed and not self.is_installable:
            logger.info("Don't register {} as it's not installable on this configuration.".format(name))
            return

        category.register_framework(self)
Esempio n. 8
0
 def remove_from_config(self):
     """Remove current framework from config"""
     config = ConfigHandler().config
     del (config["frameworks"][self.category.prog_name][self.prog_name])
     ConfigHandler().config = config
Esempio n. 9
0
 def test_load_invalid_config(self):
     """Existing invalid file gives an empty result"""
     change_xdg_path('XDG_CONFIG_HOME', self.config_dir_for_name("invalid"))
     self.assertEqual(ConfigHandler().config, {})
     self.expect_warn_error = True
Esempio n. 10
0
 def test_load_no_config(self):
     """No existing file gives an empty result"""
     change_xdg_path('XDG_CONFIG_HOME', self.config_dir_for_name("foo"))
     self.assertEqual(ConfigHandler().config, {})
Esempio n. 11
0
 def test_singleton(self):
     """Ensure we are delivering a singleton for TestConfigHandler"""
     config1 = ConfigHandler()
     config2 = ConfigHandler()
     self.assertEqual(config1, config2)
Esempio n. 12
0
    def test_dont_create_file_without_assignment(self):
        """We don't create any file without an assignment"""
        ConfigHandler()

        self.assertEqual(len(os.listdir(self.config_dir)), 0)