[libvirt] [jenkins-ci PATCH 2/8] lcitool: Stub out Python implementation

Andrea Bolognani abologna at redhat.com
Wed Jul 11 15:54:30 UTC 2018


Doesn't do much right now, but it's a start :)

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 guests/lcitool | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100755 guests/lcitool

diff --git a/guests/lcitool b/guests/lcitool
new file mode 100755
index 0000000..1cba8ad
--- /dev/null
+++ b/guests/lcitool
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+# lcitool - libvirt CI guest management tool
+# Copyright (C) 2017-2018  Andrea Bolognani <abologna at redhat.com>
+#
+# This program 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 2 of the License, or (at your
+# option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import argparse
+import sys
+import textwrap
+
+# This is necessary to maintain Python 2.7 compatibility
+try:
+    import configparser
+except ImportError:
+    import ConfigParser as configparser
+
+class Error(Exception):
+
+    def __init__(self, message):
+        self.message = message
+
+class Application:
+
+    def __init__(self):
+        self._parser = argparse.ArgumentParser(
+            conflict_handler = "resolve",
+            formatter_class = argparse.RawDescriptionHelpFormatter,
+            description = "libvirt CI guest management tool",
+            epilog = textwrap.dedent("""
+                supported actions:
+                """),
+        )
+        self._parser.add_argument(
+            "-a",
+            metavar = "ACTION",
+            required = True,
+            help = "action to perform (see below)",
+        )
+
+    def run(self):
+        cmdline = self._parser.parse_args()
+        action = cmdline.a
+
+        method = "_action_{}".format(action.replace("-", "_"))
+
+        if hasattr(self, method):
+            getattr(self, method).__call__()
+        else:
+            raise Error("Invalid action '{}'".format(action))
+
+if __name__ == "__main__":
+    try:
+        Application().run()
+    except Error as e:
+        sys.stderr.write("{}: {}\n".format(sys.argv[0], e.message))
+        sys.exit(1)
-- 
2.17.1




More information about the libvir-list mailing list