示例#1
0
 def test_metadata(self):
     pkg_db = PackageDB(self.tempdir.name)
     pkg_db.add_category("app-test")
     ebuild_data = {
         "herd": ["testers", "crackers"],
         "maintainer": [{"email": "*****@*****.**", "name": "tux"}],
         "longdescription": "very long description here",
         "use": {"flag": {"use1": "testing use1", "use2": "testing use2"}},
     }
     package = Package("app-test", "metadata_tester", "0.1")
     pkg_db.add_package(package, ebuild_data)
     metadata_g = MetadataGenerator(pkg_db)
     metadata = metadata_g.generate(package)
     self.assertEqual(
         metadata,
         [
             '<?xml version="1.0" encoding="utf-8"?>',
             '<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">',
             "<pkgmetadata>",
             "\t<herd>testers</herd>",
             "\t<herd>crackers</herd>",
             "\t<maintainer>",
             "\t\t<email>[email protected]</email>",
             "\t\t<name>tux</name>",
             "\t</maintainer>",
             "\t<longdescription>very long description here</longdescription>",
             "\t<use>",
             '\t\t<flag name="u">s</flag>',
             '\t\t<flag name="u">s</flag>',
             "\t</use>",
             "</pkgmetadata>",
         ],
     )
示例#2
0
class TestEbuildGenerator(BaseTest):

    ebuild_data = {"herd": ["testers", "crackers"],
                   'maintainer': [{'email': '*****@*****.**',
                                   'name': 'tux'}],
                   "longdescription": "very long description here",
                   "use": {"flag": {"use1": "testing use1", "use2": "testing use2"}},
                   "homepage": "example.com",
                   "description": "testing ebuild",
                   "array": "(a b c d)"}
    package = Package("app-test", "metadata_tester", "0.1")

    def setUp(self):
        super(TestEbuildGenerator, self).setUp()
        self.pkg_db = PackageDB(self.tempdir.name)
        self.pkg_db.add_category("app-test")
        self.pkg_db.add_package(self.package, self.ebuild_data)

    def test_ebuild_generator_from_file(self):
        template = os.path.join(self.tempdir.name, "test.tmpl")
        os.system("echo 'TEST_SUBST=%(array)s' > " + template)
        
        ebuild_g = EbuildGeneratorFromFile(self.pkg_db, template)
        ebuild = ebuild_g.generate(self.package)
        self.assertEqual(ebuild, ['TEST_SUBST=(a b c d)'])

    def test_default_ebuild_generator(self):
        vars_before_inherit = \
          [{"name":"test_raw_value", "value":"raw_value", "raw":True},
           {"name":"test_value", "value":"value"}]

        inherit = ["g-test"]
        
        vars_after_description = \
          ["homepage"]

        vars_after_keywords = \
          [{"name":"array"},
           {"name":"array", "raw":True}]

        layout = Layout(vars_before_inherit,
                    inherit, vars_after_description, vars_after_keywords)

        ebuild_g = DefaultEbuildGenerator(self.pkg_db, layout)
        ebuild = ebuild_g.generate(self.package)
        self.assertEqual(ebuild, ['# automatically generated by g-sorcery',
                                  '# please do not edit this file', '',
                                  'EAPI=5', '',
                                  'TEST_RAW_VALUE=raw_value', 'TEST_VALUE="value"', '',
                                  'inherit g-test', '',
                                  'DESCRIPTION="testing ebuild"', '',
                                  'HOMEPAGE="example.com"', '',
                                  'SLOT="0"', 'KEYWORDS="~amd64 ~x86"', '',
                                  'ARRAY="(a b c d)"', 'ARRAY=(a b c d)', ''])
示例#3
0
def main():
    parser = \
            argparse.ArgumentParser(description='Package DB manipulation tool')
    parser.add_argument('db_dir')

    subparsers = parser.add_subparsers()

    p_ebuild_data = subparsers.add_parser('ebuild_data')
    p_ebuild_data_subparsers = p_ebuild_data.add_subparsers()

    p_ebuild_data_rename = p_ebuild_data_subparsers.add_parser('add_var')
    p_ebuild_data_rename.set_defaults(func=add_var)
    p_ebuild_data_rename.add_argument('name')
    p_ebuild_data_rename.add_argument('-f', '--function')
    p_ebuild_data_rename.add_argument('-l', '--lambda_function')
    p_ebuild_data_rename.add_argument('-v', '--value')

    p_ebuild_data_rename = p_ebuild_data_subparsers.add_parser('rename_var')
    p_ebuild_data_rename.set_defaults(func=rename_var)
    p_ebuild_data_rename.add_argument('old_name')
    p_ebuild_data_rename.add_argument('new_name')

    p_ebuild_data_show_all = p_ebuild_data_subparsers.add_parser('show_all')
    p_ebuild_data_show_all.set_defaults(func=show_all)

    p_ebuild_data_for_all = p_ebuild_data_subparsers.add_parser('for_all')
    p_ebuild_data_for_all.add_argument('function')
    p_ebuild_data_for_all.set_defaults(func=for_all)

    p_sync = subparsers.add_parser('sync')
    p_sync.set_defaults(func=sync)
    p_sync.add_argument('uri')

    args = parser.parse_args()
    pkg_db = PackageDB(args.db_dir)
    return args.func(pkg_db, args)
示例#4
0
 def test_metadata(self):
     pkg_db = PackageDB(self.tempdir.name)
     pkg_db.add_category("app-test")
     ebuild_data = {"herd": ["testers", "crackers"],
                    'maintainer': [{'email': '*****@*****.**',
                                      'name': 'tux'}],
                    "longdescription": "very long description here",
                    "use": {"flag": {"use1": "testing use1", "use2": "testing use2"}}}
     package = Package("app-test", "metadata_tester", "0.1")
     pkg_db.add_package(package, ebuild_data)
     metadata_g = MetadataGenerator(pkg_db)
     metadata = metadata_g.generate(package)
     self.assertEqual(metadata,
                      ['<?xml version="1.0" encoding="utf-8"?>',
                       '<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">',
                       '<pkgmetadata>',
                       '\t<herd>testers</herd>', '\t<herd>crackers</herd>',
                       '\t<maintainer>', '\t\t<email>[email protected]</email>', '\t\t<name>tux</name>', '\t</maintainer>',
                       '\t<longdescription>very long description here</longdescription>',
                       '\t<use>', '\t\t<flag name="u">s</flag>', '\t\t<flag name="u">s</flag>', '\t</use>',
                       '</pkgmetadata>'])
示例#5
0
    def test_functionality(self):
        port = 8080
        for fmt in SUPPORTED_FILE_FORMATS:
            sync_address = "127.0.0.1:" + str(port) + "/dummy.tar.gz"
            orig_tempdir = TemporaryDirectory()
            orig_path = os.path.join(orig_tempdir.name, "db")
            os.makedirs(orig_path)
            orig_db = PackageDB(orig_path, preferred_category_format=fmt)
            orig_db.add_category("app-test1")
            orig_db.add_category("app-test2")
            ebuild_data = {
                "test1":
                "tst1",
                "test2":
                "tst2",
                "test3":
                serializable_elist([
                    DeserializableClass("1", "2"),
                    DeserializableClass("3", "4")
                ])
            }
            common_data = {
                "common1":
                "cmn1",
                "common2":
                "cmn2",
                "common3":
                serializable_elist([
                    DeserializableClass("c1", "c2"),
                    DeserializableClass("c3", "c4")
                ])
            }
            packages = [
                Package("app-test1", "test", "1"),
                Package("app-test1", "test", "2"),
                Package("app-test1", "test1", "1"),
                Package("app-test2", "test2", "1")
            ]
            for package in packages:
                orig_db.add_package(package, ebuild_data)
            orig_db.set_common_data("app-test1", common_data)
            full_data = dict(ebuild_data)
            full_data.update(common_data)

            orig_db.write()
            os.system("cd " + orig_tempdir.name +
                      " && tar cvzf good.tar.gz db")
            os.system("echo invalid >> " + orig_tempdir.name +
                      "/db/app-test1/packages." + fmt)
            os.system("cd " + orig_tempdir.name +
                      " && tar cvzf dummy.tar.gz db")

            test_db = PackageDB(self.tempdir.name)
            self.assertRaises(SyncError, test_db.sync, sync_address)

            srv = Server(orig_tempdir.name, port=port)
            srv.start()
            try:
                self.assertRaises(IntegrityError, test_db.sync, sync_address)
                os.system("cd " + orig_tempdir.name +
                          " && mv good.tar.gz dummy.tar.gz")
                test_db.sync(sync_address)
            finally:
                srv.shutdown()
                srv.join()
            test_db.read()
            self.assertEqual(orig_db.database, test_db.database)
            self.assertEqual(orig_db.get_common_data("app-test1"),
                             test_db.get_common_data("app-test1"))
            self.assertEqual(orig_db.get_common_data("app-test2"),
                             test_db.get_common_data("app-test2"))
            self.assertEqual(set(test_db.list_categories()),
                             set(["app-test1", "app-test2"]))
            self.assertTrue(test_db.in_category("app-test1", "test"))
            self.assertFalse(test_db.in_category("app-test2", "test"))
            self.assertRaises(InvalidKeyError, test_db.in_category,
                              "app-test3", "test")
            self.assertEqual(set(test_db.list_package_names("app-test1")),
                             set(['test', 'test1']))
            self.assertEqual(
                set(test_db.list_catpkg_names()),
                set(['app-test1/test', 'app-test1/test1', 'app-test2/test2']))
            self.assertRaises(InvalidKeyError, test_db.list_package_versions,
                              "invalid", "test")
            self.assertRaises(InvalidKeyError, test_db.list_package_versions,
                              "app-test1", "invalid")
            self.assertEqual(
                set(test_db.list_package_versions("app-test1", "test")),
                set(['1', '2']))
            self.assertEqual(set(test_db.list_all_packages()), set(packages))
            self.assertEqual(test_db.get_package_description(packages[0]),
                             full_data)
            self.assertRaises(KeyError, test_db.get_package_description,
                              Package("invalid", "invalid", "1"))
            self.assertEqual(test_db.get_max_version("app-test1", "test"), "2")
            self.assertEqual(test_db.get_max_version("app-test1", "test1"),
                             "1")
            self.assertRaises(InvalidKeyError, test_db.get_max_version,
                              "invalid", "invalid")
            pkg_set = set(packages)
            for package, data in test_db:
                self.assertTrue(package in pkg_set)
                if package.category == "app-test1":
                    self.assertEqual(data, full_data)
                else:
                    self.assertEqual(data, ebuild_data)
                pkg_set.remove(package)
            self.assertTrue(not pkg_set)
            self.assertEqual(orig_db.database, test_db.database)
            port = port + 1
示例#6
0
 def setUp(self):
     super(TestEbuildGenerator, self).setUp()
     self.pkg_db = PackageDB(self.tempdir.name)
     self.pkg_db.add_category("app-test")
     self.pkg_db.add_package(self.package, self.ebuild_data)
示例#7
0
class TestEbuildGenerator(BaseTest):

    ebuild_data = {
        "herd": ["testers", "crackers"],
        'maintainer': [{
            'email': '*****@*****.**',
            'name': 'tux'
        }],
        "longdescription": "very long description here",
        "use": {
            "flag": {
                "use1": "testing use1",
                "use2": "testing use2"
            }
        },
        "homepage": "example.com",
        "description": "testing ebuild",
        "array": "(a b c d)"
    }
    package = Package("app-test", "metadata_tester", "0.1")

    def setUp(self):
        super(TestEbuildGenerator, self).setUp()
        self.pkg_db = PackageDB(self.tempdir.name)
        self.pkg_db.add_category("app-test")
        self.pkg_db.add_package(self.package, self.ebuild_data)

    def test_ebuild_generator_from_file(self):
        template = os.path.join(self.tempdir.name, "test.tmpl")
        os.system("echo 'TEST_SUBST=%(array)s' > " + template)

        ebuild_g = EbuildGeneratorFromFile(self.pkg_db, template)
        ebuild = ebuild_g.generate(self.package)
        self.assertEqual(ebuild, ['TEST_SUBST=(a b c d)'])

    def test_default_ebuild_generator(self):
        vars_before_inherit = \
          [{"name":"test_raw_value", "value":"raw_value", "raw":True},
           {"name":"test_value", "value":"value"}]

        inherit = ["g-test"]

        vars_after_description = \
          ["homepage"]

        vars_after_keywords = \
          [{"name":"array"},
           {"name":"array", "raw":True}]

        layout = Layout(vars_before_inherit, inherit, vars_after_description,
                        vars_after_keywords)

        ebuild_g = DefaultEbuildGenerator(self.pkg_db, layout)
        ebuild = ebuild_g.generate(self.package)
        self.assertEqual(ebuild, [
            '# automatically generated by g-sorcery',
            '# please do not edit this file', '', 'EAPI=5', '',
            'TEST_RAW_VALUE=raw_value', 'TEST_VALUE="value"', '',
            'inherit g-test', '', 'DESCRIPTION="testing ebuild"', '',
            'HOMEPAGE="example.com"', '', 'SLOT="0"', 'KEYWORDS="~amd64 ~x86"',
            '', 'ARRAY="(a b c d)"', 'ARRAY=(a b c d)', ''
        ])
示例#8
0
    def test_functionality(self):
        port = 8080
        for fmt in SUPPORTED_FILE_FORMATS:
            sync_address = "127.0.0.1:" + str(port) + "/dummy.tar.gz"
            orig_tempdir = TemporaryDirectory()
            orig_path = os.path.join(orig_tempdir.name, "db")
            os.makedirs(orig_path)
            orig_db = PackageDB(orig_path, preferred_category_format=fmt)
            orig_db.add_category("app-test1")
            orig_db.add_category("app-test2")
            ebuild_data = {"test1": "tst1", "test2": "tst2",
                           "test3": serializable_elist([DeserializableClass("1", "2"),
                                                        DeserializableClass("3", "4")])}
            common_data = {"common1": "cmn1", "common2": "cmn2",
                           "common3": serializable_elist([DeserializableClass("c1", "c2"),
                                                          DeserializableClass("c3", "c4")])}
            packages = [Package("app-test1", "test", "1"), Package("app-test1", "test", "2"),
                        Package("app-test1", "test1", "1"), Package("app-test2", "test2", "1")]
            for package in packages:
                orig_db.add_package(package, ebuild_data)
            orig_db.set_common_data("app-test1", common_data)
            full_data = dict(ebuild_data)
            full_data.update(common_data)

            orig_db.write()
            os.system("cd " + orig_tempdir.name + " && tar cvzf good.tar.gz db")
            os.system("echo invalid >> " + orig_tempdir.name + "/db/app-test1/packages." + fmt)
            os.system("cd " + orig_tempdir.name + " && tar cvzf dummy.tar.gz db")

            test_db = PackageDB(self.tempdir.name)
            self.assertRaises(SyncError, test_db.sync, sync_address)

            srv = Server(orig_tempdir.name, port=port)
            srv.start()
            self.assertRaises(IntegrityError, test_db.sync, sync_address)
            os.system("cd " + orig_tempdir.name + " && mv good.tar.gz dummy.tar.gz")
            test_db.sync(sync_address)
            srv.shutdown()
            srv.join()
            test_db.read()
            self.assertEqual(orig_db.database, test_db.database)
            self.assertEqual(orig_db.get_common_data("app-test1"), test_db.get_common_data("app-test1"))
            self.assertEqual(orig_db.get_common_data("app-test2"), test_db.get_common_data("app-test2"))
            self.assertEqual(set(test_db.list_categories()), set(["app-test1", "app-test2"]))
            self.assertTrue(test_db.in_category("app-test1", "test"))
            self.assertFalse(test_db.in_category("app-test2", "test"))
            self.assertRaises(InvalidKeyError, test_db.in_category, "app-test3", "test")
            self.assertEqual(set(test_db.list_package_names("app-test1")), set(['test', 'test1']))
            self.assertEqual(set(test_db.list_catpkg_names()),set(['app-test1/test', 'app-test1/test1', 'app-test2/test2']))
            self.assertRaises(InvalidKeyError, test_db.list_package_versions, "invalid", "test")
            self.assertRaises(InvalidKeyError, test_db.list_package_versions, "app-test1", "invalid")
            self.assertEqual(set(test_db.list_package_versions("app-test1", "test")), set(['1', '2']))
            self.assertEqual(set(test_db.list_all_packages()), set(packages))
            self.assertEqual(test_db.get_package_description(packages[0]), full_data)
            self.assertRaises(KeyError, test_db.get_package_description, Package("invalid", "invalid", "1"))
            self.assertEqual(test_db.get_max_version("app-test1", "test"), "2")
            self.assertEqual(test_db.get_max_version("app-test1", "test1"), "1")
            self.assertRaises(InvalidKeyError, test_db.get_max_version, "invalid", "invalid")
            pkg_set = set(packages)
            for package, data in test_db:
                self.assertTrue(package in pkg_set)
                if package.category == "app-test1":
                    self.assertEqual(data, full_data)
                else:
                    self.assertEqual(data, ebuild_data)
                pkg_set.remove(package)
            self.assertTrue(not pkg_set)
            self.assertEqual(orig_db.database, test_db.database)
            port = port + 1
示例#9
0
 def setUp(self):
     super(TestEbuildGenerator, self).setUp()
     self.pkg_db = PackageDB(self.tempdir.name)
     self.pkg_db.add_category("app-test")
     self.pkg_db.add_package(self.package, self.ebuild_data)