예제 #1
0
 def test_multiple_architectures(self, mock_dpkg_architecture,
                                 mock_package_install_hooks):
     with self.run_in_subprocess("click_get_frameworks_dir") as (enter,
                                                                 preloads):
         enter()
         mock_dpkg_architecture.return_value = "armhf"
         path = self.make_fake_package(
             control_fields={
                 "Package": "test-package",
                 "Version": "1.1",
                 "Architecture": "multi",
                 "Maintainer": "Foo Bar <*****@*****.**>",
                 "Description": "test",
                 "Click-Version": "0.2",
             },
             manifest={
                 "name": "test-package",
                 "version": "1.1",
                 "framework": "ubuntu-sdk-13.10",
                 "architecture": ["armhf", "i386"],
             },
             control_scripts={"preinst": static_preinst})
         root = os.path.join(self.temp_dir, "root")
         db = Click.DB()
         db.add(root)
         installer = ClickInstaller(db)
         self._setup_frameworks(preloads, frameworks=["ubuntu-sdk-13.10"])
         with mock_quiet_subprocess_call():
             installer.install(path)
         self.assertTrue(
             os.path.exists(os.path.join(root, "test-package", "current")))
예제 #2
0
def run(argv):
    parser = OptionParser("%prog pkgdir [options] {PACKAGE-NAME|PATH}")
    parser.add_option(
        "--root", metavar="PATH", help="look for additional packages in PATH")
    parser.add_option(
        "--user", metavar="USER",
        help="look up PACKAGE-NAME for USER (if you have permission; "
             "default: current user)")
    options, args = parser.parse_args(argv)
    if len(args) < 1:
        parser.error("need package name")
    try:
        if "/" in args[0]:
            print(Click.find_package_directory(args[0]))
        else:
            db = Click.DB()
            db.read(db_dir=None)
            if options.root is not None:
                db.add(options.root)
            package_name = args[0]
            registry = Click.User.for_user(db, name=options.user)
            print(registry.get_path(package_name))
    except Exception as e:
        print(e, file=sys.stderr)
        return 1
    return 0
예제 #3
0
 def setUp(self):
     super(TestClickSingleDB, self).setUp()
     self.use_temp_dir()
     self.master_db = Click.DB()
     self.master_db.add(self.temp_dir)
     self.db = self.master_db.get(self.master_db.props.size - 1)
     self.spawn_calls = []
예제 #4
0
 def test_packages_all(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.assertEqual([], list(db.get_packages(all_versions=True)))
     os.makedirs(os.path.join(self.temp_dir, "a", "pkg1", "1.0"))
     os.symlink("1.0", os.path.join(self.temp_dir, "a", "pkg1", "current"))
     os.makedirs(os.path.join(self.temp_dir, "b", "pkg1", "1.1"))
     os.symlink("1.1", os.path.join(self.temp_dir, "b", "pkg1", "current"))
     os.makedirs(os.path.join(self.temp_dir, "b", "pkg2", "0.1"))
     os.symlink("0.1", os.path.join(self.temp_dir, "b", "pkg2", "current"))
     self.assertEqual([
         ("pkg1", "1.1", os.path.join(self.temp_dir, "b", "pkg1",
                                      "1.1"), True),
         ("pkg2", "0.1", os.path.join(self.temp_dir, "b", "pkg2",
                                      "0.1"), True),
         ("pkg1", "1.0", os.path.join(self.temp_dir, "a", "pkg1",
                                      "1.0"), False),
     ], self._installed_packages_tuplify(
         db.get_packages(all_versions=True)))
예제 #5
0
 def get_installed_version_and_directory(self):
     db = Click.DB()
     db.read()
     package_name = 'com.ubuntu.reminders'
     registry = Click.User.for_user(db, name=os.environ.get('USER'))
     version = registry.get_version(package_name)
     directory = registry.get_path(package_name)
     return version, directory
예제 #6
0
 def setUp(self):
     super(TestClickInstaller, self).setUp()
     self.use_temp_dir()
     self.db = Click.DB()
     self.db.add(self.temp_dir)
     # mock signature checks during the tests
     self.debsig_patcher = mock.patch("click_package.install.DebsigVerify")
     self.debsig_patcher.start()
예제 #7
0
 def test_upgrade(self, mock_package_install_hooks):
     with self.run_in_subprocess("click_get_frameworks_dir") as (enter,
                                                                 preloads):
         enter()
         os.environ["TEST_QUIET"] = "1"
         path = self.make_fake_package(
             control_fields={
                 "Package": "test-package",
                 "Version": "1.1",
                 "Architecture": "all",
                 "Maintainer": "Foo Bar <*****@*****.**>",
                 "Description": "test",
                 "Click-Version": "0.2",
             },
             manifest={
                 "name": "test-package",
                 "version": "1.1",
                 "framework": "ubuntu-sdk-13.10",
             },
             control_scripts={"preinst": static_preinst},
             data_files={"foo": None})
         root = os.path.join(self.temp_dir, "root")
         package_dir = os.path.join(root, "test-package")
         inst_dir = os.path.join(package_dir, "current")
         os.makedirs(os.path.join(package_dir, "1.0"))
         os.symlink("1.0", inst_dir)
         db = Click.DB()
         db.add(root)
         installer = ClickInstaller(db)
         self._setup_frameworks(preloads, frameworks=["ubuntu-sdk-13.10"])
         with mock_quiet_subprocess_call():
             installer.install(path)
         self.assertCountEqual([".click", "test-package"], os.listdir(root))
         self.assertCountEqual(["1.1", "current"], os.listdir(package_dir))
         self.assertTrue(os.path.islink(inst_dir))
         self.assertEqual("1.1", os.readlink(inst_dir))
         self.assertCountEqual([".click", "foo"], os.listdir(inst_dir))
         status_path = os.path.join(inst_dir, ".click", "status")
         with open(status_path) as status_file:
             # .readlines() avoids the need for a python-apt backport to
             # Ubuntu 12.04 LTS.
             status = list(Deb822.iter_paragraphs(status_file.readlines()))
         self.assertEqual(1, len(status))
         self.assertEqual(
             {
                 "Package": "test-package",
                 "Status": "install ok installed",
                 "Version": "1.1",
                 "Architecture": "all",
                 "Maintainer": "Foo Bar <*****@*****.**>",
                 "Description": "test",
                 "Click-Version": "0.2",
             }, status[0])
         mock_package_install_hooks.assert_called_once_with(db,
                                                            "test-package",
                                                            "1.0",
                                                            "1.1",
                                                            user_name=None)
예제 #8
0
    def test_gc_fixes_old_user_registrations(self):
        with self.run_in_subprocess("getpwnam") as (enter, preloads):
            enter()

            # Setup the system hook
            preloads["getpwnam"].side_effect = (
                lambda name: self.make_pointer(Passwd(pw_dir=b"/foo")))

            # Setup both databases
            db1 = os.path.join(self.temp_dir, "db1")
            db2 = os.path.join(self.temp_dir, "db2")
            db = Click.DB()
            db.add(db1)
            db.add(db2)

            # Prepare common manifest for the packages
            manifest = {"hooks": {"test-app": {"test": "foo"}}}

            # Setup versions 1.0 and 3.0 of package in db1
            version1 = os.path.join(db1, "test-package", "1.0")
            with mkfile(
                    os.path.join(version1, ".click", "info",
                                 "test-package.manifest")) as f:
                json.dump(manifest, f)

            version3 = os.path.join(db1, "test-package", "3.0")
            with mkfile(
                    os.path.join(version3, ".click", "info",
                                 "test-package.manifest")) as f:
                json.dump(manifest, f)

            # Setup version 0.2 of package in db2
            version2 = os.path.join(db2, "test-package", "2.0")
            with mkfile(
                    os.path.join(version2, ".click", "info",
                                 "test-package.manifest")) as f:
                json.dump(manifest, f)

            # Setup the user registration for 2.0 in db2.
            registrationPath = os.path.join(db2, ".click", "users", "foo",
                                            "test-package")
            os.makedirs(os.path.dirname(registrationPath))
            os.symlink(version2, registrationPath)

            # Run the garbage collection to update the registrations.
            db.gc()

            # Verify that the user still has a registration for the package,
            # and that it's now registered for version 3.0.
            self.assertTrue(os.path.lexists(registrationPath))
            self.assertEqual(version3, os.readlink(registrationPath))

            user_db = Click.User.for_user(db, "foo")
            try:
                version = user_db.get_version("test-package")
                self.assertEqual("3.0", version)
            except:
                self.fail("No user registration for 'test-package'")
예제 #9
0
 def test_no_db_conf_errors(self):
     db = Click.DB()
     self.assertRaisesDatabaseError(Click.DatabaseError.INVALID, db.get, 0)
     self.assertEqual(db.props.overlay, "")
     self.assertRaisesDatabaseError(Click.DatabaseError.INVALID,
                                    db.maybe_remove, "something", "1.0")
     self.assertRaisesDatabaseError(Click.DatabaseError.INVALID, db.gc)
     self.assertRaisesDatabaseError(Click.DatabaseError.INVALID,
                                    db.ensure_ownership)
예제 #10
0
def list_packages(options):
    db = Click.DB()
    db.read(db_dir=None)
    if options.root is not None:
        db.add(options.root)
    if options.all:
        return json_array_to_python(db.get_manifests(all_versions=True))
    else:
        registry = Click.User.for_user(db, name=options.user)
        return json_array_to_python(registry.get_manifests())
예제 #11
0
 def test_overlay(self):
     with open(os.path.join(self.temp_dir, "00_custom.conf"), "w") as f:
         print("[Click Database]", file=f)
         print("root = /custom", file=f)
     with open(os.path.join(self.temp_dir, "99_default.conf"), "w") as f:
         print("[Click Database]", file=f)
         print("root = /opt/click.ubuntu.com", file=f)
     db = Click.DB()
     db.read(db_dir=self.temp_dir)
     self.assertEqual("/opt/click.ubuntu.com", db.props.overlay)
예제 #12
0
 def setUp(self):
     super(UserDataRemovalTestCase, self).setUp()
     self.use_temp_dir()
     self.db = Click.DB()
     self.db.add(self.temp_dir)
     # add app
     self.appname = "some-app"
     self.registry = Click.User.for_user(self.db, "user")
     os.makedirs(self.registry.get_overlay_db())
     path = os.path.join(self.registry.get_overlay_db(), self.appname)
     os.symlink("/1.0", path)
예제 #13
0
 def test_read_configuration(self):
     with open(os.path.join(self.temp_dir, "a.conf"), "w") as a:
         print("[Click Database]", file=a)
         print("root = /a", file=a)
     with open(os.path.join(self.temp_dir, "b.conf"), "w") as b:
         print("[Click Database]", file=b)
         print("root = /b", file=b)
     db = Click.DB()
     db.read(db_dir=self.temp_dir)
     db.add("/c")
     self.assertEqual(3, db.props.size)
     self.assertEqual(["/a", "/b", "/c"],
                      [db.get(i).props.root for i in range(db.props.size)])
예제 #14
0
def run(argv):
    parser = OptionParser(
        dedent("""\
        %prog install [options] PACKAGE-FILE

        This is a low-level tool; to install a package as an ordinary user
        you should generally use "pkcon install-local PACKAGE-FILE"
        instead."""))
    parser.add_option("--root",
                      metavar="PATH",
                      help="install packages underneath PATH")
    parser.add_option("--force-missing-framework",
                      action="store_true",
                      default=False,
                      help="install despite missing system framework")
    parser.add_option("--user",
                      metavar="USER",
                      help="register package for USER")
    parser.add_option("--all-users",
                      default=False,
                      action="store_true",
                      help="register package for all users")
    parser.add_option("--allow-unauthenticated",
                      default=False,
                      action="store_true",
                      help="allow installing packages with no signatures")
    parser.add_option("--verbose",
                      default=False,
                      action="store_true",
                      help="be more verbose on install")
    options, args = parser.parse_args(argv)
    if len(args) < 1:
        parser.error("need package file name")
    db = Click.DB()
    db.read(db_dir=None)
    if options.root is not None:
        db.add(options.root)
    package_path = args[0]
    installer = ClickInstaller(
        db=db,
        force_missing_framework=options.force_missing_framework,
        allow_unauthenticated=options.allow_unauthenticated)
    try:
        installer.install(package_path,
                          user=options.user,
                          all_users=options.all_users,
                          quiet=not options.verbose)
    except ClickInstallerError as e:
        print("Cannot install %s: %s" % (package_path, e), file=sys.stderr)
        return 1
    return 0
예제 #15
0
 def test_manifests_all(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.assertEqual([],
                      json_array_to_python(
                          db.get_manifests(all_versions=True)))
     self.assertEqual([],
                      json.loads(
                          db.get_manifests_as_string(all_versions=True)))
     a_pkg1_manifest_path = os.path.join(self.temp_dir, "a", "pkg1", "1.0",
                                         ".click", "info", "pkg1.manifest")
     a_pkg1_manifest_obj = {"name": "pkg1", "version": "1.0"}
     with mkfile(a_pkg1_manifest_path) as a_pkg1_manifest:
         json.dump(a_pkg1_manifest_obj, a_pkg1_manifest)
     os.symlink("1.0", os.path.join(self.temp_dir, "a", "pkg1", "current"))
     b_pkg1_manifest_path = os.path.join(self.temp_dir, "b", "pkg1", "1.1",
                                         ".click", "info", "pkg1.manifest")
     b_pkg1_manifest_obj = {"name": "pkg1", "version": "1.1"}
     with mkfile(b_pkg1_manifest_path) as b_pkg1_manifest:
         json.dump(b_pkg1_manifest_obj, b_pkg1_manifest)
     os.symlink("1.1", os.path.join(self.temp_dir, "b", "pkg1", "current"))
     b_pkg2_manifest_path = os.path.join(self.temp_dir, "b", "pkg2", "0.1",
                                         ".click", "info", "pkg2.manifest")
     b_pkg2_manifest_obj = {"name": "pkg2", "version": "0.1"}
     with mkfile(b_pkg2_manifest_path) as b_pkg2_manifest:
         json.dump(b_pkg2_manifest_obj, b_pkg2_manifest)
     os.symlink("0.1", os.path.join(self.temp_dir, "b", "pkg2", "current"))
     a_pkg1_manifest_obj["_directory"] = os.path.join(
         self.temp_dir, "a", "pkg1", "1.0")
     a_pkg1_manifest_obj["_removable"] = 0
     b_pkg1_manifest_obj["_directory"] = os.path.join(
         self.temp_dir, "b", "pkg1", "1.1")
     b_pkg1_manifest_obj["_removable"] = 1
     b_pkg2_manifest_obj["_directory"] = os.path.join(
         self.temp_dir, "b", "pkg2", "0.1")
     b_pkg2_manifest_obj["_removable"] = 1
     self.assertEqual(
         [b_pkg1_manifest_obj, b_pkg2_manifest_obj, a_pkg1_manifest_obj],
         json_array_to_python(db.get_manifests(all_versions=True)))
     self.assertEqual(
         [b_pkg1_manifest_obj, b_pkg2_manifest_obj, a_pkg1_manifest_obj],
         json.loads(db.get_manifests_as_string(all_versions=True)))
예제 #16
0
 def test_reinstall_preinstalled(self):
     # Attempting to reinstall a preinstalled version shouldn't actually
     # reinstall it in an overlay database (which would cause
     # irreconcilable confusion about the correct target for system hook
     # symlinks), but should instead simply update the user registration.
     path = self.make_fake_package(
         control_fields={
             "Package": "test-package",
             "Version": "1.1",
             "Architecture": "all",
             "Maintainer": "Foo Bar <*****@*****.**>",
             "Description": "test",
             "Click-Version": "0.4",
         },
         manifest={
             "name": "test-package",
             "version": "1.1",
             "framework": "ubuntu-sdk-13.10",
         },
         control_scripts={"preinst": static_preinst})
     underlay = os.path.join(self.temp_dir, "underlay")
     overlay = os.path.join(self.temp_dir, "overlay")
     db = Click.DB()
     db.add(underlay)
     installer = ClickInstaller(db, True)
     with mock_quiet_subprocess_call():
         installer.install(path, all_users=True)
     underlay_unpacked = os.path.join(underlay, "test-package", "1.1")
     self.assertTrue(os.path.exists(underlay_unpacked))
     all_link = os.path.join(underlay, ".click", "users", "@all",
                             "test-package")
     self.assertTrue(os.path.islink(all_link))
     self.assertEqual(underlay_unpacked, os.readlink(all_link))
     db.add(overlay)
     registry = Click.User.for_user(db, "test-user")
     registry.remove("test-package")
     user_link = os.path.join(overlay, ".click", "users", "test-user",
                              "test-package")
     self.assertTrue(os.path.islink(user_link))
     self.assertEqual("@hidden", os.readlink(user_link))
     installer = ClickInstaller(db, True)
     with mock_quiet_subprocess_call():
         installer.install(path, user="******")
     overlay_unpacked = os.path.join(overlay, "test-package", "1.1")
     self.assertFalse(os.path.exists(overlay_unpacked))
     self.assertEqual("1.1", registry.get_version("test-package"))
예제 #17
0
 def test_has_package_version(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.assertFalse(db.has_package_version("pkg", "1.0"))
     os.makedirs(os.path.join(self.temp_dir, "a", "pkg", "1.0"))
     self.assertTrue(db.has_package_version("pkg", "1.0"))
     self.assertFalse(db.has_package_version("pkg", "1.1"))
     os.makedirs(os.path.join(self.temp_dir, "b", "pkg", "1.0"))
     self.assertTrue(db.has_package_version("pkg", "1.0"))
     os.makedirs(os.path.join(self.temp_dir, "b", "pkg", "1.1"))
     self.assertTrue(db.has_package_version("pkg", "1.1"))
예제 #18
0
    def setUp(self):
        super(StopAppTestCase, self).setUp()
        self.use_temp_dir()
        self.db = Click.DB()
        self.db.add(self.temp_dir)

        # setup fake app_stop
        fake_app_stop = os.path.join(self.temp_dir, "bin", "ubuntu-app-stop")
        self.fake_app_stop_output = os.path.join(self.temp_dir,
                                                 "fake-app-stop.out")
        fake_app_stop_content = dedent("""\
        #!/bin/sh
        echo "$@" >> %s
        """ % self.fake_app_stop_output)
        make_file_with_content(fake_app_stop, fake_app_stop_content, 0o755)
        # its ok to modify env here, click.helpers.TestCase will take care
        # of it
        os.environ["PATH"] = "%s:%s" % (os.path.dirname(fake_app_stop),
                                        os.environ["PATH"])
예제 #19
0
 def test_world_readable(self, mock_package_install_hooks):
     with self.run_in_subprocess("click_get_frameworks_dir") as (enter,
                                                                 preloads):
         enter()
         owner_only_file = os.path.join(self.temp_dir, "owner-only-file")
         touch(owner_only_file)
         os.chmod(owner_only_file, stat.S_IRUSR | stat.S_IWUSR)
         owner_only_dir = os.path.join(self.temp_dir, "owner-only-dir")
         os.mkdir(owner_only_dir, stat.S_IRWXU)
         path = self.make_fake_package(
             control_fields={
                 "Package": "test-package",
                 "Version": "1.1",
                 "Architecture": "all",
                 "Maintainer": "Foo Bar <*****@*****.**>",
                 "Description": "test",
                 "Click-Version": "0.2",
             },
             manifest={
                 "name": "test-package",
                 "version": "1.1",
                 "framework": "ubuntu-sdk-13.10",
             },
             control_scripts={"preinst": static_preinst},
             data_files={
                 "world-readable-file": owner_only_file,
                 "world-readable-dir": owner_only_dir,
             })
         root = os.path.join(self.temp_dir, "root")
         db = Click.DB()
         db.add(root)
         installer = ClickInstaller(db)
         self._setup_frameworks(preloads, frameworks=["ubuntu-sdk-13.10"])
         with mock_quiet_subprocess_call():
             installer.install(path)
         inst_dir = os.path.join(root, "test-package", "current")
         self.assertEqual(
             stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH,
             self._get_mode(os.path.join(inst_dir, "world-readable-file")))
         self.assertEqual(
             stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH
             | stat.S_IXOTH,
             self._get_mode(os.path.join(inst_dir, "world-readable-dir")))
예제 #20
0
def run(argv):
    parser = OptionParser("%prog unregister [options] PACKAGE-NAME [VERSION]")
    parser.add_option("--root",
                      metavar="PATH",
                      help="look for additional packages in PATH")
    parser.add_option(
        "--user",
        metavar="USER",
        help="unregister package for USER (default: $SUDO_USER, if known)")
    parser.add_option(
        "--all-users",
        default=False,
        action="store_true",
        help="unregister package that was previously registered for all users")
    options, args = parser.parse_args(argv)
    if len(args) < 1:
        parser.error("need package name")
    if os.geteuid() != 0:
        parser.error(
            "click unregister must be started as root, since it may need to "
            "remove packages from disk")
    if options.user is None and "SUDO_USER" in os.environ:
        options.user = os.environ["SUDO_USER"]
    db = Click.DB()
    db.read(db_dir=None)
    if options.root is not None:
        db.add(options.root)
    package = args[0]
    if options.all_users:
        registry = Click.User.for_all_users(db)
    else:
        registry = Click.User.for_user(db, name=options.user)
    old_version = registry.get_version(package)
    if len(args) >= 2 and old_version != args[1]:
        print("Not removing %s %s; expected version %s" %
              (package, old_version, args[1]),
              file=sys.stderr)
        sys.exit(1)
    registry.remove(package)
    db.maybe_remove(package, old_version)
    # TODO: remove data
    return 0
예제 #21
0
 def test_remove_multiple_root_creates_overlay_directory(self):
     multi_db = Click.DB()
     multi_db.add(os.path.join(self.temp_dir, "preinstalled"))
     multi_db.add(os.path.join(self.temp_dir, "click"))
     user_dbs = [
         os.path.join(
             multi_db.get(i).props.root, ".click", "users", "user")
         for i in range(multi_db.props.size)
     ]
     a_1_0 = os.path.join(self.temp_dir, "preinstalled", "a", "1.0")
     os.makedirs(a_1_0)
     os.makedirs(user_dbs[0])
     os.symlink(a_1_0, os.path.join(user_dbs[0], "a"))
     self.assertFalse(os.path.exists(user_dbs[1]))
     registry = Click.User.for_user(multi_db, "user")
     self.assertEqual("1.0", registry.get_version("a"))
     registry.remove("a")
     self.assertFalse(registry.has_package_name("a"))
     self.assertEqual("@hidden", os.readlink(os.path.join(user_dbs[1],
                                                          "a")))
예제 #22
0
 def test_manifest_bad(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)
     db = Click.DB()
     db.read(db_dir=self.temp_dir)
     manifest_path = os.path.join(self.temp_dir, "a", "pkg", "1.0",
                                  ".click", "info", "pkg.manifest")
     with mkfile(manifest_path) as manifest:
         print("{bad syntax", file=manifest)
     self.assertRaisesDatabaseError(Click.DatabaseError.BAD_MANIFEST,
                                    db.get_manifest, "pkg", "1.0")
     self.assertRaisesDatabaseError(Click.DatabaseError.BAD_MANIFEST,
                                    db.get_manifest_as_string, "pkg", "1.0")
     manifest_path = os.path.join(self.temp_dir, "a", "pkg", "1.1",
                                  ".click", "info", "pkg.manifest")
     with mkfile(manifest_path) as manifest:
         print("[0]", file=manifest)
     self.assertRaisesDatabaseError(Click.DatabaseError.BAD_MANIFEST,
                                    db.get_manifest, "pkg", "1.0")
     self.assertRaisesDatabaseError(Click.DatabaseError.BAD_MANIFEST,
                                    db.get_manifest_as_string, "pkg", "1.0")
예제 #23
0
 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")))
예제 #24
0
    def test_sandbox(self):
        with self.run_in_subprocess("click_get_frameworks_dir") as (enter,
                                                                    preloads):
            enter()
            original_call = subprocess.check_output

            def call_side_effect(*args, **kwargs):
                return original_call(
                    ["touch", os.path.join(self.temp_dir, "sentinel")],
                    **kwargs)

            path = self.make_fake_package(
                control_fields={
                    "Package": "test-package",
                    "Version": "1.0",
                    "Architecture": "all",
                    "Maintainer": "Foo Bar <*****@*****.**>",
                    "Description": "test",
                    "Click-Version": "0.2",
                },
                manifest={
                    "name": "test-package",
                    "version": "1.0",
                    "framework": "ubuntu-sdk-13.10",
                },
                control_scripts={"preinst": static_preinst},
                data_files={"foo": None})
            root = os.path.join(self.temp_dir, "root")
            db = Click.DB()
            db.add(root)
            installer = ClickInstaller(db)
            self._setup_frameworks(preloads, frameworks=["ubuntu-sdk-13.10"])
            with mock.patch("subprocess.check_output") as mock_call:
                mock_call.side_effect = call_side_effect
                self.assertRaises(subprocess.CalledProcessError,
                                  installer.install, path)
            self.assertFalse(
                os.path.exists(os.path.join(self.temp_dir, "sentinel")))
예제 #25
0
 def _setUpMultiDB(self):
     self.multi_db = Click.DB()
     self.multi_db.add(os.path.join(self.temp_dir, "custom"))
     self.multi_db.add(os.path.join(self.temp_dir, "click"))
     user_dbs = [
         os.path.join(
             self.multi_db.get(i).props.root, ".click", "users", "user")
         for i in range(self.multi_db.props.size)
     ]
     a_1_0 = os.path.join(self.temp_dir, "custom", "a", "1.0")
     os.makedirs(a_1_0)
     with mkfile(os.path.join(a_1_0, ".click", "info", "a.manifest")) as m:
         json.dump({
             "name": "a",
             "version": "1.0",
             "hooks": {
                 "a-app": {}
             }
         }, m)
     b_2_0 = os.path.join(self.temp_dir, "custom", "b", "2.0")
     os.makedirs(b_2_0)
     with mkfile(os.path.join(b_2_0, ".click", "info", "b.manifest")) as m:
         json.dump({"name": "b", "version": "2.0"}, m)
     a_1_1 = os.path.join(self.temp_dir, "click", "a", "1.1")
     os.makedirs(a_1_1)
     with mkfile(os.path.join(a_1_1, ".click", "info", "a.manifest")) as m:
         json.dump({"name": "a", "version": "1.1"}, m)
     c_0_1 = os.path.join(self.temp_dir, "click", "c", "0.1")
     os.makedirs(c_0_1)
     with mkfile(os.path.join(c_0_1, ".click", "info", "c.manifest")) as m:
         json.dump({"name": "c", "version": "0.1"}, m)
     os.makedirs(user_dbs[0])
     os.symlink(a_1_0, os.path.join(user_dbs[0], "a"))
     os.symlink(b_2_0, os.path.join(user_dbs[0], "b"))
     os.makedirs(user_dbs[1])
     os.symlink(a_1_1, os.path.join(user_dbs[1], "a"))
     os.symlink(c_0_1, os.path.join(user_dbs[1], "c"))
     return user_dbs, Click.User.for_user(self.multi_db, "user")
예제 #26
0
 def test_path(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_path, "pkg", "1.0")
     os.makedirs(os.path.join(self.temp_dir, "a", "pkg", "1.0"))
     self.assertEqual(os.path.join(self.temp_dir, "a", "pkg", "1.0"),
                      db.get_path("pkg", "1.0"))
     self.assertRaisesDatabaseError(Click.DatabaseError.DOES_NOT_EXIST,
                                    db.get_path, "pkg", "1.1")
     os.makedirs(os.path.join(self.temp_dir, "b", "pkg", "1.0"))
     # The deepest copy of the same package/version is still preferred.
     self.assertEqual(os.path.join(self.temp_dir, "a", "pkg", "1.0"),
                      db.get_path("pkg", "1.0"))
     os.makedirs(os.path.join(self.temp_dir, "b", "pkg", "1.1"))
     self.assertEqual(os.path.join(self.temp_dir, "b", "pkg", "1.1"),
                      db.get_path("pkg", "1.1"))
예제 #27
0
def _get_click_dir_variable():
    '''Format click databases as variable'''
    import gi
    gi.require_version('Click', '0.4')
    from gi.repository import Click

    global click_databases
    if click_databases is None:
        db = Click.DB()
        db.read()
        click_databases = sorted(
            [db.get(i).props.root for i in range(db.props.size)])

    d = ""
    if len(click_databases) < 1:  # pragma: no cover
        raise AppArmorExceptionClickDatabaseNotFound(
            "Could not find any click databases")
    elif len(click_databases) == 1:  # pragma: no cover
        d = click_databases[0]
    else:
        d = "{%s}" % ",".join(click_databases)

    return d
예제 #28
0
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)
예제 #29
0
 def test_add(self):
     db = Click.DB()
     self.assertEqual(0, db.props.size)
     db.add("/new/root")
     self.assertEqual(1, db.props.size)
     self.assertEqual("/new/root", db.get(0).props.root)
예제 #30
0
 def test_read_not_directory(self):
     path = os.path.join(self.temp_dir, "file")
     touch(path)
     db = Click.DB()
     self.assertRaisesFileError(GLib.FileError.NOTDIR, db.read, db_dir=path)