Kaynağa Gözat

wxGUI/startup: move delete mapset and location to separate functions

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@73174 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 6 yıl önce
ebeveyn
işleme
76071a2eba
2 değiştirilmiş dosya ile 17 ekleme ve 3 silme
  1. 3 3
      gui/wxpython/gis_set.py
  2. 14 0
      gui/wxpython/startup/utils.py

+ 3 - 3
gui/wxpython/gis_set.py

@@ -22,7 +22,6 @@ This program is free software under the GNU General Public License
 
 import os
 import sys
-import shutil
 import copy
 import platform
 import codecs
@@ -39,6 +38,7 @@ from core.gcmd import GMessage, GError, DecodeString, RunCommand
 from core.utils import GetListOfLocations, GetListOfMapsets
 from startup.utils import (
     get_lockfile_if_present, get_possible_database_path, create_mapset)
+import startup.utils as sutils
 from startup.guiutils import SetSessionMapset, NewMapsetDialog
 from location_wizard.dialogs import RegionDef
 from gui_core.dialogs import TextEntryDialog
@@ -758,7 +758,7 @@ class GRASSStartup(wx.Frame):
 
         if dlg.ShowModal() == wx.ID_YES:
             try:
-                shutil.rmtree(os.path.join(self.gisdbase, location, mapset))
+                sutils.delete_mapset(self.gisdbase, location, mapset)
                 self.OnSelectLocation(None)
                 self.lbmapsets.SetSelection(0)
             except:
@@ -786,7 +786,7 @@ class GRASSStartup(wx.Frame):
 
         if dlg.ShowModal() == wx.ID_YES:
             try:
-                shutil.rmtree(os.path.join(self.gisdbase, location))
+                sutils.delete_location(self.gisdbase, location)
                 self.UpdateLocations(self.gisdbase)
                 self.lblocations.SetSelection(0)
                 self.OnSelectLocation(None)

+ 14 - 0
gui/wxpython/startup/utils.py

@@ -82,3 +82,17 @@ def create_mapset(database, location, mapset):
     shutil.copy(region_path, mapset_path)
     # set permissions to u+rw,go+r (disabled)
     # os.chmod(os.path.join(database,location,mapset,'WIND'), 0644)
+
+
+def delete_mapset(database, location, mapset):
+    """Deletes a specified mapset"""
+    if mapset == 'PERMANENT':
+        # TODO: translatable or not?
+        raise ValueError("Mapset PERMANENT cannot be deleted"
+                         " (whole location can be)")
+    shutil.rmtree(os.path.join(database, location, mapset))
+
+
+def delete_location(database, location):
+    """Deletes a specified location"""
+    shutil.rmtree(os.path.join(database, location))