#25 CLI plugins packaging
Opened 6 years ago by tkopecek. Modified 5 years ago
tkopecek/koji-tools plugins  into  master

file modified
+55 -2
@@ -1,3 +1,23 @@ 

+ %if 0%{?fedora}

%if 0%{?fedora} || 0%{?rhel} >= 8

+ %bcond_without python3

+ # If the definition isn't available for python3_pkgversion, define it

+ %{?!python3_pkgversion:%global python3_pkgversion 3}

+ %else

+ %bcond_with python3

+ %endif

+ 

+ # Compatibility with RHEL. These macros have been added to EPEL but

+ # not yet to RHEL proper.

+ # https://bugzilla.redhat.com/show_bug.cgi?id=1307190

This RHBZ is closed duplicate of RHBZ#1297522 , which shipped a few years ago.

More importantly, RHEL 7.7 beta has Python 3. Can we just use that? It would simplify the packaging as we prep it for Fedora.

+ %{!?__python2: %global __python2 /usr/bin/python2}

+ %{!?python2_sitelib: %global python2_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}

+ %{!?python2_sitearch: %global python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}

+ %{!?py2_build: %global py2_build %{expand: CFLAGS="%{optflags}" %{__python2} setup.py %{?py_setup_args} build --executable="%{__python2} -s"}}

+ %{!?py2_install: %global py2_install %{expand: CFLAGS="%{optflags}" %{__python2} setup.py %{?py_setup_args} install -O1 --skip-build --root %{buildroot}}}

+ 

+ # If the definition isn't available for python3_pkgversion, define it

+ %{?!python3_pkgversion:%global python3_pkgversion 3}

+ 

  Name:       koji-tools

  Version:    1.3

  Release:    2%{?dist}
@@ -8,14 +28,33 @@ 

  Source0:    %{name}-%{version}.tar.gz

  BuildRoot:  %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

  BuildArch:  noarch

- 

  BuildRequires:  python-devel

+ %if 0%{with python3}

+ BuildRequires:  python3-devel

+ %endif

  Requires: koji

  

  %description

  provides a collection of tools/utilities that interacts

  and automates koji tasks for the user.

  

+ %package -n python2-%{name}-plugins-cli

+ Summary:    Koji tools for use as plugins

+ Requires:   python2-koji

+ 

+ %description -n python2-%{name}-plugins-cli

+ Various plugins for koji

+ 

+ %if 0%{with python3}

+ %package -n python%{python3_pkgversion}-%{name}-plugins-cli

+ Summary:    Koji tools for use as plugins

+ Requires:   python%{python3_pkgversion}-koji

+ %{?python_provide:%python_provide python%{python3_pkgversion}-%{name}-hub}

+ 

+ %description -n python%{python3_pkgversion}-%{name}-plugins-cli

+ Various plugins for koji

"Plugins for the Koji client CLI"

+ %endif

+ 

  %prep

  %setup -q

  
@@ -25,16 +64,30 @@ 

  rm -rf $RPM_BUILD_ROOT

  install -d $RPM_BUILD_ROOT%{_bindir}

  install -pm 0755 src/bin/* $RPM_BUILD_ROOT%{_bindir}

+ install -d $RPM_BUILD_ROOT%{python2_sitelib}/koji_cli_plugins

+ install -pm 0644 src/plugins/cli/* $RPM_BUILD_ROOT%{python2_sitelib}/koji_cli_plugins

+ %if 0%{with python3}

+ install -d $RPM_BUILD_ROOT%{python3_sitelib}/koji_cli_plugins

+ install -pm 0644 src/plugins/cli/* $RPM_BUILD_ROOT%{python3_sitelib}/koji_cli_plugins

+ %endif

  

  %clean

  rm -rf $RPM_BUILD_ROOT

  

- 

  %files

  %defattr(-,root,root,-)

  %{_bindir}/*

  %doc COPYING LGPL

  

+ %files -n python2-%{name}-plugins-cli

+ %defattr(-,root,root,-)

+ %{python2_sitelib}/koji_cli_plugins

+ 

+ %if 0%{with python3}

+ %files -n python%{python3_pkgversion}-%{name}-plugins-cli

+ %defattr(-,root,root,-)

+ %{python3_sitelib}/koji_cli_plugins

+ %endif

  

  %changelog

  * Mon Sep 26 2016 Jay Greguske <jgregusk@redhat.com> 1.3-2

src/plugins/cli/koji_buildroots_with_build.py src/bin/koji-buildroots-with-build
file renamed
+20 -17
@@ -1,35 +1,38 @@ 

- #!/usr/bin/python

- 

- import koji

  import sys

  from optparse import OptionParser

  

+ from koji.plugin import export_cli

+ from koji_cli.lib import _, activate_session

+ 

  

- def main():

-     global options

-     parser = OptionParser("usage: %prog [options] <nvr|nvra>")

-     parser.add_option('-r', '--profile', default='koji',

-                       help='set the koji profile')

-     (options, args) = parser.parse_args()

+ @export_cli

+ def handle_list_buildroots_with_build(options, session, args):

+     "[info] List buildroots containing this build"

+     usage = _("usage: %prog [options] buildroot-with-build <nvr|nvra>")

+     parser = OptionParser(usage=usage)

+     (opts, args) = parser.parse_args(args)

      if len(args) != 1:

          parser.error('Please specify a build or rpm')

-     session_opts = koji.grab_session_options(koji.config)

-     session = koji.ClientSession(koji.config.server, session_opts)

+ 

+     activate_session(session, options)

+ 

      rpminfo = session.getRPM(args[0])

      if rpminfo:

          rpms = [rpminfo]

      else:

          buildinfo = session.getBuild(args[0])

          if not buildinfo:

-             print "Could not find", args[0]

+             print("Could not find: %s" % args[0])

              sys.exit(1)

          rpms = session.listRPMs(buildID=buildinfo['id'])

+ 

      brs = {}

+     session.multicall = True

      for rpm in rpms:

-         for br in session.listBuildroots(rpmID=rpm['id']):

+         session.listBuildroots(rpmID=rpm['id'])

+     for [buildroots] in session.multiCall():

+         for br in buildroots:

              brs[br['id']] = br

-     for br_id, br in sorted(brs.items()):

-         print "%(id)s: %(arch)s %(tag_name)s" % br

  

- if __name__ == "__main__":

-     main()

+     for br_id, br in sorted(brs.items()):

+         print("%(id)s: %(arch)-8s %(tag_name)s" % br)

I've tried to convert one PoC script to be CLI plugin and updated spec to create python2/3-koji-tools-plugins-cli rpms.
Few changes are in buildroot_with_build itself due to py2/3 compatibility and plugin conversion.

"Plugins for the Koji client CLI"

%if 0%{?fedora} || 0%{?rhel} >= 8

This RHBZ is closed duplicate of RHBZ#1297522 , which shipped a few years ago.

More importantly, RHEL 7.7 beta has Python 3. Can we just use that? It would simplify the packaging as we prep it for Fedora.

Hmm, it would be nice to just ignore python2. @mikem anything against? I thinks we can go this way - it is not essential package for koji, so we can just assume, that if anybody wants to use it, he can run it on some machine with py3. And it will be easier maintenance for us.

My concern are scripts which are expected to run on hub (e.g. remove-stray-build) which could still be running py2 only. But packaging could be fixed downstream for such cases.

(If we would like to go this way, I'll file a separate issue/PR, as it has not much to do with plugins).

There are a couple of changes mixed in here, like src/plugins/cli/koji_buildroots_with_build.py switches to activate_session(), or session.multicall

I would like to rewrite this change and break it up into smaller commits after you merge #31. Is that ok with you?