Re: [PATCH] virt-manager: Make virt-manager remember last image directory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
this is new version of my patch so please check.

Thanks,
Michal

On 06/22/2009 12:15 PM, Michal Novotny wrote:
Hi,
I've modified my patch to match those requirements and hopefully they're already met now so please review this patch. In addition to saving those 5 directories (for image/media/save/restore and screenshot files) I found a bug that prevented showing existing PNG files in folders when saving screenshots and that has been fixed too (simple fix by changing "*.png" mask to "png" only because of asterisk and dot appended by util.browse_local() function itself).

Thanks,
Michal

On 06/19/2009 03:39 PM, Cole Robinson wrote:
On 06/18/2009 12:22 PM, Michal Novotny wrote:
  
# HG changeset patch
# User Michal Novotny <minovotn@xxxxxxxxxx>
# Date 1245341781 -7200
# Node ID b599a65ca0615704a47e38eabcd2ff0947bcbaec
# Parent  a996e00b3bb6a99fdf9505c053bc1f6bee532d3b
Make virt-manager remember last used paths

This patch makes virt-manager remember last used paths for disk images, saved
snapshots, restored snapshots, media paths and also screenshot paths not to
bother users with changing paths from the default location per HV technology.
Useful when installing multiple domains and having all the media/image files
in non-default locations.

    

  
...


_______________________________________________ et-mgmt-tools mailing list et-mgmt-tools@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/et-mgmt-tools

# HG changeset patch
# User Michal Novotny <minovotn@xxxxxxxxxx>
# Date 1245737179 -7200
# Node ID 7800fad8b767b020cbddaa34da11bed6c25cb446
# Parent  2e0e047d21f0c5d936b157cbb20e221ca8d114de
Make virt-manager remember last used paths

This patch makes virt-manager remember last used paths for disk images, saved
snapshots, restored snapshots, media paths and also screenshot paths not to
bother users with changing paths from the default location per HV technology.
Useful when installing multiple domains and having all the media/image files
in non-default locations.

diff -r 2e0e047d21f0 -r 7800fad8b767 src/virt-manager.schemas.in
--- a/src/virt-manager.schemas.in	Mon Jun 22 14:24:09 2009 -0400
+++ b/src/virt-manager.schemas.in	Tue Jun 23 08:06:19 2009 +0200
@@ -272,5 +272,70 @@
         <long>Whether to install a sound device for remote VMs or not</long>
       </locale>
     </schema>
+
+    <schema>
+      <key>/schemas/apps/::PACKAGE::/paths/default-image-path</key>
+      <applyto>/apps/::PACKAGE::/paths/default-image-path</applyto>
+      <owner>::PACKAGE::</owner>
+      <type>string</type>
+      <default></default>
+
+      <locale name="C">
+        <short>Default image path</short>
+        <long>Default path for choosing VM images</long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/::PACKAGE::/paths/default-media-path</key>
+      <applyto>/apps/::PACKAGE::/paths/default-media-path</applyto>
+      <owner>::PACKAGE::</owner>
+      <type>string</type>
+      <default></default>
+
+      <locale name="C">
+        <short>Default media path</short>
+        <long>Default path for choosing media</long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/::PACKAGE::/paths/default-save-path</key>
+      <applyto>/apps/::PACKAGE::/paths/default-save-path</applyto>
+      <owner>::PACKAGE::</owner>
+      <type>string</type>
+      <default></default>
+
+      <locale name="C">
+        <short>Default save domain path</short>
+        <long>Default path for saving VM snaphots</long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/::PACKAGE::/paths/default-restore-path</key>
+      <applyto>/apps/::PACKAGE::/paths/default-restore-path</applyto>
+      <owner>::PACKAGE::</owner>
+      <type>string</type>
+      <default></default>
+
+      <locale name="C">
+        <short>Default restore path</short>
+        <long>Default path for stored VM snapshots</long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/::PACKAGE::/paths/default-screenshot-path</key>
+      <applyto>/apps/::PACKAGE::/paths/default-screenshot-path</applyto>
+      <owner>::PACKAGE::</owner>
+      <type>string</type>
+      <default></default>
+
+      <locale name="C">
+        <short>Default screenshot path</short>
+        <long>Default path for saving screenshots from VMs</long>
+      </locale>
+    </schema>
   </schemalist>
 </gconfschemafile>
diff -r 2e0e047d21f0 -r 7800fad8b767 src/virtManager/addhardware.py
--- a/src/virtManager/addhardware.py	Mon Jun 22 14:24:09 2009 -0400
+++ b/src/virtManager/addhardware.py	Tue Jun 23 08:06:19 2009 +0200
@@ -701,14 +701,15 @@
 
         conn = self.vm.get_connection()
         if self.storage_browser == None:
-            self.storage_browser = vmmStorageBrowser(self.config, conn)
+            self.storage_browser = vmmStorageBrowser(self.config, conn, False)
         if self._browse_cb_id:
             self.storage_browser.disconnect(self._browse_cb_id)
 
         self._browse_cb_id = self.storage_browser.connect("storage-browse-finish", set_storage_cb)
         self.storage_browser.local_args = { "dialog_name": dialog_name,
-                                            "start_folder": folder,
-                                            "confirm_func": confirm_func, }
+                                            "confirm_func": confirm_func,
+                                            "browse_reason":
+                                                  self.config.CONFIG_DIR_IMAGE }
         self.storage_browser.show(conn)
         return None
 
diff -r 2e0e047d21f0 -r 7800fad8b767 src/virtManager/choosecd.py
--- a/src/virtManager/choosecd.py	Mon Jun 22 14:24:09 2009 -0400
+++ b/src/virtManager/choosecd.py	Tue Jun 23 08:06:19 2009 +0200
@@ -149,11 +149,13 @@
 
     def _browse_file(self, dialog_name):
         if self.storage_browser == None:
-            self.storage_browser = vmmStorageBrowser(self.config, self.conn)
-                                                     #self.topwin)
+            self.storage_browser = vmmStorageBrowser(self.config, self.conn,
+                                                     True)
             self.storage_browser.connect("storage-browse-finish",
                                          self.set_storage_path)
-        self.storage_browser.local_args = { "dialog_name": dialog_name }
+        self.storage_browser.local_args = { "dialog_name": dialog_name,
+                                            "browse_reason":
+                                                 self.config.CONFIG_DIR_MEDIA }
         self.storage_browser.show(self.conn)
         return None
 
diff -r 2e0e047d21f0 -r 7800fad8b767 src/virtManager/config.py
--- a/src/virtManager/config.py	Mon Jun 22 14:24:09 2009 -0400
+++ b/src/virtManager/config.py	Tue Jun 23 08:06:19 2009 +0200
@@ -45,6 +45,13 @@
 
 class vmmConfig:
 
+    # GConf directory names for saving last used paths
+    CONFIG_DIR_IMAGE = "image"
+    CONFIG_DIR_MEDIA = "media"
+    CONFIG_DIR_SAVE = "save"
+    CONFIG_DIR_RESTORE = "restore"
+    CONFIG_DIR_SCREENSHOT = "screenshot"
+
     CONSOLE_SCALE_NEVER = 0
     CONSOLE_SCALE_FULLSCREEN = 1
     CONSOLE_SCALE_ALWAYS = 2
@@ -261,6 +268,36 @@
         self.conf.set_bool(self.conf_dir + "/vmlist-fields/network_traffic", state)
 
 
+    def get_default_directory(self, conn, _type):
+        if not _type:
+            logging.error("Unknown type for get_default_directory")
+            return
+
+        try:
+            path = self.conf.get_value(self.conf_dir + "/paths/default-%s-path"
+                                                                       % _type)
+        except:
+            path = None
+
+        if not path:
+            if (_type == self.CONFIG_DIR_IMAGE or
+                _type == self.CONFIG_DIR_MEDIA):
+                path = self.get_default_image_dir(conn)
+            if (_type == self.CONFIG_DIR_SAVE or
+                _type == self.CONFIG_DIR_RESTORE):
+                path = self.get_default_save_dir(conn)
+
+        logging.debug("get_default_directory(%s): returning %s" % (_type, path))
+        return path
+
+    def set_default_directory(self, folder, _type):
+        if not _type:
+            logging.error("Unknown type for set_default_directory")
+            return
+
+        logging.debug("set_default_directory(%s): saving %s" % (_type, folder))
+        self.conf.set_value(self.conf_dir + "/paths/default-%s-path" % _type,
+                                                                      folder)
 
     def on_vmlist_domain_id_visible_changed(self, callback):
         self.conf.notify_add(self.conf_dir + "/vmlist-fields/domain_id", callback)
diff -r 2e0e047d21f0 -r 7800fad8b767 src/virtManager/create.py
--- a/src/virtManager/create.py	Mon Jun 22 14:24:09 2009 -0400
+++ b/src/virtManager/create.py	Tue Jun 23 08:06:19 2009 +0200
@@ -996,7 +996,8 @@
 
     def browse_iso(self, ignore1=None, ignore2=None):
         self._browse_file(_("Locate ISO Image"),
-                          self.set_iso_storage_path)
+                          self.set_iso_storage_path,
+                          is_media=True)
         self.window.get_widget("install-local-box").activate()
 
     def toggle_enable_storage(self, src):
@@ -1004,7 +1005,8 @@
 
     def browse_storage(self, ignore1):
         self._browse_file(_("Locate existing storage"),
-                          self.set_disk_storage_path)
+                          self.set_disk_storage_path,
+                          is_media=False)
 
     def toggle_storage_select(self, src):
         act = src.get_active()
@@ -1648,13 +1650,20 @@
             logging.exception("Error detecting distro.")
             self.detectedDistro = (None, None)
 
-    def _browse_file(self, dialog_name, callback, folder=None):
+    def _browse_file(self, dialog_name, callback, folder=None, is_media=False):
         if self.storage_browser == None:
-            self.storage_browser = vmmStorageBrowser(self.config, self.conn)
+            self.storage_browser = vmmStorageBrowser(self.config, self.conn,
+                                                     is_media)
             self.storage_browser.connect("storage-browse-finish",
                                          callback)
+        if is_media:
+            reason = self.config.CONFIG_DIR_MEDIA
+        else:
+            reason = self.config.CONFIG_DIR_IMAGE
+
         self.storage_browser.local_args = { "dialog_name": dialog_name,
-                                            "start_folder": folder}
+                                            "start_folder": folder,
+                                            "browse_reason": reason}
         self.storage_browser.show(self.conn)
 
     def show_help(self, ignore):
diff -r 2e0e047d21f0 -r 7800fad8b767 src/virtManager/details.py
--- a/src/virtManager/details.py	Mon Jun 22 14:24:09 2009 -0400
+++ b/src/virtManager/details.py	Tue Jun 23 08:06:19 2009 +0200
@@ -1410,8 +1410,10 @@
         # user to choose what image format they'd like to save in....
         path = util.browse_local(self.window.get_widget("vmm-details"),
                                  _("Save Virtual Machine Screenshot"),
-                                 _type = ("*.png", "PNG files"),
-                                 dialog_type = gtk.FILE_CHOOSER_ACTION_SAVE)
+                                 self.config, self.vm.get_connection(),
+                                 _type = ("png", "PNG files"),
+                                 dialog_type = gtk.FILE_CHOOSER_ACTION_SAVE,
+                                 browse_reason=self.config.CONFIG_DIR_SCREENSHOT)
         if not path:
             return
 
diff -r 2e0e047d21f0 -r 7800fad8b767 src/virtManager/engine.py
--- a/src/virtManager/engine.py	Mon Jun 22 14:24:09 2009 -0400
+++ b/src/virtManager/engine.py	Tue Jun 23 08:06:19 2009 +0200
@@ -406,8 +406,9 @@
 
         path = util.browse_local(src.window.get_widget("vmm-details"),
                                  _("Save Virtual Machine"),
-                                 self.config.get_default_save_dir(con),
-                                 dialog_type=gtk.FILE_CHOOSER_ACTION_SAVE)
+                                 self.config, self.get_connection(uri),
+                                 dialog_type=gtk.FILE_CHOOSER_ACTION_SAVE,
+                                 browse_reason=self.config.CONFIG_DIR_SAVE)
 
         if not path:
             return
diff -r 2e0e047d21f0 -r 7800fad8b767 src/virtManager/manager.py
--- a/src/virtManager/manager.py	Mon Jun 22 14:24:09 2009 -0400
+++ b/src/virtManager/manager.py	Tue Jun 23 08:06:19 2009 +0200
@@ -397,7 +397,8 @@
 
         path = util.browse_local(self.window.get_widget("vmm-manager"),
                                  _("Restore Virtual Machine"),
-                                 self.config.get_default_save_dir(conn))
+                                 self.config, conn,
+                                 browse_reason=self.config.CONFIG_DIR_RESTORE)
 
         if not path:
             return
diff -r 2e0e047d21f0 -r 7800fad8b767 src/virtManager/storagebrowse.py
--- a/src/virtManager/storagebrowse.py	Mon Jun 22 14:24:09 2009 -0400
+++ b/src/virtManager/storagebrowse.py	Tue Jun 23 08:06:19 2009 +0200
@@ -38,7 +38,7 @@
                                   gobject.TYPE_NONE, [str]),
     }
 
-    def __init__(self, config, conn):
+    def __init__(self, config, conn, is_media=False):
         self.__gobject_init__()
         self.window = gtk.glade.XML(config.get_glade_dir() + \
                                     "/vmm-storage-browse.glade",
@@ -58,8 +58,14 @@
         # Add Volume wizard
         self.addvol = None
 
+        if is_media:
+            reason = self.config.CONFIG_DIR_MEDIA
+        else:
+            reason = self.config.CONFIG_DIR_IMAGE
+
         # Arguments to pass to util.browse_local for local storage
-        self.local_args = {"dialog_name": _("Choose local storage")}
+        self.local_args = {"dialog_name": _("Choose local storage"),
+                           "browse_reason": reason, }
 
         self.window.signal_autoconnect({
             "on_vmm_storage_browse_delete_event" : self.close,
@@ -232,7 +238,8 @@
                           "".join(traceback.format_exc()))
 
     def browse_local(self, src):
-        filename = util.browse_local(parent=self.topwin, **self.local_args)
+        filename = util.browse_local(parent=self.topwin, config=self.config,
+                                     conn=self.conn, **self.local_args)
         if filename:
             self._do_finish(path=filename)
 
diff -r 2e0e047d21f0 -r 7800fad8b767 src/virtManager/util.py
--- a/src/virtManager/util.py	Mon Jun 22 14:24:09 2009 -0400
+++ b/src/virtManager/util.py	Tue Jun 23 08:06:19 2009 +0200
@@ -21,6 +21,7 @@
 import logging
 import gtk
 import libxml2
+import os.path
 
 import libvirt
 
@@ -90,17 +91,24 @@
     return ret
 
 
-def browse_local(parent, dialog_name, start_folder=None, _type=None,
-                 dialog_type=gtk.FILE_CHOOSER_ACTION_OPEN, confirm_func=None):
+def browse_local(parent, dialog_name, config, conn, start_folder=None,
+                 _type=None, dialog_type=gtk.FILE_CHOOSER_ACTION_OPEN,
+                 confirm_func=None, browse_reason=None):
     """
     Helper function for launching a filechooser
 
     @param parent: Parent window for the filechooser
     @param dialog_name: String to use in the title bar of the filechooser.
+    @param config: vmmConfig used by calling class
+    @param conn: vmmConnection used by calling class
     @param start_folder: Folder the filechooser is viewing at startup
     @param _type: File extension to filter by (e.g. "iso", "png")
     @param dialog_type: Maps to FileChooserDialog 'action'
     @param confirm_func: Optional callback function if file is chosen.
+    @param browse_reason: The vmmConfig.CONFIG_DIR* reason we are browsing.
+        If set, this will override the 'folder' parameter with the gconf
+        value, and store the user chosen path.
+
     """
 
     overwrite_confirm = False
@@ -109,6 +117,9 @@
         choose_button = gtk.STOCK_SAVE
         overwrite_confirm = True
 
+    if browse_reason:
+        start_folder = config.get_default_directory(conn, browse_reason)
+
     fcdialog = gtk.FileChooserDialog(dialog_name, parent,
                                      dialog_type,
                                      (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
@@ -142,10 +153,15 @@
     if(response == gtk.RESPONSE_ACCEPT):
         filename = fcdialog.get_filename()
         fcdialog.destroy()
-        return filename
+        ret = filename
     else:
         fcdialog.destroy()
-        return None
+        ret = None
+
+    if ret and browse_reason and not path.startwith("/dev"):
+        config.set_default_directory(os.path.dirname(ret), browse_reason)
+
+    return ret
 
 def dup_conn(config, conn, libconn=None, return_conn_class=False):
 
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux