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")))
 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)
Exemple #3
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
 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"))
 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")))