Ejemplo n.º 1
0
def parse_options(rawargs):
    parser = config.make_parser(prog="pycman-sync")
    # Misc actions
    group0 = parser.add_argument_group("Actions (default is installing specified packages)")
    group0.add_argument(
        "-c", "--clean", action="count", default=0, help="remove old packages from cache directory (-cc for all)"
    )
    group0.add_argument(
        "-u", "--sysupgrade", action="count", default=0, help="upgrade installed packages (-uu allows downgrade)"
    )
    group0.add_argument(
        "-y", "--refresh", action="count", default=0, help="download fresh package databases from the server"
    )
    # Installation options
    grp_install = parser.add_argument_group("Install options")
    grp_install.add_argument("-d", "--nodeps", action="store_true", default=False, help="skip dependency checks")
    grp_install.add_argument(
        "-f", "--force", action="store_true", default=False, help="force install, overwrite conflicting files"
    )
    grp_install.add_argument(
        "-k", "--dbonly", action="store_true", default=False, help="only modify database entries, not package files"
    )
    grp_install.add_argument(
        "-w",
        "--downloadonly",
        action="store_true",
        default=False,
        help="download packages but do not install/upgrade anything",
    )
    grp_install.add_argument("--asdeps", dest="mode", action="store_const", const=pyalpm.PKG_REASON_DEPEND)
    grp_install.add_argument("--asexplicit", dest="mode", action="store_const", const=pyalpm.PKG_REASON_EXPLICIT)
    # Options to query sync databases
    group1 = parser.add_argument_group("Query actions")
    group1.add_argument(
        "-g",
        "--groups",
        action="store_true",
        default=False,
        help="view list of groups, or all members of a package group",
    )
    group1.add_argument("-i", "--info", action="count", dest="info", default=0, help="view package information")
    group1.add_argument("-l", "--list", action="store_true", default=False, help="list the contents of repositories")
    group1.add_argument(
        "-s", "--search", action="store_true", default=False, help="search remote repositories for matching strings"
    )
    group1.add_argument(
        "-q",
        "--quiet",
        action="store_true",
        dest="quiet",
        default=False,
        help="show less information for query and search",
    )
    group1.add_argument(
        "args",
        metavar="arg",
        nargs="*",
        help="arguments (group names for -g, repo names for -l, " "package names for -i)",
    )
    return parser.parse_args(rawargs)
Ejemplo n.º 2
0
def main(rawargs):
	global handle
	parser = config.make_parser()
	group = parser.add_argument_group("upgrade options")
	group.add_argument('-d', '--nodeps',
			action='store_true', default=False,
			help='skip dependency checks')
	group.add_argument('-f', '--force',
			action='store_true', default=False,
			help='force install, overwrite conflicting files')
	group.add_argument('-k', '--dbonly',
			action='store_true', default=False,
			help='only modify database entries, not package files')
	group.add_argument('--asdeps', dest='mode',
			action="store_const",
			const=pyalpm.PKG_REASON_DEPEND)
	group.add_argument('--asexplicit', dest='mode',
			action="store_const",
			const=pyalpm.PKG_REASON_EXPLICIT)
	group.add_argument('pkgs', metavar='pkg', nargs='*',
			help="a list of package URLs, e.g. package-1.0-1-x86_64.tar.xz")

	args = parser.parse_args(rawargs)
	handle = config.init_with_config_and_options(args)

	if args.verbose:
		print("upgrade " + " ".join(rawargs), file=sys.stderr)

	return upgrade(args.pkgs, args)
Ejemplo n.º 3
0
def main(rawargs):
	global handle
	parser = config.make_parser()
	group = parser.add_argument_group("upgrade options")
	group.add_argument('-d', '--nodeps',
			action = 'store_true', default = False,
			help = 'skip dependency checks')
	group.add_argument('-f', '--force',
			action = 'store_true', default = False,
			help = 'force install, overwrite conflicting files')
	group.add_argument('-k', '--dbonly',
			action = 'store_true', default = False,
			help = 'only modify database entries, not package files')
	group.add_argument('--asdeps', dest = 'mode',
			action = "store_const",
			const = pyalpm.PKG_REASON_DEPEND)
	group.add_argument('--asexplicit', dest = 'mode',
			action = "store_const",
			const = pyalpm.PKG_REASON_EXPLICIT)
	group.add_argument('pkgs', metavar = 'pkg', nargs='*',
			help = "a list of package URLs, e.g. package-1.0-1-i686.tar.xz")

	args = parser.parse_args(rawargs)
	handle = config.init_with_config_and_options(args)

	if args.verbose:
		print("upgrade " + " ".join(rawargs), file = sys.stderr)

	return upgrade(args.pkgs, args)
Ejemplo n.º 4
0
def main(rawargs):
    global handle
    parser = config.make_parser()
    group = parser.add_argument_group("Remove options")
    group.add_argument(
        '-c',
        '--cascade',
        action='store_true',
        default=False,
        help='remove packages and all packages that depend on them')
    group.add_argument('-d',
                       '--nodeps',
                       action='store_true',
                       default=False,
                       help='skip dependency checks')
    group.add_argument('-k',
                       '--dbonly',
                       action='store_true',
                       default=False,
                       help='only modify database entries, not package files')
    group.add_argument('-n',
                       '--nosave',
                       action='store_true',
                       default=False,
                       help='remove configuration files as well')
    group.add_argument(
        '-s',
        '--recursive',
        action='store_true',
        default=False,
        help="remove dependencies also (that won't break packages)")
    group.add_argument(
        '-u',
        '--unneeded',
        action='store_true',
        default=False,
        help="remove unneeded packages (that won't break packages)")
    group.add_argument('pkgs',
                       metavar='pkg',
                       nargs='*',
                       help="a list of packages, e.g. libreoffice, openjdk6")

    args = parser.parse_args(rawargs)
    handle = config.init_with_config_and_options(args)

    if args.verbose:
        print("remove " + " ".join(rawargs), file=sys.stderr)

    if len(args.pkgs) == 0:
        print('error: no targets specified')
        return 1

    return remove(args.pkgs, args)
Ejemplo n.º 5
0
def main():
  parser = config.make_parser(description='Backs-up the list of pacman-installed packages on the system.', 
    prog = 'pacbackup')

  group = parser.add_argument_group("Backup options")
  group.add_argument('--backup-config', metavar='<path>', default='~/.pacbackup/pkglist', 
    help = "specifies the backup file location, default : ~/.pacbackup/pkglist")

  backup = PacBackup(parser.parse_args())
  print("Retriving current package list")
  backup.retrieve_pkg_lists()
  print("Backing package list up")
  backup.backup_pkg_lists()
  print("Committing the backup to the local git tree")
  backup.add_to_git()
Ejemplo n.º 6
0
def main(rawargs):
	global handle
	parser = config.make_parser()
	parser.add_argument('deps', metavar = 'dep', nargs='*',
			help = "a dependency string, e.g. 'pacman>=3.4.0'")
	args = parser.parse_args(rawargs)
	handle = config.init_with_config_and_options(args)

	if args.verbose:
		print("deptest " + " ".join(rawargs), file = sys.stderr)
	missing = deptest(args.deps)

	if len(missing) == 0:
		return 0
	else:
		[print(dep) for dep in missing]
		return 127
Ejemplo n.º 7
0
def main(rawargs):
    global handle
    parser = config.make_parser()
    parser.add_argument('deps',
                        metavar='dep',
                        nargs='*',
                        help="a dependency string, e.g. 'pacman>=3.4.0'")
    args = parser.parse_args(rawargs)
    handle = config.init_with_config_and_options(args)

    if args.verbose:
        print("deptest " + " ".join(rawargs), file=sys.stderr)
    missing = deptest(args.deps)

    if len(missing) == 0:
        return 0
    else:
        [print(dep) for dep in missing]
        return 127
Ejemplo n.º 8
0
def main(rawargs):
	global handle
	parser = config.make_parser()
	mode = parser.add_mutually_exclusive_group(required = True)
	mode.add_argument('--asdeps', dest = 'mode',
			action = "store_const",
			const = pyalpm.PKG_REASON_DEPEND)
	mode.add_argument('--asexplicit', dest = 'mode',
			action = "store_const",
			const = pyalpm.PKG_REASON_EXPLICIT)
	parser.add_argument('pkgs', metavar = 'pkg', nargs='*',
			help = "a dependency string, e.g. 'pacman>=3.4.0'")
	args = parser.parse_args(rawargs)
	handle = config.init_with_config_and_options(args)

	if args.verbose:
		print("database " + " ".join(rawargs), file = sys.stderr)

	commit(args.pkgs, args.mode)
	return 0
Ejemplo n.º 9
0
def main():
    parser = config.make_parser(
        description=
        'Backs-up the list of pacman-installed packages on the system.',
        prog='pacbackup')

    group = parser.add_argument_group("Backup options")
    group.add_argument(
        '--backup-config',
        metavar='<path>',
        default='~/.pacbackup/pkglist',
        help=
        "specifies the backup file location, default : ~/.pacbackup/pkglist")

    backup = PacBackup(parser.parse_args())
    print("Retriving current package list")
    backup.retrieve_pkg_lists()
    print("Backing package list up")
    backup.backup_pkg_lists()
    print("Committing the backup to the local git tree")
    backup.add_to_git()
Ejemplo n.º 10
0
def main(rawargs):
	global handle
	parser = config.make_parser()
	group = parser.add_argument_group("Remove options")
	group.add_argument('-c', '--cascade',
			action = 'store_true', default = False,
			help = 'remove packages and all packages that depend on them')
	group.add_argument('-d', '--nodeps',
			action = 'store_true', default = False,
			help = 'skip dependency checks')
	group.add_argument('-k', '--dbonly',
			action = 'store_true', default = False,
			help = 'only modify database entries, not package files')
	group.add_argument('-n', '--nosave',
			action = 'store_true', default = False,
			help = 'remove configuration files as well')
	group.add_argument('-s', '--recursive',
			action = 'store_true', default = False,
			help = "remove dependencies also (that won't break packages)")
	group.add_argument('-u', '--unneeded',
			action = 'store_true', default = False,
			help = "remove unneeded packages (that won't break packages)")
	group.add_argument('pkgs', metavar = 'pkg', nargs='*',
			help = "a list of packages, e.g. libreoffice, openjdk6")

	args = parser.parse_args(rawargs)
	handle = config.init_with_config_and_options(args)

	if args.verbose:
		print("remove " + " ".join(rawargs), file = sys.stderr)

	if len(args.pkgs) == 0:
		print('error: no targets specified')
		return 1

	return remove(args.pkgs, args)
Ejemplo n.º 11
0
def main(rawargs):
    global handle
    parser = config.make_parser(prog='pycman-query')
    group = parser.add_argument_group("Query options")
    group.add_argument('-d',
                       '--deps',
                       action='store_true',
                       default=False,
                       help='list packages installed as dependencies [filter]')
    group.add_argument('-e',
                       '--explicit',
                       action='store_true',
                       default=False,
                       help='list packages explicitly installed [filter]')
    group.add_argument('-i',
                       '--info',
                       action='count',
                       dest='info',
                       default=0,
                       help='view package information')
    group.add_argument('-l',
                       '--list',
                       action='store_true',
                       dest='listfiles',
                       default=False,
                       help='list the contents of the queried package')
    group.add_argument(
        '-m',
        '--foreign',
        action='store_true',
        default=False,
        help='list installed packages not found in sync db(s) [filter]')
    group.add_argument('-o',
                       '--owns',
                       action='store_true',
                       default=False,
                       help='query the package that owns <file>')
    group.add_argument('-p',
                       '--package',
                       action='store_true',
                       default=False,
                       help='query a package file instead of the database')
    group.add_argument('-q',
                       '--quiet',
                       action='store_true',
                       dest='quiet',
                       default=False,
                       help='show less information for query and search')
    group.add_argument(
        '-s',
        '--search',
        action='store_true',
        default=False,
        help='search locally-installed packages for matching strings')
    group.add_argument(
        '-t',
        '--unrequired',
        action='store_true',
        default=False,
        help="list packages not required by any package [filter]")
    group.add_argument('-u',
                       '--upgrades',
                       action='store_true',
                       default=False,
                       help="list outdated packages [filter]")
    group.add_argument(
        'pkgnames',
        metavar='pkg',
        nargs='*',
        help='packages to show (show all packages if no arguments) '
        '(when used with -o: a filename, '
        'when used with -p: the path to a package file)')

    args = parser.parse_args(rawargs)
    handle = config.init_with_config_and_options(args)

    if args.verbose:
        print("query " + " ".join(rawargs), file=sys.stderr)

    db = handle.get_localdb()
    retcode = 0

    # actions other than listing packages
    if args.owns:
        return find_file(args.pkgnames, args)
    if args.search:
        return find_search(args.pkgnames, args)

    pkglist = []
    if len(args.pkgnames) > 0:
        # a list of package names was specified
        for pkgname in args.pkgnames:
            if args.package:
                pkg = handle.load_pkg(pkgname)
            else:
                pkg = db.get_pkg(pkgname)
            if pkg is None:
                print('error: package "%s" not found' % pkgname)
                retcode = 1
            else:
                pkglist.append(pkg)
    else:
        # no package was specified, display all
        pkglist = db.pkgcache
    # determine the list of package to actually display
    pkglist = filter_pkglist(pkglist, args)
    for pkg in pkglist:
        display_pkg(pkg, args)

    return retcode
Ejemplo n.º 12
0
def main(rawargs):
	global handle
	parser = config.make_parser(prog = 'pycman-query')
	group = parser.add_argument_group("Query options")
	group.add_argument('-d', '--deps',
			action = 'store_true', default = False,
			help = 'list packages installed as dependencies [filter]')
	group.add_argument('-e', '--explicit',
			action = 'store_true', default = False,
			help = 'list packages explicitly installed [filter]')
	group.add_argument('-i', '--info',
			action = 'count', dest = 'info', default = 0,
			help = 'view package information')
	group.add_argument('-l', '--list',
			action = 'store_true', dest = 'listfiles', default = False,
			help = 'list the contents of the queried package')
	group.add_argument('-m', '--foreign',
			action = 'store_true', default = False,
			help = 'list installed packages not found in sync db(s) [filter]')
	group.add_argument('-o', '--owns',
			action = 'store_true', default = False,
			help = 'query the package that owns <file>')
	group.add_argument('-p', '--package',
			action = 'store_true', default = False,
			help = 'query a package file instead of the database')
	group.add_argument('-q', '--quiet',
			action = 'store_true', dest = 'quiet', default = False,
			help = 'show less information for query and search')
	group.add_argument('-s', '--search', action = 'store_true', default = False,
			help = 'search locally-installed packages for matching strings')
	group.add_argument('-t', '--unrequired',
			action = 'store_true', default = False,
			help = "list packages not required by any package [filter]")
	group.add_argument('-u', '--upgrades',
			action = 'store_true', default = False,
			help = "list outdated packages [filter]")
	group.add_argument('pkgnames', metavar = 'pkg', nargs = '*',
			help = 'packages to show (show all packages if no arguments) '
			'(when used with -o: a filename, '
			'when used with -p: the path to a package file)')

	args = parser.parse_args(rawargs)
	handle = config.init_with_config_and_options(args)

	if args.verbose:
		print("query " + " ".join(rawargs), file = sys.stderr)

	db = handle.get_localdb()
	retcode = 0

	# actions other than listing packages
	if args.owns:
		return find_file(args.pkgnames, args)
	if args.search:
		return find_search(args.pkgnames, args)

	pkglist = []
	if len(args.pkgnames) > 0:
		# a list of package names was specified
		for pkgname in args.pkgnames:
			if args.package:
				pkg = handle.load_pkg(pkgname)
			else:
				pkg = db.get_pkg(pkgname)
			if pkg is None:
				print('error: package "%s" not found' % pkgname)
				retcode = 1
			else:
				pkglist.append(pkg)
	else:
		# no package was specified, display all
		pkglist = db.pkgcache
	# determine the list of package to actually display
	pkglist = filter_pkglist(pkglist, args)
	for pkg in pkglist:
		display_pkg(pkg, args)

	return retcode
Ejemplo n.º 13
0
def parse_options(rawargs):
    parser = config.make_parser(prog='pycman-sync')
    # Misc actions
    group0 = parser.add_argument_group(
        "Actions (default is installing specified packages)")
    group0.add_argument(
        "-c",
        "--clean",
        action='count',
        default=0,
        help='remove old packages from cache directory (-cc for all)')
    group0.add_argument(
        "-u",
        "--sysupgrade",
        action='count',
        default=0,
        help='upgrade installed packages (-uu allows downgrade)')
    group0.add_argument(
        "-y",
        "--refresh",
        action='count',
        default=0,
        help='download fresh package databases from the server')
    # Installation options
    grp_install = parser.add_argument_group("Install options")
    grp_install.add_argument('-d',
                             '--nodeps',
                             action='store_true',
                             default=False,
                             help='skip dependency checks')
    grp_install.add_argument('-f',
                             '--force',
                             action='store_true',
                             default=False,
                             help='force install, overwrite conflicting files')
    grp_install.add_argument(
        '-k',
        '--dbonly',
        action='store_true',
        default=False,
        help='only modify database entries, not package files')
    grp_install.add_argument(
        '-w',
        '--downloadonly',
        action='store_true',
        default=False,
        help='download packages but do not install/upgrade anything')
    grp_install.add_argument('--asdeps',
                             dest='mode',
                             action="store_const",
                             const=pyalpm.PKG_REASON_DEPEND)
    grp_install.add_argument('--asexplicit',
                             dest='mode',
                             action="store_const",
                             const=pyalpm.PKG_REASON_EXPLICIT)
    # Options to query sync databases
    group1 = parser.add_argument_group("Query actions")
    group1.add_argument(
        '-g',
        '--groups',
        action='store_true',
        default=False,
        help='view list of groups, or all members of a package group')
    group1.add_argument('-i',
                        '--info',
                        action='count',
                        dest='info',
                        default=0,
                        help='view package information')
    group1.add_argument('-l',
                        '--list',
                        action='store_true',
                        default=False,
                        help='list the contents of repositories')
    group1.add_argument('-s',
                        '--search',
                        action='store_true',
                        default=False,
                        help='search remote repositories for matching strings')
    group1.add_argument('-q',
                        '--quiet',
                        action='store_true',
                        dest='quiet',
                        default=False,
                        help='show less information for query and search')
    group1.add_argument(
        'args',
        metavar='arg',
        nargs='*',
        help='arguments (group names for -g, repo names for -l, '
        'package names for -i)')
    return parser.parse_args(rawargs)
Ejemplo n.º 14
0
def main(argv):
    global HTML_MIN
    retcode = 0
    parser = config.make_parser(
        prog=__program__,
        description=
        "Generate a static site for browsing an Arch repo, styled like the main website.",
    )
    parser.add_argument(
        "--version",
        action="version",
        version=f"%(prog)s {__version__}",
    )
    group = parser.add_argument_group("Generator options")
    group.add_argument(
        "-d",
        "--pkg-dir",
        metavar="<dir>",
        action="store",
        dest="pkg_dir",
        type=str,
        default=".",
        help="Path to the directory of packages",
    )
    group.add_argument(
        "-o",
        "--output",
        metavar="<dir>",
        action="store",
        dest="output",
        type=str,
        default="build",
        help="Directory to put resulting HTML files",
    )
    group.add_argument(
        "-n",
        "--name",
        metavar="<name>",
        action="store",
        dest="repo_name",
        type=str,
        default="unofficial",
        help="Repository name. Defaults to unofficial",
    )
    group.add_argument(
        "--url",
        metavar="<url>",
        action="store",
        dest="repo_url",
        type=str,
        help="The URL to use in the pacman configuration",
    )
    group.add_argument(
        "--key-id",
        metavar="<ID>",
        action="store",
        dest="key_id",
        type=str,
        help="GPG key ID that has been used to sign this repository",
    )
    group.add_argument(
        "--description",
        metavar="<text>",
        action="store",
        dest="description",
        type=str,
        help="The repository description",
    )
    group.add_argument(
        "--resources",
        metavar="<dir>",
        action="store",
        dest="res_dir",
        type=str,
        default=f"/usr/share/{__program__}",
        help="Where additional resources (templates, CSS) are in the system",
    )
    group.add_argument(
        "--html-min",
        action="store_true",
        help="Minify the generated HTML",
    )
    global args
    args = parser.parse_args(argv)

    # Set up logging
    if args.debug:
        log_level = logging.DEBUG
    elif args.verbose:
        log_level = logging.INFO
    else:
        log_level = logging.WARNING
    if DAIQUIRI_LOGS:
        daiquiri.setup(level=log_level)
    else:
        logging.basicConfig(level=log_level)

    if args.html_min and not HTML_MIN:
        logger.error(
            "Can not minify HTML without the htmlmin library installed!")
        return 1
    HTML_MIN = args.html_min

    handle = config.init_with_config_and_options(args)
    os.makedirs(args.output, mode=0o755, exist_ok=True)

    for db in handle.get_syncdbs():
        if db.name.lower() in official_repos:
            for package in db.pkgcache:
                cached_packages[package.name] = package

    packages = []
    pkg_dir_list = os.listdir(args.pkg_dir)
    pkg_dir_list.sort()
    for filename in pkg_dir_list:
        if ".pkg.tar." in filename and not filename.endswith(".sig"):
            file = os.path.join(args.pkg_dir, filename)
            logger.debug(f"Loading package {file=}")
            sibling_packages.append(handle.load_pkg(file))

    for package in sibling_packages:
        data = pkg_to_dict(package, package.filename)
        packages.append(data)
        output_file = os.path.join(args.output, package_html_path(package))
        package_template(
            data,
            outfile=output_file,
            repo=args.repo_name,
            template_file=os.path.join(args.res_dir, "package.html.j2"),
        )

    te = Template(open(os.path.join(args.res_dir, "index.html.j2")).read())
    index_page = os.path.join(args.output, "index.html")
    logger.info(f"Writing index template to {index_page}")
    with open(index_page, "w") as f:
        html_text = te.render(
            packages=packages,
            repo_name=args.repo_name,
            url=args.repo_url,
            repo_desc=args.description,
            key_id=args.key_id,
        )
        f.write(minify_html(html_text))

    shutil.copyfile(
        os.path.join(args.res_dir, "archrepo.css"),
        os.path.join(args.output, "archrepo.css"),
    )
    return retcode