[virt-tools-list] [virt-manager] [PATCH v2 10/10] setup.py: Install the bash completion files

Lin Ma lma at suse.com
Fri Dec 7 08:28:56 UTC 2018


Signed-off-by: Lin Ma <lma at suse.com>
---
 setup.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/setup.py b/setup.py
index 658e6503..2d3446cd 100755
--- a/setup.py
+++ b/setup.py
@@ -20,6 +20,13 @@ import distutils.dist
 import distutils.log
 import distutils.sysconfig
 
+from subprocess import getstatusoutput
+
+def bash_completion_dir():
+    (sts, output) = getstatusoutput(
+        'pkg-config --variable=completionsdir bash-completion')
+    return output if not sts and output else '/etc/bash_completion.d'
+
 if sys.version_info.major < 3:
     print("virt-manager is python3 only. Run this as ./setup.py")
     sys.exit(1)
@@ -218,10 +225,29 @@ class my_build(distutils.command.build.build):
                 self.distribution.data_files.append((dest, icons))
 
 
+    def _make_bash_completion_files(self):
+        scripts = ["virt-install", "virt-clone", "virt-convert", "virt-xml"]
+        path ="data/bash-completion"
+        for script in scripts:
+            print("Generating %s/%s" % (path, script))
+            ret = os.system('cp -f '
+                            '%s/virtmanager %s/%s' % (path, path, script))
+            if ret != 0:
+                raise RuntimeError("Copying template file "
+                                   "%s/virtmanager to %s/%s' failed."
+                                   % (path, path, script))
+
+            ret = os.system('sed -i s/virtmanager/%s/ %s/%s'
+                            % (script, path, script))
+            if ret != 0:
+                raise RuntimeError("Updating %s/%s' failed." % (path, script))
+
+
     def run(self):
         self._make_bin_wrappers()
         self._make_man_pages()
         self._build_icons()
+        self._make_bash_completion_files()
 
         self.run_command("build_i18n")
         distutils.command.build.build.run(self)
@@ -663,6 +689,7 @@ distutils.core.setup(
         ("share/virt-manager/virtinst/devices", glob.glob("virtinst/devices/*.py")),
         ("share/virt-manager/virtinst/domain", glob.glob("virtinst/domain/*.py")),
         ("share/virt-manager/virtconv", glob.glob("virtconv/*.py")),
+        (bash_completion_dir(), glob.glob("data/bash-completion/virt-*")),
     ],
 
     cmdclass={
-- 
2.16.2




More information about the virt-tools-list mailing list