Commit 5b32abe7 authored by Robin Sonnabend's avatar Robin Sonnabend

Building the package with patches works

parent 7f4b8d4c
Pipeline #484 failed with stage
in 5 minutes and 25 seconds
__pycache__/
venv/
*.sw[po]
---
- name: adcli
patch_dir: patches/adcli
maintainer:
name: FSMPI Admin-Team
mail: admin@fsmpi.rwth-aachen.de
packages:
- name: adcli
patch_dir: patches/adcli
version: 0.8.2-1.1-fsmpi
changelog: Apply the unreleased upstream-patches, fixing RT#100
#!/usr/bin/env python3
import locale
locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
import os
import subprocess as sp
import re
import tempfile
import yaml
......@@ -11,17 +15,91 @@ def load_config():
return yaml.load(config_file)
def build_package(repo_dir, name, patch_dir=None):
with tempfile.TemporaryDirectory() as tempdir:
os.chdir(tempdir)
result = sp.run(
["apt-get", "source", name],
check=True)
PKG_NAME_PATTERN = r"[a-zA-Z0-9.+-]+"
EPOCH_PATTERN = r"[0-9]+:"
UPSTREAM_VERSION_PATTERN = r"[a-zA-Z0-9.+-:]+"
DEBIAN_VERSION_PATTERN = r"[a-zA-Z0-9.+~]+"
EXTRACT_PATTERN = (r"extracting (?P<name>{pkg_name}) in (?P<dir>{pkg_name}-{version})"
.format(pkg_name=PKG_NAME_PATTERN, version=UPSTREAM_VERSION_PATTERN))
def run_checked(command, **kwargs):
try:
return sp.run(
command, check=True,
stdout=sp.PIPE, stderr=sp.PIPE, universal_newlines=True,
**kwargs)
except sp.CalledProcessError as error:
print(error.stderr)
raise
def build_package(repo_dir, name, patch_dir=None, version=None, changelog=None):
with tempfile.TemporaryDirectory(dir=os.path.abspath(".")) as tempdir:
os.chdir(tempdir)
result = run_checked(["apt-get", "source", name])
source_dir_candidates = [
line for line in result.stdout.splitlines() if "extracting" in line]
if len(source_dir_candidates) != 1:
raise ValueError("Got inconclusive candidate directories: {}".format(
source_dir_candidates))
source_dir_match = re.search(EXTRACT_PATTERN, source_dir_candidates[0])
if source_dir_match is None:
raise ValueError("Cannot get extraction directory from {}".format(
source_dir_candidates[0]))
pkg_dir = source_dir_match.group("dir")
pkg_name = source_dir_match.group("name")
if pkg_name != name:
raise ValueError(
"Extracted package {} is not expected package {}".format(
pkg_name, name))
debian_workdir = os.path.join(tempdir, pkg_dir, "debian")
os.chdir(debian_workdir)
if patch_dir is not None:
abs_patch_dir = os.path.join(repo_dir, patch_dir)
for patch in sorted(os.listdir(abs_patch_dir)):
patch_file = os.path.join(abs_patch_dir, patch)
run_checked(["quilt", "import", patch_file])
command = ["debchange", "--preserve"]
if version is None:
command.append("--nmu")
else:
command.extend(["--newversion", version])
def _get_log_entries():
if changelog:
yield changelog
yield "Non-maintainer upload"
for entry in _get_log_entries():
run_checked(command + [entry])
command = ["debuild", "-b", "-uc", "-us"]
run_checked(command)
deb_packages = [
filename
for filename in os.listdir(tempdir)
if filename.endswith(".deb")
]
print(deb_packages)
#input("Waiting for you, do your thing…")
def main():
repo_dir = os.getcwd()
for package in load_config():
config = load_config()
maintainer = config.get("maintainer", None)
if maintainer is not None:
name = maintainer.get("name", None)
mail = maintainer.get("mail", None)
if name:
os.environ["DEBFULLNAME"] = name
if mail:
os.environ["DEBEMAIL"] = mail
for package in config["packages"]:
build_package(repo_dir=repo_dir, **package)
os.chdir(repo_dir)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment