Quellcode durchsuchen

attempt to fix https://trac.osgeo.org/grass/ticket/1496 - TODO: replace such ugly hacks with something more reasonable in the future

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@49565 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa vor 13 Jahren
Ursprung
Commit
f1210ca24a
3 geänderte Dateien mit 32 neuen und 8 gelöschten Zeilen
  1. 19 1
      gui/wxpython/core/gcmd.py
  2. 4 1
      lib/python/core.py
  3. 9 6
      lib/python/task.py

+ 19 - 1
gui/wxpython/core/gcmd.py

@@ -506,8 +506,20 @@ class CommandThread(Thread):
         Debug.msg(1, "gcmd.CommandThread(): %s" % ' '.join(self.cmd))
 
         self.startTime = time.time()
+
+        # TODO: replace ugly hack bellow
+        args = self.cmd
+        if sys.platform == 'win32':
+            ext = os.path.splitext(self.cmd[0])[1] == '.py'
+            if ext or self.cmd[0] in globalvar.grassCmd['script']:
+                os.chdir(os.path.join(os.getenv('GISBASE'), 'scripts'))
+                if not ext:
+                    args = [sys.executable, self.cmd[0] + '.py'] + self.cmd[1:]
+                else:
+                    args = [sys.executable, self.cmd[0]] + self.cmd[1:]
+        
         try:
-            self.module = Popen(self.cmd,
+            self.module = Popen(args,
                                 stdin = subprocess.PIPE,
                                 stdout = subprocess.PIPE,
                                 stderr = subprocess.PIPE,
@@ -624,6 +636,12 @@ def RunCommand(prog, flags = "", overwrite = False, quiet = False, verbose = Fal
     Debug.msg(2, "gcmd.RunCommand(): command started")
     start = time.time()
     
+    if sys.platform == "win32":
+        if prog in globalvar.grassCmd['script']:
+            prog += globalvar.EXT_SCT
+        # else:
+        # prog += globalvar.EXT_BIN
+    
     ps = grass.start_command(prog, flags, overwrite, quiet, verbose, **kwargs)
     
     if stdin:

+ 4 - 1
lib/python/core.py

@@ -165,7 +165,10 @@ def start_command(prog, flags = "", overwrite = False, quiet = False, verbose =
 	else:
 	    options[opt] = val
     args = make_command(prog, flags, overwrite, quiet, verbose, **options)
-
+    if sys.platform == 'win32' and os.path.splitext(prog)[1] == '.py':
+        os.chdir(os.path.join(os.getenv('GISBASE'), 'scripts'))
+        args.insert(0, sys.executable)
+    
     global debug_level
     if debug_level > 0:
         sys.stderr.write("D1/%d: %s.start_command(): %s\n" % (debug_level, __name__, ' '.join(args)))

+ 9 - 6
lib/python/task.py

@@ -430,14 +430,17 @@ def get_interface_description(cmd):
 
     @param cmd command (name of GRASS module)
     """
-    if sys.platform == 'win32' and os.path.splitext(cmd)[1] == '.py':
-        args = [sys.executable, cmd, '--interface-description']
-    else:
-        args = [cmd, '--interface-description']
-    
     try:
-        cmdout, cmderr = Popen(args, stdout = PIPE,
+        cmdout, cmderr = Popen([cmd, '--interface-description'], stdout = PIPE,
                                stderr = PIPE).communicate()
+        # TODO: replace ugly hack bellow
+        if not cmdout and sys.platform == 'win32':
+            if os.path.splitext(cmd)[1] == '':
+                cmd += '.py'
+            
+            os.chdir(os.path.join(os.getenv('GISBASE'), 'scripts'))
+            cmdout, cmderr = Popen([sys.executable, cmd, '--interface-description'], stdout = PIPE,
+                                   stderr = PIPE).communicate()
     except OSError, e:
         raise ScriptError, _("Unable to fetch interface description for command '%(cmd)s'."
                              "\n\nDetails: %(det)s") % { 'cmd' : cmd, 'det' : e }