[elbe-devel] [PATCH 17/21] elbepack: soapclient: make get_files a method on ElbeSoapClient
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Tue Aug 6 11:18:15 CEST 2024
This is useful functionality that should be usable without going through
"elbe control".
Make it a library function that can be called from other parts of elbe
and call it from "elbe control".
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/commands/control.py | 32 ++++++--------------------------
elbepack/soapclient.py | 24 ++++++++++++++++++++++++
2 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/elbepack/commands/control.py b/elbepack/commands/control.py
index 2980524a3321..4863125572ef 100644
--- a/elbepack/commands/control.py
+++ b/elbepack/commands/control.py
@@ -4,7 +4,6 @@
import argparse
import binascii
-import fnmatch
import os
import socket
import sys
@@ -158,33 +157,14 @@ def _dump_file(client, args):
help='Select files based on wildcard expression.')
@_add_project_dir_argument
def _get_files(client, args):
- files = client.service.get_files(args.project_dir)
-
- nfiles = 0
-
- for f in files[0]:
- if (args.pbuilder_only and not f.name.startswith('pbuilder_cross')
- and not f.name.startswith('pbuilder')):
- continue
-
- if args.matches and not fnmatch.fnmatch(f.name, args.matches):
- continue
-
- nfiles += 1
- try:
- print(f'{f.name} \t({f.description})')
- except AttributeError:
- print(f'{f.name}')
-
- if args.output:
- dst = os.path.abspath(args.output)
- os.makedirs(dst, exist_ok=True)
- dst_fname = str(os.path.join(dst, os.path.basename(f.name)))
- client.download_file(args.project_dir, f.name, dst_fname)
-
- if nfiles == 0:
+ files = client.get_files(args.project_dir, args.output,
+ pbuilder_only=args.pbuilder_only, wildcard=args.matches)
+ if not files:
sys.exit(189)
+ for file in files:
+ print(f'{file.name}\t{file.description}')
+
@_add_project_dir_argument
def _wait_busy(client, args):
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index 995a6b3a13ca..ea476f3f6456 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -4,6 +4,7 @@
# SPDX-FileCopyrightText: 2016 Claudius Heine <ch at denx.de>
import binascii
+import fnmatch
import logging
import os
import socket
@@ -218,3 +219,26 @@ class ElbeSoapClient:
self.service.start_pdebuild(builddir)
self.upload_file(self.service.append_pdebuild, builddir, pdebuild_file)
self.service.finish_pdebuild(builddir, profile, cross)
+
+ def get_files(self, builddir, outdir, *, pbuilder_only=False, wildcard=None):
+ files = self.service.get_files(builddir)
+
+ result = []
+
+ for f in files[0]:
+ if (pbuilder_only and not f.name.startswith('pbuilder_cross')
+ and not f.name.startswith('pbuilder')):
+ continue
+
+ if wildcard and not fnmatch.fnmatch(f.name, wildcard):
+ continue
+
+ result.append(f)
+
+ if outdir:
+ dst = os.path.abspath(outdir)
+ os.makedirs(dst, exist_ok=True)
+ dst_fname = str(os.path.join(dst, os.path.basename(f.name)))
+ self.download_file(builddir, f.name, dst_fname)
+
+ return result
--
2.46.0
More information about the elbe-devel
mailing list