Commit 8e1c0fa9 authored by sumpfralle's avatar sumpfralle

fixes path/uri handling for Windows

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1043 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 780291e8
...@@ -6346,6 +6346,7 @@ Everyone else should use the option for M3/M5 (see above).</property> ...@@ -6346,6 +6346,7 @@ Everyone else should use the option for M3/M5 (see above).</property>
<object class="GtkLabel" id="GCodeTouchOffLabel"> <object class="GtkLabel" id="GCodeTouchOffLabel">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Touch off and tool length measurement</property> <property name="label" translatable="yes">Touch off and tool length measurement</property>
<property name="use_markup">True</property>
</object> </object>
</child> </child>
</object> </object>
...@@ -7586,6 +7587,8 @@ Leave this field empty for running a local server.</property> ...@@ -7586,6 +7587,8 @@ Leave this field empty for running a local server.</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="label" translatable="yes">Parallel processing is currently not available on your system. <property name="label" translatable="yes">Parallel processing is currently not available on your system.
You need to switch to Python v2.6 (or higher) or install the Python module "multiprocessing". You need to switch to Python v2.6 (or higher) or install the Python module "multiprocessing".
Note: The Windows standalone executable does not support parallel processing. Please install PyCAM's package for Windows and its dependencies if you need this feature.
</property> </property>
<property name="wrap">True</property> <property name="wrap">True</property>
</object> </object>
......
...@@ -3030,12 +3030,17 @@ class ProjectGui: ...@@ -3030,12 +3030,17 @@ class ProjectGui:
timestamp): timestamp):
if info != 0: if info != 0:
uris = [str(selection_data.data)] uris = [str(selection_data.data)]
elif pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS:
uris = selection_data.data.splitlines()
else: else:
uris = selection_data.get_uris() uris = selection_data.get_uris()
if not uris: if not uris:
# empty selection # empty selection
return True return True
for uri in uris: for uri in uris:
if not uri or (uri == chr(0)):
continue
uri = pycam.Utils.URIHandler(uri)
file_type, importer = pycam.Importers.detect_file_type(uri, file_type, importer = pycam.Importers.detect_file_type(uri,
quiet=True) quiet=True)
if importer: if importer:
......
...@@ -27,6 +27,7 @@ __all__ = ["iterators", "polynomials", "ProgressCounter", "threading", ...@@ -27,6 +27,7 @@ __all__ = ["iterators", "polynomials", "ProgressCounter", "threading",
import sys import sys
import os import os
import re
import socket import socket
import urllib import urllib
import urlparse import urlparse
...@@ -67,11 +68,10 @@ class URIHandler(object): ...@@ -67,11 +68,10 @@ class URIHandler(object):
self.set_location(location) self.set_location(location)
def __str__(self): def __str__(self):
url = self._uri.geturl() if self.is_local():
if url.startswith(self.DEFAULT_PREFIX): return self.get_local_path()
return url[len(self.DEFAULT_PREFIX):]
else: else:
return url return self._uri.geturl()
def set_location(self, location): def set_location(self, location):
if isinstance(location, URIHandler): if isinstance(location, URIHandler):
...@@ -79,7 +79,7 @@ class URIHandler(object): ...@@ -79,7 +79,7 @@ class URIHandler(object):
elif not location: elif not location:
self._uri = urlparse.urlparse(self.DEFAULT_PREFIX) self._uri = urlparse.urlparse(self.DEFAULT_PREFIX)
elif (get_platform() == PLATFORM_WINDOWS) and (location[1:3] == ":\\"): elif (get_platform() == PLATFORM_WINDOWS) and (location[1:3] == ":\\"):
self._uri = urlparse.urlparse(self.DEFAULT_PREFIX + location) self._uri = urlparse.urlparse(self.DEFAULT_PREFIX + location.replace("\\", "/"))
else: else:
self._uri = urlparse.urlparse(location) self._uri = urlparse.urlparse(location)
if not self._uri.scheme: if not self._uri.scheme:
...@@ -88,17 +88,22 @@ class URIHandler(object): ...@@ -88,17 +88,22 @@ class URIHandler(object):
os.path.realpath(os.path.abspath(location))) os.path.realpath(os.path.abspath(location)))
def is_local(self): def is_local(self):
return bool(self and not self._uri.scheme or \ return bool(self and (not self._uri.scheme or \
(self._uri.scheme == "file")) (self._uri.scheme == "file")))
def get_local_path(self): def get_local_path(self):
if self.is_local(): if self.is_local():
return self._uri.path return self.get_path()
else: else:
return None return None
def get_path(self): def get_path(self):
return self._uri.path if get_platform() == PLATFORM_WINDOWS:
text = self._uri.netloc + self._uri.path
text = text.lstrip("/").replace("/", "\\")
return re.sub("%([0-9a-fA-F]{2})", lambda token: chr(int(token.groups()[0], 16)), text)
else:
return self._uri.path
def get_url(self): def get_url(self):
return self._uri.geturl() return self._uri.geturl()
...@@ -142,7 +147,7 @@ class URIHandler(object): ...@@ -142,7 +147,7 @@ class URIHandler(object):
if not self: if not self:
return False return False
elif self.is_local(): elif self.is_local():
return os.path.exists(self._uri.path) return os.path.exists(self.get_local_path())
else: else:
try: try:
handle = self.open() handle = self.open()
...@@ -152,8 +157,8 @@ class URIHandler(object): ...@@ -152,8 +157,8 @@ class URIHandler(object):
return False return False
def is_writable(self): def is_writable(self):
return bool(self.is_local() and os.path.isfile(self._uri.path) and \ return bool(self.is_local() and os.path.isfile(self.get_local_path()) and \
os.access(self._uri.path, os.W_OK)) os.access(self.get_local_path(), os.W_OK))
def get_all_ips(): def get_all_ips():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment