mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
util: Move get_cache_dir to VirtinstConnection
Renaming it get_app_cache_dir so it doesn't conflict with get_cache_dir usage in virtManager
This commit is contained in:
parent
e6262435d6
commit
c2de4d7c36
@ -14,7 +14,6 @@ import libvirt
|
||||
|
||||
import virtinst
|
||||
from virtinst import pollhelpers
|
||||
from virtinst import util
|
||||
|
||||
from . import connectauth
|
||||
from .baseclass import vmmGObject
|
||||
@ -356,7 +355,7 @@ class vmmConnection(vmmGObject):
|
||||
|
||||
def get_cache_dir(self):
|
||||
uri = self.get_uri().replace("/", "_")
|
||||
ret = os.path.join(util.get_cache_dir(), uri)
|
||||
ret = os.path.join(self._backend.get_app_cache_dir(), uri)
|
||||
if not os.path.exists(ret):
|
||||
os.makedirs(ret, 0o755)
|
||||
return ret
|
||||
|
@ -3,14 +3,14 @@
|
||||
# This work is licensed under the GNU GPLv2 or later.
|
||||
# See the COPYING file in the top-level directory.
|
||||
|
||||
# pylint: disable=wrong-import-position
|
||||
|
||||
import gi
|
||||
gi.require_version('Libosinfo', '1.0')
|
||||
|
||||
from virtcli import CLIConfig as _CLIConfig
|
||||
|
||||
|
||||
# pylint: disable=wrong-import-position
|
||||
|
||||
def _setup_i18n():
|
||||
import gettext
|
||||
import locale
|
||||
|
@ -23,6 +23,7 @@ import libvirt
|
||||
from virtcli import CLIConfig
|
||||
|
||||
from . import util
|
||||
from .connection import VirtinstConnection
|
||||
from .devices import (Device, DeviceController, DeviceDisk, DeviceGraphics,
|
||||
DeviceInterface, DevicePanic)
|
||||
from .nodedev import NodeDevice
|
||||
@ -125,7 +126,7 @@ def setupLogging(appname, debug_stdout, do_quiet, cli_app=True):
|
||||
vi_dir = None
|
||||
logfile = None
|
||||
if not in_testsuite():
|
||||
vi_dir = util.get_cache_dir()
|
||||
vi_dir = VirtinstConnection.get_app_cache_dir()
|
||||
logfile = os.path.join(vi_dir, appname + ".log")
|
||||
|
||||
try:
|
||||
@ -210,8 +211,6 @@ def in_testsuite():
|
||||
##############################
|
||||
|
||||
def getConnection(uri):
|
||||
from .connection import VirtinstConnection
|
||||
|
||||
logging.debug("Requesting libvirt URI %s", (uri or "default"))
|
||||
conn = VirtinstConnection(uri)
|
||||
conn.open(_openauth_cb, None)
|
||||
|
@ -5,6 +5,7 @@
|
||||
# See the COPYING file in the top-level directory.
|
||||
|
||||
import logging
|
||||
import os
|
||||
import weakref
|
||||
|
||||
import libvirt
|
||||
@ -40,6 +41,22 @@ class VirtinstConnection(object):
|
||||
def libvirt_new_enough_for_virtmanager(version):
|
||||
return _real_local_libvirt_version() >= version
|
||||
|
||||
@staticmethod
|
||||
def get_app_cache_dir():
|
||||
ret = ""
|
||||
try:
|
||||
# We don't want to depend on glib for virt-install
|
||||
from gi.repository import GLib
|
||||
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")
|
||||
|
||||
def __init__(self, uri):
|
||||
_initial_uri = uri or ""
|
||||
|
||||
|
@ -11,7 +11,6 @@ import logging
|
||||
|
||||
from . import progress
|
||||
from . import unattended
|
||||
from . import util
|
||||
from .devices import DeviceDisk
|
||||
from .domain import DomainOs
|
||||
from .osdict import OSDB, OsMedia
|
||||
@ -230,12 +229,13 @@ class Installer(object):
|
||||
osmedia = OsMedia(osguess[1])
|
||||
script = unattended.prepare_install_script(
|
||||
guest, self._unattended_data, self.cdrom, osmedia)
|
||||
path, _ = unattended.generate_install_script(script)
|
||||
path, _ = unattended.generate_install_script(guest, script)
|
||||
logging.debug("Generated unattended script: %s", path)
|
||||
logging.debug("Generated script contents:\n%s",
|
||||
open(path).read())
|
||||
|
||||
iso = perform_cdrom_injections([path], util.get_cache_dir())
|
||||
iso = perform_cdrom_injections([path],
|
||||
guest.conn.get_app_cache_dir())
|
||||
self._add_unattended_install_cdrom_device(guest, iso)
|
||||
|
||||
self._unattended_files.extend([path, iso])
|
||||
|
@ -11,7 +11,6 @@ from . import progress
|
||||
from . import unattended
|
||||
from . import urldetect
|
||||
from . import urlfetcher
|
||||
from . import util
|
||||
from .devices import DeviceDisk
|
||||
from .initrdinject import perform_initrd_injections
|
||||
from .kernelupload import upload_kernel_initrd
|
||||
@ -87,7 +86,8 @@ class InstallerTreeMedia(object):
|
||||
Determine the scratchdir for this URI, create it if necessary.
|
||||
scratchdir is the directory that's accessible by VMs
|
||||
"""
|
||||
user_scratchdir = os.path.join(util.get_cache_dir(), "boot")
|
||||
user_scratchdir = os.path.join(
|
||||
guest.conn.get_app_cache_dir(), "boot")
|
||||
system_scratchdir = InstallerTreeMedia.get_system_scratchdir(guest)
|
||||
|
||||
# If we are a session URI, or we don't have access to the system
|
||||
@ -218,7 +218,7 @@ class InstallerTreeMedia(object):
|
||||
location = self.location if self._media_type == MEDIA_URL else None
|
||||
script = unattended.prepare_install_script(
|
||||
guest, self._unattended_data, location, cache.os_media)
|
||||
path, cmdline = unattended.generate_install_script(script)
|
||||
path, cmdline = unattended.generate_install_script(guest, script)
|
||||
|
||||
logging.debug("Generated unattended cmdline: %s", cmdline)
|
||||
logging.debug("Generated unattended script: %s", path)
|
||||
|
@ -14,8 +14,6 @@ from gi.repository import Libosinfo
|
||||
from gi.repository import Gio
|
||||
from gi.repository import GLib
|
||||
|
||||
from . import util
|
||||
|
||||
|
||||
def _make_installconfig(script, osobj, unattended_data, arch, hostname, url):
|
||||
"""
|
||||
@ -262,8 +260,8 @@ def prepare_install_script(guest, unattended_data, url=None, os_media=None):
|
||||
return script
|
||||
|
||||
|
||||
def generate_install_script(script):
|
||||
scratch = tempfile.mktemp(dir=util.get_cache_dir())
|
||||
def generate_install_script(guest, script):
|
||||
scratch = tempfile.mktemp(dir=guest.conn.get_app_cache_dir())
|
||||
if not os.path.exists(scratch):
|
||||
os.makedirs(scratch, 0o751)
|
||||
|
||||
|
@ -9,8 +9,6 @@ import logging
|
||||
import re
|
||||
import urllib.parse
|
||||
|
||||
from .cli import parse_optstr_tuples
|
||||
|
||||
|
||||
def sanitize_xml_for_test_define(xml):
|
||||
import difflib
|
||||
@ -129,6 +127,8 @@ class MagicURI(object):
|
||||
if not self.uri_is_magic(uri):
|
||||
raise RuntimeError("uri=%s is not virtinst magic URI" % uri)
|
||||
|
||||
from .cli import parse_optstr_tuples
|
||||
|
||||
uri = uri.replace(self.VIRTINST_URI_MAGIC_PREFIX, "")
|
||||
ret = uri.split(",", 1)
|
||||
self.open_uri = ret[0]
|
||||
|
@ -5,8 +5,6 @@
|
||||
# See the COPYING file in the top-level directory.
|
||||
#
|
||||
|
||||
import os
|
||||
|
||||
import libvirt
|
||||
|
||||
|
||||
@ -118,22 +116,6 @@ def xml_escape(xml):
|
||||
return xml
|
||||
|
||||
|
||||
def get_cache_dir():
|
||||
ret = ""
|
||||
try:
|
||||
# We don't want to depend on glib for virt-install
|
||||
from gi.repository import GLib
|
||||
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")
|
||||
|
||||
|
||||
def get_prop_path(obj, prop_path):
|
||||
"""Return value of attribute identified by `prop_path`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user