Esempio n. 1
0
 def test_opts_for(self):
     """ Requires the testing pakit.yml. """
     config_file = os.path.join(os.path.dirname(__file__), 'pakit.yml')
     config = Config(config_file)
     opts = config.opts_for('ag')
     assert opts.get('repo') == 'unstable'
     assert opts.get('prefix') == '/tmp/test_pakit/builds'
Esempio n. 2
0
 def test_get_missing_key(self):
     self.config.write()
     sub.call(['sed', '-i', '-e', '/command\\|timeout/d',
               self.config.filename])
     with open(self.config.filename) as fin:
         lines = fin.readlines()
         assert 'command:' not in lines
         assert 'timeout:' not in lines
     config = Config(self.config_file)
     assert config.get('pakit.command.timeout') == 120
Esempio n. 3
0
def global_init(config_file):
    """
    Performs global configuration of pakit.

    Must be called before using pakit. Will ...
        - Read user configuration.
        - Initialize the logging system.
        - Populate the recipe database.
        - Create configured folders.
        - Setup pakit man page.

    Args:
        config_file: The YAML configuration filename.

    Returns:
        The loaded config object.
    """
    config = Config(config_file)
    pakit.conf.CONFIG = config
    log_init(config)
    logging.debug('Global Config: %s', config)
    PLOG('Loaded config from: ' + config.filename)

    for path in config.get('pakit.paths').values():
        try:
            os.makedirs(path)
        except OSError:
            pass

    prefix = config.path_to('prefix')
    pakit.conf.IDB = InstallDB(os.path.join(prefix, 'idb.yml'))
    logging.debug('InstallDB: %s', pakit.conf.IDB)

    manager = pakit.recipe.RecipeManager(config)
    manager.check_for_deletions()
    manager.check_for_updates()
    manager.init_new_uris()
    recipe_db = pakit.recipe.RecipeDB(config)
    for path in manager.paths:
        recipe_db.index(path)
    pakit.recipe.RDB = recipe_db

    pakit.shell.link_man_pages(config.path_to('link'))
    environment_check(config)

    return config
Esempio n. 4
0
class TestConfig(object):
    """ Test the operation of Config class. """
    def setup(self):
        self.config_file = os.path.join(tc.STAGING, 'pakit.yml')
        self.config = Config(self.config_file)

    def teardown(self):
        tc.delete_it(self.config_file)

    def test_get_default(self):
        assert self.config.get('pakit.paths.prefixxx', 42) == 42

    def test_get_raises(self):
        with pytest.raises(KeyError):
            assert self.config['pakit.paths.prefixxx']

    def test_get_missing_key(self):
        self.config.write()
        sub.call(['sed', '-i', '-e', '/command\\|timeout/d',
                  self.config.filename])
        with open(self.config.filename) as fin:
            lines = fin.readlines()
            print(lines)
            assert 'command:' not in lines
            assert 'timeout:' not in lines
        config = Config(self.config_file)
        assert config.get('pakit.command.timeout') == 120

    def test_path_to(self):
        expect = pakit.conf.TEMPLATE['pakit']['paths']['link']
        assert self.config.path_to('link') == expect

    def test_path_to_raises(self):
        with pytest.raises(KeyError):
            self.config.path_to('bad_key')

    def test_opts_for(self):
        """ Requires the testing pakit.yml. """
        config_file = os.path.join(os.path.dirname(__file__), 'pakit.yml')
        config = Config(config_file)
        opts = config.opts_for('ag')
        assert opts.get('repo') == 'unstable'
        assert opts.get('prefix') == '/tmp/test_pakit/builds'

    def test_reset(self):
        self.config['pakit.paths.prefix'] = 22
        self.config.reset()
        assert self.config.get('pakit.paths.prefix') == '/tmp/pakit/builds'
Esempio n. 5
0
 def setup(self):
     self.config_file = os.path.join(tc.STAGING, 'pakit.yml')
     self.config = Config(self.config_file)
Esempio n. 6
0
class TestConfig(object):
    """ Test the operation of Config class. """
    def setup(self):
        self.config_file = os.path.join(tc.STAGING, 'pakit.yml')
        self.config = Config(self.config_file)

    def teardown(self):
        tc.delete_it(self.config_file)

    def test__str__(self):
        print()
        print(str(self.config))
        expect = """Config File: PLACE0
Contents:
{
  "pakit": {
    "command": {
      "timeout": 120
    },
    "defaults": {
      "repo": "stable"
    },
    "log": {
      "enabled": true,
      "file": "/tmp/pakit/main.log",
      "level": "debug"
    },
    "paths": {
      "link": "/tmp/pakit/links",
      "prefix": "/tmp/pakit/builds",
      "recipes": "PLACE1",
      "source": "/tmp/pakit/src"
    },
    "recipe": {
      "update_interval": 86400,
      "uris": [
        {
          "uri": "https://github.com/pakit/base_recipes"
        },
        {
          "uri": "user_recipes"
        }
      ]
    }
  }
}"""

        expect = expect.replace('PLACE0', self.config.filename)
        expect = expect.replace('PLACE1', os.path.expanduser('~/.pakit'))
        print(expect)
        assert str(self.config) == expect

    def test__contains__(self):
        assert 'pakit' in self.config
        assert 'pakit.paths' in self.config
        assert 'pakit.paths.prefix' in self.config
        assert 'beaver' not in self.config
        assert 'canada.beaver' not in self.config

    def test_get(self):
        assert self.config.get('pakit.paths.prefix') == '/tmp/pakit/builds'

    def test_get_missing_key(self):
        self.config.write()
        sub.call(['sed', '-i', '-e', '/command\\|timeout/d',
                  self.config.filename])
        with open(self.config.filename) as fin:
            lines = fin.readlines()
            assert 'command:' not in lines
            assert 'timeout:' not in lines
        config = Config(self.config_file)
        assert config.get('pakit.command.timeout') == 120

    def test_path_to(self):
        expect = pakit.conf.TEMPLATE['pakit']['paths']['link']
        assert self.config.path_to('link') == expect

    def test_path_to_raises(self):
        with pytest.raises(KeyError):
            self.config.path_to('bad_key')

    def test_get_raises(self):
        with pytest.raises(KeyError):
            self.config.get('pakit.paths.prefixxx')

    def test_opts_for(self):
        """ Requires the testing pakit.yml. """
        config_file = os.path.join(os.path.dirname(__file__), 'pakit.yml')
        config = Config(config_file)
        opts = config.opts_for('ag')
        assert opts.get('repo') == 'unstable'
        assert opts.get('prefix') == '/tmp/test_pakit/builds'

    def test_set(self):
        self.config.set('pakit.paths.prefix', '/dev/null')
        assert self.config.get('pakit.paths.prefix') == '/dev/null'

        self.config.set('hello.world', True)
        assert self.config.get('hello.world') is True

    def test_write(self):
        self.config.set('pakit.paths.install', 22)
        self.config.write()
        self.config.read()
        assert self.config.get('pakit.paths.install') == 22

    def test_reset(self):
        self.config.set('pakit.paths.prefix', 22)
        self.config.reset()
        assert self.config.get('pakit.paths.prefix') == '/tmp/pakit/builds'