def test_get_manifest_multiple_root(self): user_dbs, registry = self._setUpMultiDB() expected_a = { "name": "a", "version": "1.1", "_directory": os.path.join(user_dbs[1], "a"), "_removable": 1, } self.assertEqual(expected_a, json_object_to_python(registry.get_manifest("a"))) self.assertEqual(expected_a, json.loads(registry.get_manifest_as_string("a"))) expected_b = { "name": "b", "version": "2.0", "_directory": os.path.join(user_dbs[0], "b"), "_removable": 1, } self.assertEqual(expected_b, json_object_to_python(registry.get_manifest("b"))) self.assertEqual(expected_b, json.loads(registry.get_manifest_as_string("b"))) expected_c = { "name": "c", "version": "0.1", "_directory": os.path.join(user_dbs[1], "c"), "_removable": 1, } self.assertEqual(expected_c, json_object_to_python(registry.get_manifest("c"))) self.assertEqual(expected_c, json.loads(registry.get_manifest_as_string("c"))) self.assertRaisesUserError(Click.UserError.NO_SUCH_PACKAGE, registry.get_path, "d")
def test_manifest(self): manifest_path = os.path.join(self.temp_dir, "a", "1.0", ".click", "info", "a.manifest") manifest_obj = { "name": "a", "version": "1.0", "hooks": { "a-app": {} }, "_should_be_removed": "", } with mkfile(manifest_path) as manifest: json.dump(manifest_obj, manifest) del manifest_obj["_should_be_removed"] manifest_obj["_directory"] = os.path.join(self.temp_dir, "a", "1.0") self.assertEqual( manifest_obj, json_object_to_python(self.db.get_manifest("a", "1.0"))) self.assertRaisesDatabaseError(Click.DatabaseError.DOES_NOT_EXIST, self.db.get_manifest, "a", "1.1") self.assertEqual( manifest_obj, json.loads(self.db.get_manifest_as_string("a", "1.0"))) self.assertRaisesDatabaseError(Click.DatabaseError.DOES_NOT_EXIST, self.db.get_manifest_as_string, "a", "1.1")
def test_manifest(self): with open(os.path.join(self.temp_dir, "a.conf"), "w") as a: print("[Click Database]", file=a) print("root = %s" % os.path.join(self.temp_dir, "a"), file=a) with open(os.path.join(self.temp_dir, "b.conf"), "w") as b: print("[Click Database]", file=b) print("root = %s" % os.path.join(self.temp_dir, "b"), file=b) db = Click.DB() db.read(db_dir=self.temp_dir) self.assertRaisesDatabaseError(Click.DatabaseError.DOES_NOT_EXIST, db.get_manifest, "pkg", "1.0") self.assertRaisesDatabaseError(Click.DatabaseError.DOES_NOT_EXIST, db.get_manifest_as_string, "pkg", "1.0") a_manifest_path = os.path.join(self.temp_dir, "a", "pkg", "1.0", ".click", "info", "pkg.manifest") a_manifest_obj = {"name": "pkg", "version": "1.0"} with mkfile(a_manifest_path) as a_manifest: json.dump(a_manifest_obj, a_manifest) a_manifest_obj["_directory"] = os.path.join(self.temp_dir, "a", "pkg", "1.0") self.assertEqual(a_manifest_obj, json_object_to_python(db.get_manifest("pkg", "1.0"))) self.assertEqual(a_manifest_obj, json.loads(db.get_manifest_as_string("pkg", "1.0"))) self.assertRaisesDatabaseError(Click.DatabaseError.DOES_NOT_EXIST, db.get_manifest, "pkg", "1.1") self.assertRaisesDatabaseError(Click.DatabaseError.DOES_NOT_EXIST, db.get_manifest_as_string, "pkg", "1.1") b_manifest_path = os.path.join(self.temp_dir, "b", "pkg", "1.1", ".click", "info", "pkg.manifest") b_manifest_obj = {"name": "pkg", "version": "1.1"} with mkfile(b_manifest_path) as b_manifest: json.dump(b_manifest_obj, b_manifest) b_manifest_obj["_directory"] = os.path.join(self.temp_dir, "b", "pkg", "1.1") self.assertEqual(b_manifest_obj, json_object_to_python(db.get_manifest("pkg", "1.1"))) self.assertEqual(b_manifest_obj, json.loads(db.get_manifest_as_string("pkg", "1.1")))
def test_get_manifest(self): registry = Click.User.for_user(self.db, "user") manifest_path = os.path.join(self.temp_dir, "a", "1.0", ".click", "info", "a.manifest") manifest_obj = {"name": "a", "version": "1.0"} with mkfile(manifest_path) as manifest: json.dump(manifest_obj, manifest) manifest_obj["_directory"] = os.path.join(registry.get_overlay_db(), "a") manifest_obj["_removable"] = 1 registry.set_version("a", "1.0") self.assertEqual(manifest_obj, json_object_to_python(registry.get_manifest("a"))) self.assertEqual(manifest_obj, json.loads(registry.get_manifest_as_string("a")))
def get_manifest(options, arg): if "/" not in arg: db = Click.DB() db.read(db_dir=None) if options.root is not None: db.add(options.root) registry = Click.User.for_user(db, name=options.user) if registry.has_package_name(arg): return json_object_to_python(registry.get_manifest(arg)) try: with closing(DebFile(filename=arg)) as package: with package.control.get_file("manifest", encoding="UTF-8") as manifest_file: return _load_manifest(manifest_file) except Exception: pkgdir = Click.find_package_directory(arg) manifest_path = glob.glob( os.path.join(pkgdir, ".click", "info", "*.manifest")) if len(manifest_path) > 1: raise Exception("Multiple manifest files found in '%s'" % (manifest_path)) with open(manifest_path[0]) as f: return _load_manifest(f)