[virt-tools-list] [PATCH-v5.5 3/5] make wrapper executables work

Gene Czarcinski gene at czarc.net
Tue Apr 9 19:19:00 UTC 2013


1. Add virtcli to data_files[]

2. Add code to wrapper created in my_build() to determine
the directory the wrapper script is located and then
execute the python program which is located relative
to that directory.  For real system installs, this
directory will be "/usr/bin".

3. Update virt-manager.spec for the virtcli directory.
.
Signed-off-by: Gene Czarcinski <gene at czarc.net>
---
 setup.py          | 18 ++++++++++++++++--
 virt-manager.spec |  1 +
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index e98561e..6186316 100644
--- a/setup.py
+++ b/setup.py
@@ -81,10 +81,23 @@ class my_build(build_extra):
             os.mkdir("build")
 
         for app in cmds:
-            sharepath = os.path.join(cliconfig.asset_dir, app)
+            sharepath = os.path.join("../share/virt-manager", app)
 
             wrapper = "#!/bin/sh\n\n"
-            wrapper += "exec \"%s\" \"$@\"" % (sharepath)
+            wrapper += """
+SOURCE=\"${BASH_SOURCE[0]}\"
+# resolve $SOURCE until the file is no longer a symlink
+while [ -h \"$SOURCE\" ]; do
+  DIR=\"$( cd -P \"$( dirname \"$SOURCE\" )\" && pwd )\"
+  SOURCE=\"$(readlink \"$SOURCE\")\"
+     # if $SOURCE was a relative symlink, we need to resolve it
+     # relative to the path where the symlink file was located
+  [[ $SOURCE != /* ]] && SOURCE=\"$DIR/$SOURCE\"
+done
+DIR=\"$( cd -P \"$( dirname \"$SOURCE\" )\" && pwd )\"
+
+"""
+            wrapper += "exec \"$DIR/%s\" \"$@\"" % (sharepath)
 
             newpath = os.path.abspath(os.path.join("build", app))
             print "Generating %s" % newpath
@@ -407,6 +420,7 @@ setup(
 
         ("share/virt-manager/virtManager", glob.glob("virtManager/*.py")),
 
+        ("share/virt-manager/virtcli", glob.glob("virtcli/*.py")),
         ("share/virt-manager/virtinst", glob.glob("virtinst/*.py")),
         ("share/virt-manager/virtconv", glob.glob("virtconv/*.py")),
         ("share/virt-manager/virtconv/parsers",
diff --git a/virt-manager.spec b/virt-manager.spec
index 7a36545..841172c 100644
--- a/virt-manager.spec
+++ b/virt-manager.spec
@@ -277,6 +277,7 @@ update-desktop-database -q %{_datadir}/applications
 %{_mandir}/man1/%{name}.1*
 
 %{_datadir}/%{name}/ui/*.ui
+%{_datadir}/%{name}/virtcli/*
 %{_datadir}/%{name}/%{name}
 
 %{_datadir}/%{name}/icons
-- 
1.8.1.4




More information about the virt-tools-list mailing list