[elbe-devel] [PATCH 2/2] elbepack: prjrepo: move repo actions out of soapclient.py

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Jul 24 15:09:17 CEST 2024


The repo actions are highly specific to the prjrepo subcommand.
There is no reason to have them in the generic soapclient module.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/commands/prjrepo.py | 116 +++++++++++++++++++++++++++++++++++++++++--
 elbepack/soapclient.py       | 110 ----------------------------------------
 2 files changed, 113 insertions(+), 113 deletions(-)

diff --git a/elbepack/commands/prjrepo.py b/elbepack/commands/prjrepo.py
index e63da2e6f37c..769eb4420904 100644
--- a/elbepack/commands/prjrepo.py
+++ b/elbepack/commands/prjrepo.py
@@ -3,16 +3,126 @@
 # SPDX-FileCopyrightText: 2017 Linutronix GmbH
 
 import argparse
+import binascii
+import os
 import socket
 import sys
+from datetime import datetime
 from http.client import BadStatusLine
 from urllib.error import URLError
 
+import debian.deb822
+
 from suds import WebFault
 
-from elbepack.cli import add_arguments_from_decorated_function
+from elbepack.cli import add_argument, add_arguments_from_decorated_function
 from elbepack.config import cfg
-from elbepack.soapclient import ElbeSoapClient, repo_actions
+from elbepack.soapclient import ElbeSoapClient
+
+
+ at add_argument('project_dir')
+def _list_packages(client, args):
+    for pkg in client.service.list_packages(args.project_dir):
+        print(pkg)
+
+
+ at add_argument('project_dir')
+def _download(client, args):
+    filename = 'repo.tar.gz'
+    client.service.tar_prjrepo(args.project_dir, filename)
+
+    dst_fname = os.path.join(
+        '.',
+        'elbe-projectrepo-' +
+        datetime.now().strftime('%Y%m%d-%H%M%S') +
+        '.tar.gz')
+
+    client.download_file(args.project_dir, filename, dst_fname)
+    print(f'{dst_fname} saved')
+
+
+def _upload_file(client, f, builddir):
+    # Uploads file f into builddir in intivm
+    size = 1024 * 1024
+    part = 0
+
+    with open(f, 'rb') as fp:
+        while True:
+
+            xml_base64 = binascii.b2a_base64(fp.read(size))
+
+            if not isinstance(xml_base64, str):
+                xml_base64 = xml_base64.decode('ascii')
+
+            # finish upload
+            if len(xml_base64) == 1:
+                part = client.service.upload_file(builddir,
+                                                  os.path.basename(f),
+                                                  xml_base64,
+                                                  -1)
+            else:
+                part = client.service.upload_file(builddir,
+                                                  os.path.basename(f),
+                                                  xml_base64,
+                                                  part)
+            if part == -1:
+                print('project busy, upload not allowed')
+                return -1
+            if part == -2:
+                print('Upload of package finished.')
+                break
+
+
+ at add_argument('project_dir')
+ at add_argument('package')
+def _upload_pkg(client, args):
+    print('\n--------------------------')
+    print('Upload and Include Package')
+    print('--------------------------')
+    print('Check files...')
+
+    filetype = os.path.splitext(args.package)[1]
+
+    # Check filetype
+    if filetype not in ['.dsc', '.deb', '.changes']:
+        print('Error: Only .dsc, .deb or .changes files allowed to upload.')
+        sys.exit(202)
+
+    files = [args.package]  # list of all files which will be uploaded
+
+    # Parse .dsc-File and append neccessary source files to files
+    if filetype == '.dsc':
+        for f in debian.deb822.Dsc(open(args.package))['Files']:
+            files.append(f['name'])
+
+    if filetype == '.changes':
+        for f in debian.deb822.Changes(open(args.package))['Files']:
+            files.append(f['name'])
+
+    # Check whether all files are available
+    abort = False
+    for f in files:
+        if not os.path.isfile(f):
+            print(f'File {f} not found.')
+            abort = True
+    # Abort if one or more source files are missing
+    if abort:
+        sys.exit(203)
+
+    print('Start uploading file(s)...')
+    for f in files:
+        print(f'Upload {f}...')
+        _upload_file(client, f, args.project_dir)
+
+    print('Including Package in initvm...')
+    client.service.include_package(args.project_dir, os.path.basename(args.package))
+
+
+_actions = {
+    'list_packages': _list_packages,
+    'download': _download,
+    'upload_pkg': _upload_pkg,
+}
 
 
 def run_command(argv):
@@ -47,7 +157,7 @@ def run_command(argv):
 
     subparsers = aparser.add_subparsers(required=True)
 
-    for action_name, do_action in repo_actions.items():
+    for action_name, do_action in _actions.items():
         action_parser = subparsers.add_parser(action_name)
         action_parser.set_defaults(func=do_action)
         add_arguments_from_decorated_function(action_parser, do_action)
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index 621bfdb49539..3957cfa2469d 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -5,19 +5,14 @@
 
 import binascii
 import logging
-import os
 import socket
 import sys
 import time
-from datetime import datetime
 from http.client import BadStatusLine
 from urllib.error import URLError
 
-import debian.deb822
-
 from suds.client import Client
 
-from elbepack.cli import add_argument
 from elbepack.config import cfg
 from elbepack.version import elbe_version
 
@@ -121,108 +116,3 @@ class ElbeSoapClient:
 
             fp.write(binascii.a2b_base64(ret))
             part = part + 1
-
-
- at add_argument('project_dir')
-def _list_packages(client, args):
-    for pkg in client.service.list_packages(args.project_dir):
-        print(pkg)
-
-
- at add_argument('project_dir')
-def _download(client, args):
-    filename = 'repo.tar.gz'
-    client.service.tar_prjrepo(args.project_dir, filename)
-
-    dst_fname = os.path.join(
-        '.',
-        'elbe-projectrepo-' +
-        datetime.now().strftime('%Y%m%d-%H%M%S') +
-        '.tar.gz')
-
-    client.download_file(args.project_dir, filename, dst_fname)
-    print(f'{dst_fname} saved')
-
-
-def _upload_file(client, f, builddir):
-    # Uploads file f into builddir in intivm
-    size = 1024 * 1024
-    part = 0
-
-    with open(f, 'rb') as fp:
-        while True:
-
-            xml_base64 = binascii.b2a_base64(fp.read(size))
-
-            if not isinstance(xml_base64, str):
-                xml_base64 = xml_base64.decode('ascii')
-
-            # finish upload
-            if len(xml_base64) == 1:
-                part = client.service.upload_file(builddir,
-                                                  os.path.basename(f),
-                                                  xml_base64,
-                                                  -1)
-            else:
-                part = client.service.upload_file(builddir,
-                                                  os.path.basename(f),
-                                                  xml_base64,
-                                                  part)
-            if part == -1:
-                print('project busy, upload not allowed')
-                return -1
-            if part == -2:
-                print('Upload of package finished.')
-                break
-
-
- at add_argument('project_dir')
- at add_argument('package')
-def _upload_pkg(client, args):
-    print('\n--------------------------')
-    print('Upload and Include Package')
-    print('--------------------------')
-    print('Check files...')
-
-    filetype = os.path.splitext(args.package)[1]
-
-    # Check filetype
-    if filetype not in ['.dsc', '.deb', '.changes']:
-        print('Error: Only .dsc, .deb or .changes files allowed to upload.')
-        sys.exit(202)
-
-    files = [args.package]  # list of all files which will be uploaded
-
-    # Parse .dsc-File and append neccessary source files to files
-    if filetype == '.dsc':
-        for f in debian.deb822.Dsc(open(args.package))['Files']:
-            files.append(f['name'])
-
-    if filetype == '.changes':
-        for f in debian.deb822.Changes(open(args.package))['Files']:
-            files.append(f['name'])
-
-    # Check whether all files are available
-    abort = False
-    for f in files:
-        if not os.path.isfile(f):
-            print(f'File {f} not found.')
-            abort = True
-    # Abort if one or more source files are missing
-    if abort:
-        sys.exit(203)
-
-    print('Start uploading file(s)...')
-    for f in files:
-        print(f'Upload {f}...')
-        _upload_file(client, f, args.project_dir)
-
-    print('Including Package in initvm...')
-    client.service.include_package(args.project_dir, os.path.basename(args.package))
-
-
-repo_actions = {
-    'list_packages': _list_packages,
-    'download': _download,
-    'upload_pkg': _upload_pkg,
-}

-- 
2.45.2



More information about the elbe-devel mailing list