[virt-tools-list] [PATCH 4/5] make executables work

Martin Kletzander mkletzan at redhat.com
Tue Apr 9 07:18:18 UTC 2013


On 04/08/2013 05:28 PM, Gene Czarcinski wrote:
> 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 releative

s/releative/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          | 15 +++++++++++++--
>  virt-manager.spec |  1 +
>  2 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/setup.py b/setup.py
> index e98561e..3a51e22 100644
> --- a/setup.py
> +++ b/setup.py
> @@ -81,10 +81,20 @@ 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]}\"\n"
> +            wrapper += " # resolve $SOURCE until the file is no longer a symlink\n"
> +            wrapper += "while [ -h \"$SOURCE\" ]; do\n"
> +            wrapper += "  DIR=\"$( cd -P \"$( dirname \"$SOURCE\" )\" && pwd )\"\n"
> +            wrapper += "  SOURCE=\"$(readlink \"$SOURCE\")\"\n"
> +            wrapper += "     # if $SOURCE was a relative symlink, we need to resolve it\n"
> +            wrapper += "     # relative to the path where the symlink file was located\n"
> +            wrapper += "  [[ $SOURCE != /* ]] && SOURCE=\"$DIR/$SOURCE\"\n"
> +            wrapper += "done\n"
> +            wrapper += "DIR=\"$( cd -P \"$( dirname \"$SOURCE\" )\" && pwd )\"\n\n"
> +            wrapper += "exec \"$DIR/%s\" \"$@\"" % (sharepath)
>  

Using r"unescaped string" would make the wrapper script more readable,
even better would be using triple quotation marks.

Other than that, it looks ok.

Martin




More information about the virt-tools-list mailing list