Skip to content

Commit

Permalink
Add slfo-packagelist-uploader.py for uploading SLFO packagelist to me…
Browse files Browse the repository at this point in the history
…ta package

slfo-packagelist-uploader.py is be able to checkout pacakgelist from
src.opensue.org/products/SLFO_main and uplaoding the packagelist to
project's pseudometa package.
  • Loading branch information
nilxam committed Sep 10, 2024
1 parent 095d929 commit 9a226fd
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
- name: FIXME, install missing dependencies
run: |
zypper -n in python3-typing_extensions python3-solv python3-pika python3-openqa_client build python3-influxdb python3-bugzilla
zypper -n in python3-typing_extensions python3-solv python3-pika python3-openqa_client build python3-influxdb python3-bugzilla python3-GitPython
- name: run a simple smoke test whether --help actually works
run: |
Expand Down
2 changes: 1 addition & 1 deletion dist/ci/testenv-tumbleweed/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN zypper in -y osc python3-pytest python3-httpretty python3-pyxdg python3-PyYA
python3-influxdb python3-pytest-cov libxml2-tools curl python3-flake8 python3-requests \
shadow vim vim-data strace git sudo patch unzip which cpio gawk openSUSE-release openSUSE-release-ftp \
perl-Net-SSLeay perl-Text-Diff perl-XML-Simple perl-XML-Parser build \
obs-service-download_files obs-service-format_spec_file obs-scm-bridge
obs-service-download_files obs-service-format_spec_file obs-scm-bridge python3-GitPython
RUN useradd tester -d /code/tests/home

COPY run_as_tester /usr/bin
Expand Down
5 changes: 5 additions & 0 deletions dist/package/openSUSE-release-tools.spec
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ Requires: osclib = %{version}
Requires: python3-requests
Requires: python3-solv
Requires: zstd
# slfo-packagelist-uploader.py
Requires: python3-GitPython
# we use the same user as repo-checker
PreReq: openSUSE-release-tools-repo-checker
BuildArch: noarch
Expand Down Expand Up @@ -428,6 +430,7 @@ exit 0
%exclude %{_datadir}/%{source_dir}/project-installcheck.py
%exclude %{_datadir}/%{source_dir}/suppkg_rebuild.py
%exclude %{_datadir}/%{source_dir}/skippkg-finder.py
%exclude %{_datadir}/%{source_dir}/slfo-packagelist-uploader.py
%exclude %{_datadir}/%{source_dir}/osclib
%exclude %{_datadir}/%{source_dir}/osc-cycle.py
%exclude %{_datadir}/%{source_dir}/osc-origin.py
Expand Down Expand Up @@ -545,9 +548,11 @@ exit 0
%files pkglistgen
%{_bindir}/osrt-pkglistgen
%{_bindir}/osrt-skippkg-finder
%{_bindir}/osrt-slfo-packagelist-uploader
%{_datadir}/%{source_dir}/pkglistgen
%{_datadir}/%{source_dir}/pkglistgen.py
%{_datadir}/%{source_dir}/skippkg-finder.py
%{_datadir}/%{source_dir}/slfo-packagelist-uploader.py

%files -n osclib
%{_datadir}/%{source_dir}/osclib
Expand Down
93 changes: 93 additions & 0 deletions slfo-packagelist-uploader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/python3

import argparse
import logging
import sys
import os
import shutil
import git

from lxml import etree as ET

import osc.conf
from osclib.core import source_file_ensure
from osclib.core import project_pseudometa_package

META_FILE = 'SLFO_Packagelist.group'


class PackagelistUploader(object):
def __init__(self, project, print_only, verbose):
self.project = project
self.print_only = print_only
self.verbose = verbose
self.apiurl = osc.conf.config['apiurl']
self.debug = osc.conf.config['debug']

def create_packagelist(self, packages=[]):
packagelist = ET.Element('packagelist')
for pkg in sorted(packages):
if not self.print_only and self.verbose:
print(pkg)
attr = {'name': pkg}
ET.SubElement(packagelist, 'package', attr)

return ET.tostring(packagelist, pretty_print=True, encoding='unicode')

def crawl(self):
"""Main method"""
cwd = os.getcwd()
filepath = os.path.join(cwd, 'SLFO_main')
if os.path.isdir(filepath):
shutil.rmtree(filepath)
gitpath = 'https://src.opensuse.org/products/SLFO_main.git'
git.Repo.clone_from(gitpath, filepath, branch='main')
packages = []
files = os.listdir(filepath)
for f in files:
if f.startswith("."):
continue
fullpath = os.path.join(filepath, f)
if os.path.isdir(fullpath):
packages.append(f)

slfo_packagelist = self.create_packagelist(packages)
pseudometa_project, pseudometa_package = project_pseudometa_package(self.apiurl, self.project)
if not self.print_only:
source_file_ensure(self.apiurl, pseudometa_project, pseudometa_package, META_FILE,
slfo_packagelist, 'Update SLFO packagelist')
else:
print(slfo_packagelist)


def main(args):
osc.conf.get_config(override_apiurl=args.apiurl)
osc.conf.config['debug'] = args.debug

if args.project is None:
print("Please pass --project argument. See usage with --help.")
quit()

uc = PackagelistUploader(args.project, args.print_only, args.verbose)
uc.crawl()


if __name__ == '__main__':
description = 'Upload SLFO packagelist from src.opensuse.org to staging meta package.'
parser = argparse.ArgumentParser(description=description)
parser.add_argument('-A', '--apiurl', metavar='URL', help='API URL')
parser.add_argument('-d', '--debug', action='store_true',
help='print info useful for debuging')
parser.add_argument('-p', '--project', dest='project', metavar='PROJECT',
help='Target project on buildservice')
parser.add_argument('-o', '--print-only', action='store_true',
help='show the result instead of the uploading')
parser.add_argument('-v', '--verbose', action='store_true',
help='show the diff')

args = parser.parse_args()

logging.basicConfig(level=logging.DEBUG if args.debug
else logging.INFO)

sys.exit(main(args))

0 comments on commit 9a226fd

Please sign in to comment.