From 0b58badfc1c2f904b7e3ca95aabd1609e5cf2834 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Tue, 1 Oct 2013 08:28:15 -0400 Subject: [PATCH] Storage debug and scratch files in ~/.cache/virt-manager (bz 693028) --- man/virt-clone.pod | 4 ++-- man/virt-install.pod | 4 ++-- man/virt-manager.pod | 2 +- virtinst/cli.py | 6 +----- virtinst/util.py | 18 +++++++++++++++++- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/man/virt-clone.pod b/man/virt-clone.pod index cb2afa53f..424a8d915 100644 --- a/man/virt-clone.pod +++ b/man/virt-clone.pod @@ -144,8 +144,8 @@ cloning the original guest. =item -d, --debug Print debugging information to the terminal when running the install process. -The debugging information is also stored in C<$HOME/.virtinst/virt-clone.log> -even if this parameter is omitted. +The debugging information is also stored in +C<~/.cache/virt-manager/virt-clone.log> even if this parameter is omitted. =back diff --git a/man/virt-install.pod b/man/virt-install.pod index 3d5651a80..74caf0218 100644 --- a/man/virt-install.pod +++ b/man/virt-install.pod @@ -1346,8 +1346,8 @@ Only print fatal error messages. =item -d, --debug Print debugging information to the terminal when running the install process. -The debugging information is also stored in C<$HOME/.virtinst/virt-install.log> -even if this parameter is omitted. +The debugging information is also stored in +C<~/.cache/virt-manager/virt-install.log> even if this parameter is omitted. =back diff --git a/man/virt-manager.pod b/man/virt-manager.pod index ca6a7920f..4f021c1d0 100644 --- a/man/virt-manager.pod +++ b/man/virt-manager.pod @@ -37,7 +37,7 @@ Specify the hypervisor connection C =item --debug List debugging output to the console (normally this is only logged in -~/.virt-manager/virt-manager.log). This function implies --no-fork. +~/.cache/virt-manager/virt-manager.log). This function implies --no-fork. =item --no-fork diff --git a/virtinst/cli.py b/virtinst/cli.py index 2c0775e1c..6b14e6838 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -147,11 +147,7 @@ def setupLogging(appname, debug_stdout, do_quiet, cli_app=True): global quiet quiet = do_quiet - dirname = "~/.virtinst" - if appname == "virt-manager": - dirname = "~/.virt-manager" - - vi_dir = os.path.expanduser(dirname) + vi_dir = util.get_cache_dir() if not os.access(vi_dir, os.W_OK): if os.path.exists(vi_dir): raise RuntimeError("No write access to directory %s" % vi_dir) diff --git a/virtinst/util.py b/virtinst/util.py index 1bc368128..c5a67d06b 100644 --- a/virtinst/util.py +++ b/virtinst/util.py @@ -479,7 +479,7 @@ def make_scratchdir(conn, hvtype): if (not scratch or not os.path.exists(scratch) or not os.access(scratch, os.W_OK)): - scratch = os.path.expanduser("~/.virtinst/boot") + scratch = os.path.join(get_cache_dir(), "boot") if not os.path.exists(scratch): os.makedirs(scratch, 0751) @@ -500,3 +500,19 @@ def pretty_bytes(val): return "%2.2f GB" % (val / (1024.0 * 1024.0 * 1024.0)) else: return "%2.2f MB" % (val / (1024.0 * 1024.0)) + + +def get_cache_dir(): + ret = "" + try: + # We don't want to depend on glib for virt-install + from gi.repository import GLib # pylint: disable=E0611 + ret = GLib.get_user_cache_dir() + except ImportError: + pass + + if not ret: + ret = os.environ.get("XDG_CACHE_HOME") + if not ret: + ret = os.path.expanduser("~/.cache") + return os.path.join(ret, "virt-manager")