[elbe-devel] [PATCH 2/3] setrepo: initial version

Manuel Traut manut at linutronix.de
Fri Sep 14 15:06:24 CEST 2018


a new subcommand to replace the mirror section of a xml with a single
repo. It's designed to be used for mirrors that have been built with cd2aptly.

Signed-off-by: Manuel Traut <manut at linutronix.de>
---
 debian/elbe.install          |  1 +
 docs/elbe-setrepo.txt        | 68 ++++++++++++++++++++++++++++++++++++
 elbepack/commands/setrepo.py | 57 ++++++++++++++++++++++++++++++
 elbepack/elbexml.py          | 33 +++++++++++++++++
 4 files changed, 159 insertions(+)
 create mode 100644 docs/elbe-setrepo.txt
 create mode 100644 elbepack/commands/setrepo.py

diff --git a/debian/elbe.install b/debian/elbe.install
index 3637e585..e961dfa5 100644
--- a/debian/elbe.install
+++ b/debian/elbe.install
@@ -9,6 +9,7 @@
 ./usr/lib/python2.*/*-packages/elbepack/commands/pkgdiff.py
 ./usr/lib/python2.*/*-packages/elbepack/commands/preprocess.py
 ./usr/lib/python2.*/*-packages/elbepack/commands/remove_sign.py
+./usr/lib/python2.*/*-packages/elbepack/commands/setrepo.py
 ./usr/lib/python2.*/*-packages/elbepack/commands/setsel.py
 ./usr/lib/python2.*/*-packages/elbepack/commands/show.py
 ./usr/lib/python2.*/*-packages/elbepack/commands/sign.py
diff --git a/docs/elbe-setrepo.txt b/docs/elbe-setrepo.txt
new file mode 100644
index 00000000..46eadd99
--- /dev/null
+++ b/docs/elbe-setrepo.txt
@@ -0,0 +1,68 @@
+elbe-setrepo(1)
+===============
+
+NAME
+----
+elbe-setrepo - Replace the mirror section with a single repository
+
+SYNOPSIS
+--------
+[verse]
+'elbe setrepo' [options] <xmlfile> <primary_host>
+
+
+DESCRIPTION
+-----------
+This command exchanges the mirror section of the initvm and target section with
+the given repository.
+
+It can be used to do 'offline rebuilds' with a repo generated by elbe-cd2aptly.
+
+OPTIONS
+-------
+--initvmpath::
+	defaults to '/debian' it is the primary_path inserted into the intivm/mirror
+	section.
+
+--targetpath::
+	defaults to '/debian' it is the primary_path inserted into the project/mirror
+	section.
+
+--protocol::
+	defaults to 'http' it is the primary_proto that is inserted.
+
+--auth::
+	normally the noauth tag is set automatically, this can be skipped by using
+	the auth flag.
+
+--no-dsc-on-mirror::
+	the specified mirror doesn't contain debian sources (dsc).
+
+<xmlfile>::
+	The xmlfile to be modified.
+
+<primary_host>::
+	The hostname inserted as primary_host into the initvm and projects mirror
+	sections.
+
+EXAMPLES
+--------
+
+* build a repo from a set of cdroms
++
+------------
+$ elbe cd2aptly build-*/bin-cdrom.iso myrepo
+------------
+
+* host the repo
++
+------------
+$ cd myrepo
+$ python -m SimpleHTTPServer &
+$ elbe setrepo --initvmpath=/ --targetpath=/ source.xml LOCALMACHINE:8000
+------------
+
+
+ELBE
+----
+Part of the linkgit:elbe[1] suite
diff --git a/elbepack/commands/setrepo.py b/elbepack/commands/setrepo.py
new file mode 100644
index 00000000..8e0665d2
--- /dev/null
+++ b/elbepack/commands/setrepo.py
@@ -0,0 +1,57 @@
+# ELBE - Debian Based Embedded Rootfilesystem Builder
+# Copyright (c) 2016-2017 Manuel Traut <manut at linutronix.de>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+from __future__ import print_function
+
+import sys
+
+from elbepack.elbexml import ElbeXML
+from optparse import OptionParser
+
+
+def run_command(argv):
+
+    oparser = OptionParser(
+            usage="usage: %prog setrepo [options] <xmlfile> <host>")
+    oparser.add_option("--initvmpath", help="path for initvm mirror",
+                       dest="initvmpath", default="debian")
+    oparser.add_option("--targetpath", help="path for target mirror",
+                       dest="targetpath", default="debian")
+    oparser.add_option("--protocol", help="protocol to access the repo",
+                       dest="protocol", default="http")
+    oparser.add_option("--no-dsc-on-mirror", action="store_true",
+                       help="mirror doesn't contain debian src packages",
+                       dest="nodsc", default=False)
+    oparser.add_option("--auth", help="don't set the noauth flag",
+                       dest="auth", default=False, action="store_true")
+    (opt, args) = oparser.parse_args(argv)
+
+    if len(args) < 2:
+        print("Wrong number of arguments")
+        oparser.print_help()
+        sys.exit(20)
+
+    try:
+        xml = ElbeXML(args[0])
+    except Exception as e:
+        print("Error reading xml file: %s" % str(e))
+        sys.exit(20)
+
+    try:
+        xml.set_repo(args[1],
+                     opt.initvmpath,
+                     opt.targetpath,
+                     opt.protocol,
+                     opt.auth,
+                     not opt.nodsc)
+    except Exception as e:
+        print("Error setting repo %s: %s" % (args[1], str(e)))
+        sys.exit(20)
+
+    try:
+        xml.xml.write(args[0])
+    except BaseException:
+        print("Unable to write new xml file")
+        sys.exit(20)
diff --git a/elbepack/elbexml.py b/elbepack/elbexml.py
index 4eb26b9f..d935f4f2 100644
--- a/elbepack/elbexml.py
+++ b/elbepack/elbexml.py
@@ -119,6 +119,39 @@ class ElbeXML(object):
 
         return mirror.replace("LOCALMACHINE", "10.0.2.2")
 
+    def _set_repo(self, project, mirror, path, proto='http', auth=False, src=True):
+        m = project.node("mirror")
+        m.clear() # this also clears url-list
+        h = m.ensure_child("primary_host")
+        h.set_text(mirror)
+        p = m.ensure_child("primary_path")
+        p.set_text(path)
+        x = m.ensure_child("primary_proto")
+        x.set_text(proto)
+        if not auth:
+            project.ensure_child("noauth")
+        if src:
+            m.ensure_child("url-list")
+            ul = m.node("url-list")
+            ul.ensure_child("url")
+            url = ul.node("url")
+            url.ensure_child("source")
+            s = url.node("source")
+            s.set_text("%s://%s/%s %s main" % (proto,
+                                               mirror,
+                                               path,
+                                               project.text("suite")))
+
+    def set_repo(self, mirror, inintvmpath, targetpath, proto='http',
+                 auth=False, src=True):
+
+        i = self.node("initvm")
+        if i:
+            self._set_repo(i, mirror, inintvmpath, proto, auth)
+        t = self.prj
+        if t:
+            self._set_repo(t, mirror, targetpath, proto, auth, src)
+
     # XXX: maybe add cdrom path param ?
     def create_apt_sources_list(self, build_sources=False):
         if self.prj is None:
-- 
2.19.0.rc2




More information about the elbe-devel mailing list