Exemple #1
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
Exemple #2
0
 def test_find_package_directory(self):
     info = os.path.join(self.temp_dir, ".click", "info")
     path = os.path.join(self.temp_dir, "file")
     Click.ensuredir(info)
     touch(path)
     pkgdir = Click.find_package_directory(path)
     self.assertEqual(self.temp_dir, pkgdir)
def read_hooks_for(path, package, app_name):
    try:
        directory = Click.find_package_directory(path)
        manifest_path = os.path.join(directory, ".click", "info",
                                     "%s.manifest" % package)
        with io.open(manifest_path, encoding="UTF-8") as manifest:
            return json.load(manifest).get("hooks", {}).get(app_name, {})
    except Exception:
        return {}
def write_desktop_file(target_path, source_path, profile):
    Click.ensuredir(os.path.dirname(target_path))
    with io.open(source_path, encoding="UTF-8") as source, \
         io.open(target_path, "w", encoding="UTF-8") as target:
        source_dir = Click.find_package_directory(source_path)
        written_comment = False
        seen_path = False
        for line in source:
            if not line.rstrip("\n") or line.startswith("#"):
                # Comment
                target.write(line)
            elif line.startswith("["):
                # Group header
                target.write(line)
                if not written_comment:
                    print(COMMENT, file=target)
            elif "=" not in line:
                # Who knows?
                target.write(line)
            else:
                key, value = line.split("=", 1)
                key = key.strip()
                value = value.strip()
                if key == "Exec":
                    target.write("%s=aa-exec-click -p %s -- %s\n" %
                                 (key, quote_for_desktop_exec(profile), value))
                elif key == "Path":
                    target.write("%s=%s\n" % (key, source_dir))
                    seen_path = True
                elif key == "Icon":
                    icon_path = os.path.join(source_dir, value)
                    if os.path.exists(icon_path):
                        target.write("%s=%s\n" % (key, icon_path))
                    else:
                        target.write("%s=%s\n" % (key, value))
                else:
                    target.write("%s=%s\n" % (key, value))
        if not seen_path:
            target.write("Path=%s\n" % source_dir)
Exemple #5
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)