[elbe-devel] [PATCH 3/5] commands: Add standalone program based on repodir module

Bastian Germann bage at linutronix.de
Tue Oct 11 10:53:54 CEST 2022


The elbepack.repodir module is used to provide a standalone "elbe repodir"
cli utility. It runs the web servers until it is interrupted.

Signed-off-by: Bastian Germann <bage at linutronix.de>
---
 debian/python3-elbe-bin.install |  1 +
 elbepack/commands/repodir.py    | 40 +++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 elbepack/commands/repodir.py

diff --git a/debian/python3-elbe-bin.install b/debian/python3-elbe-bin.install
index 6876856ff8..6c6f640558 100644
--- a/debian/python3-elbe-bin.install
+++ b/debian/python3-elbe-bin.install
@@ -12,6 +12,7 @@
 ./usr/lib/python3.*/*-packages/elbepack/commands/pkgdiff.py
 ./usr/lib/python3.*/*-packages/elbepack/commands/preprocess.py
 ./usr/lib/python3.*/*-packages/elbepack/commands/remove_sign.py
+./usr/lib/python3.*/*-packages/elbepack/commands/repodir.py
 ./usr/lib/python3.*/*-packages/elbepack/commands/setsel.py
 ./usr/lib/python3.*/*-packages/elbepack/commands/show.py
 ./usr/lib/python3.*/*-packages/elbepack/commands/sign.py
diff --git a/elbepack/commands/repodir.py b/elbepack/commands/repodir.py
new file mode 100644
index 0000000000..90441f2b76
--- /dev/null
+++ b/elbepack/commands/repodir.py
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+# SPDX-FileCopyrightText: 2022 Linutronix GmbH
+
+import sys
+import os
+from optparse import OptionParser
+from threading import Event
+
+from elbepack.repodir import RepodirError, Repodir
+
+
+def run_command(argv):
+    oparser = OptionParser(usage="usage: %prog repodir [options] <xmlfile>")
+    oparser.add_option("-o", "--output", dest="output",
+                       default="repodir.xml",
+                       help="preprocessed output file", metavar="<xmlfile>")
+    (opt, args) = oparser.parse_args(argv)
+
+    if len(args) != 1:
+        print("Wrong number of arguments", file=sys.stderr)
+        oparser.print_help()
+        sys.exit(20)
+
+    xml_input = args[0]
+    if not os.path.isfile(xml_input):
+        print("%s does not exist" % xml_input, file=sys.stderr)
+        sys.exit(20)
+
+    if os.path.exists(opt.output):
+        # This will be overridden. Try to delete first to make sure it is a regular file.
+        os.remove(opt.output)
+
+    try:
+        with Repodir(xml_input, opt.output):
+            Event().wait()
+    except KeyboardInterrupt:
+        print()
+    except RepodirError as e:
+        print(e, file=sys.stderr)
+        sys.exit(20)
-- 
2.30.2



More information about the elbe-devel mailing list