Compare commits

..

9 Commits

8 changed files with 115 additions and 44 deletions

View File

@ -1 +1 @@
VERSION = 1.5.5
VERSION = 1.6.0

View File

@ -5,7 +5,7 @@
#
# Released under the terms of the GNU GPL release 3 license
#
VERSION=1.5.5
VERSION=1.6.0
me=(${0##*/} $VERSION "Tue Jan 26 2016")
exec 3>`readlink /proc/self/fd/0`

View File

@ -1,16 +1,20 @@
#!/usr/bin/python3
"""
autodist git integration
"""
import argparse
import glob
import os
import re
import rpm
import subprocess
import sys
import tempfile
from shutil import copyfile
from pyrpm.spec import Spec, replace_macros
from gitea import *
from git import Repo
from functools import cmp_to_key
from gitea import Gitea, NotFoundException, Organization, Repository
import rpm
from pyrpm.spec import Spec, replace_macros
from git import Repo
from configobj import ConfigObj
@ -18,9 +22,6 @@ cfg = ConfigObj(infile='/etc/autodist/config-git')
gitea = Gitea(cfg["GITEA_URL"], cfg["GITEA_TOKEN"])
org = Organization.request(gitea, cfg["GITEA_ORGANIZATION"])
# argparse options
options = None
def comparePkgInfo(item1, item2):
return rpm.labelCompare(
(str(item1['e']), item1['v'], item1['r']),
@ -41,6 +42,14 @@ def giteaGetRepository(repo_name):
except NotFoundException:
return None
def giteaGetRepositories(page, limit):
try:
path = f'/orgs/{cfg["GITEA_ORGANIZATION"]}/repos?page={page}&limit={limit}'
results = gitea.requests_get(path)
return [Repository.parse_response(gitea, result) for result in results]
except NotFoundException:
return None
def findOrCreateRepo(pkg_name, pkg_description=None, create=True):
# Replace '+' for repository name as it is not allowed
repo_name = pkg_name.replace('+','Plus')
@ -69,9 +78,29 @@ def findOrCreateRepo(pkg_name, pkg_description=None, create=True):
gitea_repo = giteaGetRepository(repo_name)
return gitea_repo
def commitReleaseFromDir(pkg_info, gitea_repo, repo, temp_dir):
global options
def archiveRepo(pkg_name):
# Replace '+' for repository name as it is not allowed
repo_name = pkg_name.replace('+','Plus')
# Get gitea repository instance
#try:
# gitea_repo = org.get_repository(repo_name)
gitea_repo = giteaGetRepository(repo_name)
if gitea_repo is None:
print(f'archiveRepo: repository {repo_name} not found')
return
if getattr(gitea_repo, "archived"):
print(f'Repository {repo_name} is already archived')
return False
setattr(gitea_repo, "archived", True)
gitea_repo.commit()
return True
def commitReleaseFromDir(options, pkg_info, gitea_repo, repo, temp_dir):
src_dir = pkg_info["src"]
if src_dir.endswith(".src.rpm"):
@ -80,11 +109,11 @@ def commitReleaseFromDir(pkg_info, gitea_repo, repo, temp_dir):
src_temp_dir = tempfile.TemporaryDirectory()
src_dir = src_temp_dir.name
subprocess.run(["autospec", "-x", pkg_info["src"], f'--destdir={src_dir}'],
stdout=subprocess.PIPE)
stdout=subprocess.PIPE, check=False)
# Delete binary source archives
for pattern in [
'*.zip','*.tar.bz2','*.tar.xz','*.tar.gz','*.tgz','*.txz','*.iso',
'*.run','*.dll','*.bin','*.jar','*.msi']:
'*.run','*.dll','*.bin','*.jar','*.msi','*.deb']:
for filename in glob.glob(f'{src_dir}/{pattern}'):
os.remove(filename)
@ -145,7 +174,7 @@ def commitReleaseFromDir(pkg_info, gitea_repo, repo, temp_dir):
return
# Create/update README.md
with open(f'{temp_dir.name}/README.md', "w") as readme_file:
with open(file=f'{temp_dir.name}/README.md', mode="w", encoding="utf-8") as readme_file:
readme_file.write(f"# {pkg_info['name']}\n\n{spec_description}")
repo.index.add(['README.md'])
@ -180,9 +209,7 @@ def commitReleaseFromDir(pkg_info, gitea_repo, repo, temp_dir):
repo.create_tag(new_tag, message=f'Release {new_tag}')
#origin.push(new_tag)
def findAndCommitPackageReleases(pkgname, pkgvr):
global options
def findAndCommitPackageReleases(options, pkgname, pkgvr):
print(f'Processing package {pkgname} on {cfg["GITEA_URL"]}...')
pkgs_info = []
@ -190,10 +217,10 @@ def findAndCommitPackageReleases(pkgname, pkgvr):
# Find from archive dir
pkgnamere = pkgname.replace('+','\+')
dirs = [f for f in os.listdir(f'{cfg["ARCHIVE_DIR"]}/{pkgname[0:1]}') if re.match(f'{pkgnamere}-[^-]*-[^-]*$', f)]
for dir in dirs:
pkg_dir = f'{cfg["ARCHIVE_DIR"]}/{pkgname[0:1]}/{dir}'
for _dir in dirs:
pkg_dir = f'{cfg["ARCHIVE_DIR"]}/{pkgname[0:1]}/{_dir}'
spec = Spec.from_file(f'{pkg_dir}/{pkgname}.spec')
parts = re.split(f'{pkgnamere}-([^-]*)-([^-]*)$', dir)
parts = re.split(f'{pkgnamere}-([^-]*)-([^-]*)$', _dir)
epoch = 0 if spec.epoch is None else int(spec.epoch)
version = parts[1]
@ -203,12 +230,12 @@ def findAndCommitPackageReleases(pkgname, pkgvr):
# Find from OLD_DIR
dirs = [f for f in os.listdir(f'{cfg["OLD_DIR"]}') if re.match(f'{pkgnamere}_[0-9]*.[0-9]*$', f)]
for dir in dirs:
srpms_list = glob.glob(f'{cfg["OLD_DIR"]}/{dir}/{pkgname}-*.src.rpm')
for _dir in dirs:
srpms_list = glob.glob(f'{cfg["OLD_DIR"]}/{_dir}/{pkgname}-*.src.rpm')
for srpm in srpms_list:
parts = re.split('.*-([^-]*)-([^-]*).src.rpm$', srpm)
epoch = subprocess.run(['rpm', '-q', '--queryformat=%{epoch}', '-p', srpm],
stdout=subprocess.PIPE).stdout.decode('utf-8')
stdout=subprocess.PIPE, check=False).stdout.decode('utf-8')
# result is "(none)" if no Epoch is set
if len(epoch) > 2:
epoch = "0"
@ -223,7 +250,7 @@ def findAndCommitPackageReleases(pkgname, pkgvr):
src_path = f'{cfg["SRPMS_DIR"]}/{srpm}'
parts = re.split('.*-([^-]*)-([^-]*).src.rpm$', srpm)
epoch = subprocess.run(['rpm', '-q', '--queryformat=%{epoch}', '-p', src_path],
stdout=subprocess.PIPE).stdout.decode('utf-8')
stdout=subprocess.PIPE, check=False).stdout.decode('utf-8')
# result is "(none)" if no Epoch is set
if len(epoch) > 2:
epoch = "0"
@ -266,7 +293,7 @@ def findAndCommitPackageReleases(pkgname, pkgvr):
#exit(1)
#pkg_dir = f'{cfg["ARCHIVE_DIR"]}/{pkgname[0:1]}/{pkgname}-{vr}'
commitReleaseFromDir(pkg_info, gitea_repo, repo, temp_dir)
commitReleaseFromDir(options, pkg_info, gitea_repo, repo, temp_dir)
new_commits = True
if new_commits:
@ -280,7 +307,8 @@ def findAndCommitPackageReleases(pkgname, pkgvr):
def main():
global options
# argparse options
options = None
parser = argparse.ArgumentParser(prog='autodist-git',
description='RPM repository sync and management with git service.',
@ -294,6 +322,9 @@ def main():
parser_syncpkg.add_argument('-d', '--delete', action='store_true', help="delete and recreate existing repository",
required=False)
parser_archiverepo = subparsers.add_parser('archiverepo', help="archive a specified repository package on git server")
parser_archiverepo.add_argument('pkgname', help="name of package")
parser_syncrepo = subparsers.add_parser('syncrepo', help="sync base repository with git server")
parser_syncrepo.add_argument('--from', dest='frompkg', help="from package name", required=False)
parser_syncrepo.add_argument('--to', dest='topkg', help="to package name", required=False)
@ -303,7 +334,7 @@ def main():
try:
options = parser.parse_args()
except:
exit(1)
sys.exit(1)
if options.mode == 'syncpkg':
if options.delete:
@ -315,10 +346,18 @@ def main():
if gitea_repo is not None:
print(f'Deleting repository for {options.pkgname}...')
gitea_repo.delete()
findAndCommitPackageReleases(options.pkgname, options.pkgver)
findAndCommitPackageReleases(options, options.pkgname, options.pkgver)
elif options.mode == 'archiverepo':
print(f'Archiving repository for {options.pkgname}...')
archiveRepo(options.pkgname)
elif options.mode == 'syncrepo':
# Get list for packages from SRPMS dir
dir_list = sorted(filter(os.path.isfile, glob.glob(f'{cfg["SRPMS_DIR"]}/*.src.rpm')))
# Check for package updates to sync with git repositories
print("Checking for package updates to sync with git repositories...")
for dir_file in dir_list:
parts = re.split('.*/([^/]*)-([^-]*)-([^-]*).src.rpm$', dir_file)
pkg_name = parts[1]
@ -343,7 +382,7 @@ def main():
found_newer = True
else:
for repo_tag in repo_tags:
parts = re.split(f'([^-]*)-([^-]*)$', repo_tag["name"])
parts = re.split('([^-]*)-([^-]*)$', repo_tag["name"])
tag_item = { 'e':0, 'v': parts[1], 'r': parts[2]}
compare = comparePkgInfo(pkg_item, tag_item)
if compare == 0:
@ -355,10 +394,28 @@ def main():
if not found_equal:
if repo_tags is not None:
print(f'{pkg_name} ({pkg_vr}): needs update')
findAndCommitPackageReleases(pkg_name, None)
findAndCommitPackageReleases(options, pkg_name, None)
if found_newer:
if options.verbose:
print(f'{pkg_name} ({pkg_vr}): found_equal={found_equal} found_newer={found_newer} found_older={found_older}')
# Check for git repositories to archive
print("Checking for git repositories to archive...")
pkg_names = []
for dir_file in dir_list:
parts = re.split('.*/([^/]*)-([^-]*)-([^-]*).src.rpm$', dir_file)
pkg_names.append(parts[1])
page = 1
while True:
gitea_repos = giteaGetRepositories(page, 50)
for gitea_repo in gitea_repos:
if not getattr(gitea_repo, "archived") and not gitea_repo.name.replace('Plus','+') in pkg_names:
print(f'Archiving repository {gitea_repo.name}')
archiveRepo(gitea_repo.name)
if len(gitea_repos) < 50:
break
page += 1
else:
parser.print_help()

View File

@ -4,7 +4,7 @@
#
# Released under the terms of the GNU GPL release 3 license
#
VERSION=1.5.5
VERSION=1.6.0
BASE_REPOSITORY=base
PORT_REPOSITORY=base

View File

@ -54,6 +54,7 @@ done
# Distribution global changes
sed -i "s|^Vendor:.*|Vendor: openmamba|;
s|^Distribution:.*|Distribution: openmamba|;
/^%debug_package$/d;
/BuildRequires:[[:space:]]*libffmpeg-devel/d;
/^BuildRequires:[[:space:]]*libkdegames-devel/d;
/^BuildRequires:[[:space:]]*libkdegames5-devel/d;

View File

@ -1292,7 +1292,8 @@ if [ "$MAINTAINERMODE" != "true" ]; then
done
echo -n "</select>"
echo -n "&nbsp;<label style=\"background-color:red;padding:1px;\"><input type=checkbox id=\"rpmforce\" value=\"force\">force&nbsp;</label>"
echo -n "&nbsp;<label style=\"padding:1px;\"><input type=checkbox id=\"debug\" value=\"debug\">debug&nbsp;</label>"
echo -n "&nbsp;<label style=\"padding:1px;\"><input type=checkbox id=\"noprep\" value=\"noprep\">no prep</label>"
echo -n "&nbsp;<label style=\"padding:1px;\"><input type=checkbox id=\"debug\" value=\"debug\">debug</label>"
# destination repository select
echo -n "<br>Send to:"
echo -n "<select id=sendrepository>"
@ -1423,6 +1424,7 @@ if [ "$MAINTAINERMODE" != "true" ]; then
echo -n "<input type=button value=\"build\" onclick="
echo -n "p=getCheckedValuesByName('autodistpkgscheckbox');ajax_getvalues(\""
echo -n "AUTODISTFORCE=\"+getElementById('rpmforce').checked+\"&"
echo -n "AUTODISTNOPREP=\"+getElementById('noprep').checked+\"&"
echo -n "AUTODISTARCH=\"+getSelectedValueById('rpmbuildarch')+\"&"
echo -n "AUTODISTJOB=\"+getSelectedValueById('autodistjobs')+\"&"
echo -n "AUTODISTPKGS=\"+encodeURIComponent(p)+\"&"
@ -1490,6 +1492,7 @@ if [ "$MAINTAINERMODE" != "true" ]; then
echo -n "p=getSelectedValueById('sendrepository');"
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&"
echo -n "AUTODISTFORCE=\"+getElementById('rpmforce').checked+\"&"
echo -n "AUTODISTNOPREP=\"+getElementById('noprep').checked+\"&"
echo -n "SENDREPOSITORY=\"+p+\"&"
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue())+\"&"
echo -n "PACKAGE=$PACKAGEENCODED&REQUEST=autoportnp\""
@ -1729,6 +1732,7 @@ case $REQUEST in
social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"unscheduled autodist job <b>$AUTODISTJOB</b>\" STIME=`date +%s`"
fi ;;
"autodistbuild") [ "$AUTODISTFORCE" = "true" ] && AUTODISTADD="--force" || AUTODISTADD=
[ "$AUTODISTNOPREP" = "true" ] && AUTOSPEC="--noprep" || AUTOSPECADD=
autodistjobs=
if [ "$AUTODISTPKGS" ]; then
for p in $AUTODISTPKGS; do
@ -1737,7 +1741,7 @@ case $REQUEST in
else
autodistjobs="$AUTODISTJOB"
fi
$SUDO_WRAPPER background $ENVIRONMENT "$USER" "$PACKAGE" "autodist -v -b $autodistjobs --repository ${AUTOPORT_BASE_REPOSITORY[$ENVIRONMENT]} --arch $AUTODISTARCH --user $USER $AUTODISTADD -- --colors web" &>/dev/null
$SUDO_WRAPPER background $ENVIRONMENT "$USER" "$PACKAGE" "autodist -v -b $autodistjobs --repository ${AUTOPORT_BASE_REPOSITORY[$ENVIRONMENT]} --arch $AUTODISTARCH --user $USER $AUTODISTADD -- $AUTOSPECADD --colors web" &>/dev/null
[ $? -ne 0 ] && RET=$? || {
RET=-1
echo "Autodist build start. You may see the output in the <b>Webbuild jobs</b> box above."
@ -1803,10 +1807,12 @@ case $REQUEST in
$SUDO_WRAPPER 0 $ENVIRONMENT "$USER" $PACKAGE "rpmbuild -bp $PACKAGE.spec $RPMARCHADD --nodeps --define=\"_topdir $SPECVAR_WORKINGHOME/RPM\""
RET=$?
;;
"rpmbuild") [ "$RPMFORCE" = "true" ] && RPMFORCEADD="--force-build"
"rpmbuild") AUTOSPECADD=""
[ "$RPMFORCE" = "true" ] && AUTOSPECADD="--force-build"
[ "$NOPREP" = "true" ] && AUTOSPECADD="${AUTOSPECADD} --noprep"
[ "$RPMBUILDARCH" -a "$RPMBUILDARCH" != "${AUTOPORT_ARCH[$ENVIRONMENT]}" ] && \
RPMARCHADD="-A $RPMBUILDARCH --define \"cross_target_cpu=$RPMBUILDARCH\""
$SUDO_WRAPPER background $ENVIRONMENT "$USER" $PACKAGE "$AUTOSPEC_CMD -u $PACKAGE -a5,6 -b $RPMFORCEADD $RPMARCHADD" &>/dev/null
$SUDO_WRAPPER background $ENVIRONMENT "$USER" $PACKAGE "$AUTOSPEC_CMD -u $PACKAGE -a5,6 -b $AUTOSPECADD $RPMARCHADD" &>/dev/null
# && echo \"Webbuild HINT: now you may want to click on 'build requirements', add build requirements in .spec file and then 'recreate SRPMS'\""
[ $? -ne 0 ] && RET=$? || {
RET=-1

View File

@ -1,6 +1,6 @@
#
# webbuild functions-private include file
# Copyright (c) 2012-2014 by Silvan Calarco <silvan.calarco@mambasoft.it>
# Copyright (c) 2012-2024 by Silvan Calarco <silvan.calarco@mambasoft.it>
#
repository_list() {
@ -152,6 +152,7 @@ function print_showlogcontrols() {
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&"
echo -n "REQUEST=consolecmd&CONSOLECMD=\"+getElementById('consolecmd').value+\"&"
echo -n "RPMFORCE=\"+getElementById('rpmforce').checked+\"&"
echo -n "NOPREP=\"+getElementById('noprep').checked+\"&"
echo -n "DEBUG=\"+getElementById('debug').checked+\"&"
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue()));>"
# close tag
@ -192,7 +193,9 @@ function print_editorcontrols() {
echo -n "<input type=button value=\"build\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&REQUEST=rpmbuild&"
echo -n "RPMBUILDARCH=\"+getSelectedValueById('rpmbuildarch')+\"&"
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue())+\"&RPMFORCE=\"+getElementById('rpmforce').checked); class=boldbutton>"
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue())+\"&"
echo -n "NOPREP=\"+getElementById('noprep').checked+\"&"
echo -n "RPMFORCE=\"+getElementById('rpmforce').checked); class=boldbutton>"
# unpackaged files
echo -n "<input type=button value=\"unpackaged list\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&REQUEST=autospeclistcheck&"

View File

@ -88,11 +88,15 @@ if [ "$MODE" = "specinfo" ]; then
done < ${ENVPREFIX}${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec
[ "$AUTOBUILDREQ_BEGIN" -a "$AUTOBUILDREQ_END" -a ! "$AUTOBUILDREQ_UNDONE" ] || \
echo "SPECVAR_CHECK_NOAUTOBUILDREQ=1"
# _setup: prevent %setup macro expansion
$SUCMDPREFIX "rpmspec -P ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec --define \"%setup _setup\" > ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec.tmp 2>/dev/null"
$SUCMDPREFIX "rpmspec -P ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec > ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec.tmp 2>/dev/null"
if [ -e $SPECFILE.tmp ]; then
echo "SPECVAR_Specfile=\"$SPECFILE\""
BUILDDIR=`grep -m1 "^_setup.*-n " $SPECFILE.tmp | sed "s|.*-n \([^[:space:]]*\).*|\1|"`
# Resolve builddir by parsing %setup macro or use default
BUILDDIR_UNPARSED=`grep "^%setup" ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec | sed "s|.*-n \([^[:space:]]*\).*|\1|"`
if [ ! "$BUILDDIR_UNPARSED" ]; then
BUILDDIR_UNPARSED="$PACKAGE-%{version}"
fi
BUILDDIR=`rpmspec -q --srpm --queryformat \"${BUILDDIR_UNPARSED}\" ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec`
while read line; do
set -- $line
[ "$1" = "%package" -o "$1" = "%description" ] && break
@ -104,17 +108,17 @@ if [ "$MODE" = "specinfo" ]; then
[ "$specvar" = "$lastspecvar" ] && varidx=$(($varidx + 1)) || varidx=0
echo "$specvar[$varidx]=\"${line//\"/}\""
[ "$specvaridx" != "" ] && echo "${specvar}_idx[$varidx]=$specvaridx"
[ "$specvar" = "SPECVAR_Version" -a ! "$BUILDDIR" ] && BUILDDIR="$PACKAGE-${line}"
[ "$specvar" = "SPECVAR_Version" ] && PACKAGE_VERSION="${line}"
fi
lastspecvar=$specvar
done < $SPECFILE.tmp
rm -f $SPECFILE.tmp
echo "SPECVAR_BUILDDIR=\"$BUILDDIR\""
echo "SPECVAR_BUILDROOT=\"$PACKAGE-root\""
echo "SPECVAR_RPMBUILDDIR=\"${WORKINGHOME}/RPM/BUILD\""
echo "SPECVAR_RPMSOURCESDIR=\"${WORKINGHOME}/RPM/SOURCES\""
echo "SPECVAR_RPMBUILDROOT=\"$RPMBUILDROOT\""
echo "SPECVAR_WORKINGHOME=\"$WORKINGHOME\""
echo "SPECVAR_RPMBUILDDIR=\"${WORKINGHOME}/RPM/BUILD/${PACKAGE}-${PACKAGE_VERSION}-build\""
echo "SPECVAR_RPMSOURCESDIR=\"${WORKINGHOME}/RPM/SOURCES\""
echo "SPECVAR_RPMBUILDROOT=\"${WORKINGHOME}/RPM/BUILD/${PACKAGE}-${PACKAGE_VERSION}-build/BUILDROOT\""
exit 0
fi
else