Exemple #1
0
    def __init__(self, file_content):
        kvp_list = meta.parse(file_content)
        if not kvp_list:
            raise chewy.NoMetaError('No meta info found')

        # Default init members
        self.repobase = None

        # Validate meta info
        for kvp in kvp_list:
            if kvp[0] == meta.REPOBASE:
                if self.repobase is None:
                    self.repobase = kvp[1]
                else:
                    raise ModuleError('Multiple {} meta'.format(meta.REPOBASE))

        # Read modules list line by line
        lines = file_content.split('\n')
        self.modules = []
        line_number = 0
        for l in lines:
            line_number += 1
            line = l.lstrip()
            # Check for commented line
            if not l or l.startswith('#'):
                continue  # Ignore comments
            # Split record into fields
            record = line.split()
            if len(
                    record
            ) < self._MIN_RECORD_FIELDS:  # Minumum fields: path, version, description
                raise ManifestError(
                    'Too few fields in record at line {}'.format(line_number))

            # Unescape description
            # TODO Replace "magic number" w/ a constant
            record[2] = urllib.parse.unquote_plus(record[2])
            self.modules.append(
                chewy.Module(
                    chewy.Module.PiecewiseConstruct(self.repobase, *record)))
Exemple #2
0
 def test_module_status_1(self):
     mod = chewy.Module(_test_case_1)
     status = chewy.ModuleStatus(mod)
     status.set_remote_version(chewy.Version('1.0'))
     self.assertFalse(status.needs_update())
Exemple #3
0
 def test_module_alt(self):
     mod = chewy.Module(chewy.Module.PiecewiseConstruct('repobase', 'test.cmake', '1.0', 'description'))
     self.assertEqual(mod.repobase, 'repobase')
     self.assertEqual(mod.path, 'test.cmake')
     self.assertEqual(mod.version, chewy.Version('1.0'))
     self.assertEqual(mod.description, 'description')
Exemple #4
0
 def test_module(self):
     mod = chewy.Module(_test_case_1)
     self.assertEqual(mod.repobase, 'https://raw.github.com/mutanabbi/chewy-cmake-rep/master/')
     self.assertEqual(mod.path, 'AddBoostTests.cmake')
     self.assertEqual(mod.version, chewy.Version('2.0'))
     self.assertTrue(0 < len(mod.description))
Exemple #5
0
 def test_invalid_module_3(self):
     try:
         result = chewy.Module(_invalid_case_3)
         self.assertTrue(False)
     except chewy.ModuleError:
         self.assertTrue(True)
Exemple #6
0
 def test_empty_module(self):
     try:
         result = chewy.Module("")
         self.assertTrue(False)
     except chewy.NoMetaError:
         self.assertTrue(True)