[elbe-devel] [PATCH 1/4] setrepo: initial version
Manuel Traut
manut at linutronix.de
Mon Jul 23 15:49:54 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 | 65 ++++++++++++++++++++++++++++++++++++
elbepack/commands/setrepo.py | 53 +++++++++++++++++++++++++++++
elbepack/elbexml.py | 19 +++++++++++
4 files changed, 138 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..ea357a9e
--- /dev/null
+++ b/docs/elbe-setrepo.txt
@@ -0,0 +1,65 @@
+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.
+
+<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..63873f87
--- /dev/null
+++ b/elbepack/commands/setrepo.py
@@ -0,0 +1,53 @@
+# 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("--auth", help="don't set the noauth flag",
+ dest="auth", default=False)
+ (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)
+ 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 cf117dc6..b19eef87 100644
--- a/elbepack/elbexml.py
+++ b/elbepack/elbexml.py
@@ -117,6 +117,25 @@ class ElbeXML(object):
return mirror.replace("LOCALMACHINE", "10.0.2.2")
+ def _set_repo(self, m, mirror, path, proto='http'):
+ 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)
+
+ def set_repo(self, mirror, inintvmpath, targetpath, proto='http', auth=False):
+ i = self.node("initvm/mirror")
+ if i:
+ self._set_repo(i, mirror, inintvmpath, proto)
+ t = self.prj.node("mirror")
+ if t:
+ self._set_repo(t, mirror, targetpath, proto)
+ if not auth:
+ self.prj.ensure_child("noauth")
+
# XXX: maybe add cdrom path param ?
def create_apt_sources_list(self, build_sources=False):
if self.prj is None:
--
2.18.0
More information about the elbe-devel
mailing list