[elbe-devel] [PATCH 1/3] Add elbe prjrepo list_packages command to view the content of project repository
Philipp Arras
philipp.arras at linutronix.de
Fri May 5 16:40:13 CEST 2017
In order to view the packages available in the repository in project directory
enter `elbe prjrepo list_packages <build_dir>`. It will display the content of
<build_dir>/repo/pool/main.
Signed-off-by: Philipp Arras <philipp.arras at linutronix.de>
---
elbepack/commands/prjrepo.py | 164 +++++++++++++++++++++++++++++++++++++++++
elbepack/daemons/soap/esoap.py | 10 +++
elbepack/soapclient.py | 32 ++++++++
3 files changed, 206 insertions(+)
create mode 100755 elbepack/commands/prjrepo.py
diff --git a/elbepack/commands/prjrepo.py b/elbepack/commands/prjrepo.py
new file mode 100755
index 0000000..f78fcc0
--- /dev/null
+++ b/elbepack/commands/prjrepo.py
@@ -0,0 +1,164 @@
+#!/usr/bin/env python
+#
+# ELBE - Debian Based Embedded Rootfilesystem Builder
+# Copyright (C) 2017 Linutronix GmbH
+#
+# This file is part of ELBE.
+#
+# ELBE is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ELBE is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ELBE. If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import print_function
+
+import socket
+import sys
+
+from optparse import (OptionParser, OptionGroup)
+from suds import WebFault
+from urllib2 import URLError
+from httplib import BadStatusLine
+
+from elbepack.soapclient import RepoAction, ElbeSoapClient
+from elbepack.version import elbe_version
+from elbepack.config import cfg
+
+from elbepack.elbexml import ValidationMode
+
+
+def run_command(argv):
+ oparser = OptionParser(usage="usage: elbe prjrepo [options] <command>")
+
+ oparser.add_option("--project", dest="project", default=None,
+ help="project directory on the initvm")
+
+ oparser.add_option("--host", dest="host", default="localhost",
+ help="Ip or hostname of elbe-daemon.")
+
+ oparser.add_option("--port", dest="port", default=cfg['soapport'],
+ help="Port of soap itf on elbe-daemon.")
+
+ oparser.add_option("--pass", dest="passwd", default="foo",
+ help="Password (default is foo).")
+
+ oparser.add_option("--user", dest="user", default="root",
+ help="Username (default is root).")
+
+ oparser.add_option(
+ "--retries",
+ dest="retries",
+ default="10",
+ help="How many times to retry the connection to the server before\
+ giving up (default is 10 times, yielding 10 seconds).")
+
+ oparser.add_option("--output",
+ dest="output", default=None,
+ help="Output files to <directory>")
+
+ devel = OptionGroup(
+ oparser,
+ "options for elbe developers",
+ "Caution: Don't use these options in a productive environment")
+ devel.add_option("--skip-urlcheck", action="store_true",
+ dest="url_validation", default=ValidationMode.CHECK_ALL,
+ help="Skip URL Check inside initvm")
+
+ devel.add_option("--debug", action="store_true",
+ dest="debug", default=False,
+ help="Enable debug mode.")
+
+ devel.add_option("--ignore-version-diff", action="store_true",
+ dest="ignore_version", default=False,
+ help="allow different elbe version on host and initvm")
+ oparser.add_option_group(devel)
+
+ (opt, args) = oparser.parse_args(sys.argv)
+ args = args[2:]
+
+ if len(args) < 1:
+ print ('elbe prjrepo - no subcommand given', file=sys.stderr)
+ RepoAction.print_actions()
+ return
+
+ # Try to connect to initvm via SOAP
+ try:
+ control = ElbeSoapClient(
+ opt.host,
+ opt.port,
+ opt.user,
+ opt.passwd,
+ debug=opt.debug,
+ retries=int(
+ opt.retries))
+ except socket.error as e:
+ print ("Failed to connect to Soap server %s:%s\n" %
+ (opt.host, opt.port), file=sys.stderr)
+ print ("", file=sys.stderr)
+ print (
+ "Check, wether the Soap Server is running inside the initvm",
+ file=sys.stderr)
+ print ("try 'elbe initvm attach'", file=sys.stderr)
+ sys.exit(10)
+ except URLError as e:
+ print ("Failed to connect to Soap server %s:%s\n" %
+ (opt.host, opt.port), file=sys.stderr)
+ print ("", file=sys.stderr)
+ print ("Check, wether the initvm is actually running.", file=sys.stderr)
+ print (
+ "try 'elbe initvm --directory /path/to/initvm start'",
+ file=sys.stderr)
+ sys.exit(10)
+ except BadStatusLine as e:
+ print ("Failed to connect to Soap server %s:%s\n" %
+ (opt.host, opt.port), file=sys.stderr)
+ print ("", file=sys.stderr)
+ print ("Check, wether the initvm is actually running.", file=sys.stderr)
+ print (
+ "try 'elbe initvm --directory /path/to/initvm start'",
+ file=sys.stderr)
+ sys.exit(10)
+
+ # Check whether subcommand exists
+ try:
+ action = RepoAction(args[0])
+ except KeyError:
+ print ('elbe prjrepo - unknown subcommand', file=sys.stderr)
+ RepoAction.print_actions()
+ sys.exit(20)
+
+ # Check elbe version
+ try:
+ v_server = control.service.get_version()
+ if v_server != elbe_version:
+ print ("elbe v%s is used in initvm, this is not compatible with \
+elbe v%s that is used on this machine. Please install same \
+versions of elbe in initvm and on your machine." % (v_server, elbe_version))
+ if not (opt.ignore_version):
+ sys.exit(20)
+ except AttributeError:
+ print ("the elbe installation inside the initvm doesn't provide a \
+get_version interface. Please create a new initvm or upgrade \
+elbe inside the existing initvm.")
+ if not (opt.ignore_version):
+ sys.exit(20)
+
+ # Execute command
+ try:
+ action.execute(control, opt, args[1:])
+ except WebFault as e:
+ print ('Server returned error:', file=sys.stderr)
+ print ('', file=sys.stderr)
+ if hasattr(e.fault, 'faultstring'):
+ print (e.fault.faultstring, file=sys.stderr)
+ else:
+ print (e, file=sys.stderr)
+ sys.exit(5)
diff --git a/elbepack/daemons/soap/esoap.py b/elbepack/daemons/soap/esoap.py
index a74e35c..5c7fd24 100644
--- a/elbepack/daemons/soap/esoap.py
+++ b/elbepack/daemons/soap/esoap.py
@@ -316,3 +316,13 @@ class ESoap (ServiceBase):
def rm_log (self, uid, builddir):
self.app.pm.open_project (uid, builddir)
self.app.pm.rm_log (uid, builddir)
+
+ @rpc(String, _returns=String)
+ @authenticated_uid
+ @soap_faults
+ def list_packages (self, uid, builddir):
+ s = ''
+ for root, dirnames, filenames in os.walk(os.path.join(builddir, "repo/pool/main")):
+ for filename in fnmatch.filter(filenames, '*.deb'):
+ s += filename +'\n'
+ return s
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index a04aca4..5bcf29a 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -592,3 +592,35 @@ class BuildPbuilderAction(ClientAction):
ClientAction.register(BuildPbuilderAction)
+
+class RepoAction(ClientAction):
+ repoactiondict = {}
+ @classmethod
+ def register(cls, action):
+ cls.repoactiondict[action.tag] = action
+ @classmethod
+ def print_actions(cls):
+ print ('available subcommands are:', file=sys.stderr)
+ for a in cls.repoactiondict:
+ print (' ' + a, file=sys.stderr)
+ def __new__(cls, node):
+ action = cls.repoactiondict[node]
+ return object.__new__(action)
+
+
+class ListPackagesAction(RepoAction):
+
+ tag = 'list_packages'
+
+ def __init__(self, node):
+ RepoAction.__init__(self, node)
+
+ def execute(self, client, opt, args):
+ if len (args) != 1:
+ print ("usage: elbe prjrepo list_packages <project_dir>", file=sys.stderr)
+ sys.exit(20)
+
+ builddir = args[0]
+ print(client.service.list_packages (builddir))
+
+RepoAction.register(ListPackagesAction)
--
2.1.4
More information about the elbe-devel
mailing list