Compare commits
2 Commits
5dd15d255b
...
master
Author | SHA1 | Date | |
---|---|---|---|
630d099f46 | |||
c8a5507eaa |
14
genv
Executable file
14
genv
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import os
|
||||
from subprocess import call
|
||||
|
||||
ENV_NAME=sys.argv[1]
|
||||
ENV_COMMAND=sys.argv[2:]
|
||||
ENVS_DIR=os.path.join(os.path.expanduser("~"), ".config", "guix", "envs")
|
||||
|
||||
env_packages = []
|
||||
with open(os.path.join(ENVS_DIR, ENV_NAME)) as env_def:
|
||||
env_packages = env_def.read().strip().split(" ")
|
||||
|
||||
call(["guix", "environment", "--ad-hoc"] + env_packages + ["--"] + ENV_COMMAND)
|
64
jackson
Executable file
64
jackson
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
from subprocess import call, check_output
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
ADD_PACKAGE_PREFIX = " + "
|
||||
|
||||
def log (message, *args):
|
||||
print(message.format(*args), file=sys.stderr)
|
||||
|
||||
def get_all_package_generations ():
|
||||
package_generations = {}
|
||||
for line in check_output(["guix", "package", "--list-generations"]).decode().split("\n"):
|
||||
if not line.startswith(ADD_PACKAGE_PREFIX):
|
||||
continue
|
||||
|
||||
(package, version, output, path) = line[len(ADD_PACKAGE_PREFIX):].split("\t")
|
||||
if not package in package_generations:
|
||||
package_generations[package] = []
|
||||
|
||||
package_generations[package].append({
|
||||
"path": path,
|
||||
"version": version,
|
||||
"output": output,
|
||||
"package": package
|
||||
})
|
||||
|
||||
return package_generations
|
||||
|
||||
def run_with_packages (packages, command):
|
||||
env = {}
|
||||
env.update(os.environ)
|
||||
env.update({
|
||||
"PATH": ":".join(["{}/bin".format(package['path']) for package in packages] + [env.get("PATH", "")]),
|
||||
"LD_LIBRARY_PATH": ":".join(["{}/lib".format(package['path']) for package in packages] + [env.get("PATH", "")])
|
||||
})
|
||||
call(args.run, env=env)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--package", help="package name", required=True)
|
||||
parser.add_argument("--version", help="package version")
|
||||
parser.add_argument("--index", help="", type=int, default=0)
|
||||
parser.add_argument("--run", nargs="*", help="run command")
|
||||
args = parser.parse_args()
|
||||
|
||||
all_package_generations = get_all_package_generations()
|
||||
package_generations_for_package = all_package_generations[args.package]
|
||||
package_generations_for_package.reverse()
|
||||
|
||||
log("Found {} generations for package {}", len(package_generations_for_package), args.package)
|
||||
|
||||
if args.version:
|
||||
package_generations_for_package = [generation for generation in package_generations_for_package if generation['version'] == args.version]
|
||||
log("Found {} generations for version {}", len(package_generations_for_package), args.version)
|
||||
|
||||
selected_package = package_generations_for_package[args.index]
|
||||
|
||||
log("Selected package: {}", selected_package)
|
||||
|
||||
if args.run:
|
||||
run_with_packages([selected_package], args.run)
|
||||
else:
|
||||
print(selected_package)
|
Reference in New Issue
Block a user