feat: support adding package to repository
Signed-off-by: sisungo <[email protected]>
This commit is contained in:
@@ -29,3 +29,9 @@ def update():
|
||||
|
||||
def install(requirements: list[str]):
|
||||
subprocess.run([PACKIE_EXEC, "install", "--yes"] + requirements, check=True)
|
||||
|
||||
|
||||
def repo_add(repo: str, pkgfile: str):
|
||||
subprocess.run(
|
||||
[PACKIE_EXEC, "repo-admin", repo, "--add-package", pkgfile], check=True
|
||||
)
|
||||
|
||||
@@ -27,9 +27,13 @@ subparsers = argparser.add_subparsers(dest="subcommand")
|
||||
parser_build = subparsers.add_parser("build")
|
||||
parser_build.add_argument("BUILD_PKGNAME")
|
||||
parser_clean = subparsers.add_parser("clean")
|
||||
parser_clean.add_argument("CLEAN_PKGNAME")
|
||||
parser_clean.add_argument("CLEAN_PKGNAME", nargs="*")
|
||||
parser_clean.add_argument("--all", action="store_true")
|
||||
parser_list = subparsers.add_parser("list")
|
||||
parser_list.add_argument("ITEM", choices=("all", "built", "new"))
|
||||
parser_repo_push = subparsers.add_parser("repo-push")
|
||||
parser_repo_push.add_argument("REPO_DIR")
|
||||
parser_repo_push.add_argument("REPO_PUSH_PKGNAME", nargs="*")
|
||||
args = argparser.parse_args()
|
||||
|
||||
if args.target:
|
||||
@@ -50,7 +54,7 @@ def run_hooks(map, arg: typing.Any = None):
|
||||
os.chdir(current_dir)
|
||||
|
||||
|
||||
def run_build_package(package: str):
|
||||
def cmd_build_package(package: str):
|
||||
try:
|
||||
os.chdir(f"packages/{package}")
|
||||
os.makedirs("target", exist_ok=True)
|
||||
@@ -125,25 +129,26 @@ def run_build_package(package: str):
|
||||
file.write("OK")
|
||||
|
||||
|
||||
def run_clean_package(package: str):
|
||||
try:
|
||||
shutil.rmtree(f"packages/{package}/target")
|
||||
except Exception:
|
||||
pass
|
||||
def cmd_clean_package(package: list[str]):
|
||||
for i in package:
|
||||
try:
|
||||
shutil.rmtree(f"packages/{i}/target")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def run_list(item):
|
||||
def do_list(item: str):
|
||||
if item == "all":
|
||||
for i in os.listdir("packages"):
|
||||
if i.startswith("."):
|
||||
continue
|
||||
print(i)
|
||||
yield i
|
||||
elif item == "built":
|
||||
for i in os.listdir("packages"):
|
||||
if i.startswith("."):
|
||||
continue
|
||||
if os.path.exists(f"packages/{i}/target/build-ok.tag"):
|
||||
print(i)
|
||||
yield i
|
||||
elif item == "new":
|
||||
for i in os.listdir("packages"):
|
||||
if i.startswith("."):
|
||||
@@ -152,12 +157,17 @@ def run_list(item):
|
||||
pkgbuild_mtime = os.path.getmtime(f"packages/{i}/pkgbuild.py")
|
||||
target_mtime = os.path.getmtime(f"packages/{i}/target/build-ok.tag")
|
||||
if target_mtime < pkgbuild_mtime:
|
||||
print(i)
|
||||
yield i
|
||||
except Exception:
|
||||
print(i)
|
||||
yield i
|
||||
|
||||
|
||||
def run_build_atom(pkgname: str):
|
||||
def cmd_list(item):
|
||||
for i in do_list(item):
|
||||
print(i)
|
||||
|
||||
|
||||
def cmd_build_atom(pkgname: str):
|
||||
# Declare necessary paths
|
||||
repo_root = os.getcwd()
|
||||
package_dir = f"{repo_root}/packages/{pkgname}"
|
||||
@@ -194,15 +204,36 @@ def run_build_atom(pkgname: str):
|
||||
pass
|
||||
|
||||
|
||||
def cmd_repo_push(repo_dir: str, pkgname: list[str]):
|
||||
for pkg in pkgname:
|
||||
targetdir = f"packages/{pkg}/target"
|
||||
if not os.path.exists(targetdir):
|
||||
print(f"error: failed to add '{pkg}': package is not built")
|
||||
continue
|
||||
for target_file in os.listdir(targetdir):
|
||||
if not target_file.endswith(".pkg"):
|
||||
continue
|
||||
try:
|
||||
lib.packie.repo_add(repo_dir, f"{targetdir}/{target_file}")
|
||||
except:
|
||||
print(f"error: failed to add '{pkg}': see the output above")
|
||||
|
||||
|
||||
if args.subcommand == "build":
|
||||
if args.atombuild:
|
||||
run_build_atom(args.BUILD_PKGNAME)
|
||||
cmd_build_atom(args.BUILD_PKGNAME)
|
||||
else:
|
||||
run_build_package(args.BUILD_PKGNAME)
|
||||
cmd_build_package(args.BUILD_PKGNAME)
|
||||
elif args.subcommand == "clean":
|
||||
run_clean_package(args.CLEAN_PKGNAME)
|
||||
if args.all:
|
||||
pkgs = os.listdir("packages")
|
||||
else:
|
||||
pkgs = args.CLEAN_PKGNAME
|
||||
cmd_clean_package(pkgs)
|
||||
elif args.subcommand == "list":
|
||||
run_list(args.ITEM)
|
||||
cmd_list(args.ITEM)
|
||||
elif args.subcommand == "repo-push":
|
||||
cmd_repo_push(args.REPO_DIR, args.REPO_PUSH_PKGNAME)
|
||||
else:
|
||||
print("error: no action specified", file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
Reference in New Issue
Block a user