Browse Source

wxGUI/startup: move mapset creation core to an utils function

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@73173 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 6 năm trước cách đây
mục cha
commit
e4d8cf1d76
2 tập tin đã thay đổi với 17 bổ sung15 xóa
  1. 2 15
      gui/wxpython/gis_set.py
  2. 15 0
      gui/wxpython/startup/utils.py

+ 2 - 15
gui/wxpython/gis_set.py

@@ -38,7 +38,7 @@ from grass.script import core as grass
 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)
+    get_lockfile_if_present, get_possible_database_path, create_mapset)
 from startup.guiutils import SetSessionMapset, NewMapsetDialog
 from location_wizard.dialogs import RegionDef
 from gui_core.dialogs import TextEntryDialog
@@ -1014,20 +1014,7 @@ class GRASSStartup(wx.Frame):
         try:
             self.gisdbase = self.tgisdbase.GetValue()
             location = self.listOfLocations[self.lblocations.GetSelection()]
-            os.mkdir(os.path.join(self.gisdbase, location, mapset))
-            # copy WIND file and its permissions from PERMANENT and set
-            # permissions to u+rw,go+r
-            shutil.copy(
-                os.path.join(
-                    self.gisdbase,
-                    location,
-                    'PERMANENT',
-                    'WIND'),
-                os.path.join(
-                    self.gisdbase,
-                    location,
-                    mapset))
-            # os.chmod(os.path.join(database,location,mapset,'WIND'), 0644)
+            create_mapset(self.gisdbase, location, mapset)
             self.OnSelectLocation(None)
             self.lbmapsets.SetSelection(self.listOfMapsets.index(mapset))
             self.bstart.SetFocus()

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

@@ -17,6 +17,7 @@ solve the errors etc. in a general manner).
 
 
 import os
+import shutil
 
 
 def get_possible_database_path():
@@ -67,3 +68,17 @@ def get_lockfile_if_present(database, location, mapset):
     else:
         return None
 
+
+def create_mapset(database, location, mapset):
+    """Creates a mapset in a specified location"""
+    location_path = os.path.join(database, location)
+    mapset_path = os.path.join(location_path, mapset)
+    # create an empty directory
+    os.mkdir(mapset_path)
+    # copy WIND file and its permissions from PERMANENT
+    # this uses PERMANENT's current region instead of default (?)
+    region_file = 'WIND'
+    region_path = os.path.join(location_path, 'PERMANENT', region_file)
+    shutil.copy(region_path, mapset_path)
+    # set permissions to u+rw,go+r (disabled)
+    # os.chmod(os.path.join(database,location,mapset,'WIND'), 0644)