libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1439005 - in /libcloud/trunk/libcloud: storage/drivers/local.py utils/py3.py
Date Sun, 27 Jan 2013 00:33:34 GMT
Author: tomaz
Date: Sun Jan 27 00:33:34 2013
New Revision: 1439005

URL: http://svn.apache.org/viewvc?rev=1439005&view=rev
Log:
Modify local_storage storage driver to use custom relpath function when using
Python 2.5.

Modified:
    libcloud/trunk/libcloud/storage/drivers/local.py
    libcloud/trunk/libcloud/utils/py3.py

Modified: libcloud/trunk/libcloud/storage/drivers/local.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/storage/drivers/local.py?rev=1439005&r1=1439004&r2=1439005&view=diff
==============================================================================
--- libcloud/trunk/libcloud/storage/drivers/local.py (original)
+++ libcloud/trunk/libcloud/storage/drivers/local.py Sun Jan 27 00:33:34 2013
@@ -31,6 +31,7 @@ except ImportError:
                       'using pip: pip install lockfile')
 
 from libcloud.utils.files import read_in_chunks
+from libcloud.utils.py import relpath
 from libcloud.common.base import Connection
 from libcloud.storage.base import Object, Container, StorageDriver
 from libcloud.common.types import LibcloudError
@@ -215,7 +216,7 @@ class LocalStorageDriver(StorageDriver):
 
             for name in files:
                 full_path = os.path.join(folder, name)
-                object_name = os.path.relpath(full_path, start=cpath)
+                object_name = relpath(full_path, start=cpath)
                 yield self._make_object(container, object_name)
 
     def iterate_container_objects(self, container):

Modified: libcloud/trunk/libcloud/utils/py3.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/utils/py3.py?rev=1439005&r1=1439004&r2=1439005&view=diff
==============================================================================
--- libcloud/trunk/libcloud/utils/py3.py (original)
+++ libcloud/trunk/libcloud/utils/py3.py Sun Jan 27 00:33:34 2013
@@ -39,6 +39,7 @@ if sys.version_info >= (3, 0):
     from urllib.parse import quote as urlquote
     from urllib.parse import unquote as urlunquote
     from urllib.parse import urlencode as urlencode
+    from os.path import relpath
 
     basestring = str
 
@@ -74,6 +75,7 @@ else:
     from urllib import quote as urlquote
     from urllib import unquote as urlunquote
     from urllib import urlencode as urlencode
+    from os.path import relpath
 
     basestring = unicode = str
 
@@ -92,3 +94,19 @@ else:
 
 if sys.version_info >= (2, 5) and sys.version_info <= (2, 6):
     PY25 = True
+    import posixpath
+
+    # Taken from http://jimmyg.org/work/code/barenecessities/index.html
+    # (MIT license)
+    def relpath(path, start=posixpath.curdir):
+        """Return a relative version of a path"""
+        if not path:
+            raise ValueError("no path specified")
+        start_list = posixpath.abspath(start).split(posixpath.sep)
+        path_list = posixpath.abspath(path).split(posixpath.sep)
+        # Work out how much of the filepath is shared by start and path.
+        i = len(posixpath.commonprefix([start_list, path_list]))
+        rel_list = [posixpath.pardir] * (len(start_list) - i) + path_list[i:]
+        if not rel_list:
+            return posixpath.curdir
+        return posixpath.join(*rel_list)



Mime
View raw message