[tor-commits] [stem/master] Implement stem.util.system.expand_path() on windows.

atagar at torproject.org atagar at torproject.org
Thu Jun 21 15:45:57 UTC 2012


commit 232858d8607270e00d42316e8655c70e0221c87e
Author: Beck Chen <csybeck at gmail.com>
Date:   Fri Jun 15 02:17:00 2012 +0800

    Implement stem.util.system.expand_path() on windows.
---
 stem/util/system.py |   39 ++++++++++++++++++++-------------------
 1 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/stem/util/system.py b/stem/util/system.py
index 3d1a26b..fb27b13 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -502,28 +502,29 @@ def expand_path(path, cwd = None):
   """
   
   if platform.system() == "Windows":
-    return path # TODO: implement
+    path = path.replace("/", "\\").rstrip("\\")
   else:
-    relative_path = path
+    path = path.replace("\\", "/").rstrip("/")
+  relative_path = path
+  
+  if not path or os.path.isabs(path):
+    # empty or already absolute - nothing to do
+    pass
+  elif path.startswith("~"):
+    # prefixed with a ~ or ~user entry
+    relative_path = os.path.expanduser(path)
+  else:
+    # relative path, expand with the cwd
+    if not cwd: cwd = os.getcwd()
     
-    if not path or os.path.isabs(path):
-      # empty or already absolute - nothing to do
-      pass
-    elif path.startswith("~"):
-      # prefixed with a ~ or ~user entry
-      relative_path = os.path.expanduser(path)
-    else:
-      # relative path, expand with the cwd
-      if not cwd: cwd = os.getcwd()
-      
-      # we'll be dealing with both "my/path/" and "./my/path" entries, so
-      # cropping the later
-      if path.startswith("./"): path = path[2:]
-      elif path == ".": path = ""
-      
-      relative_path = os.path.join(cwd, path)
+    # we'll be dealing with both "my/path/" and "./my/path" entries, so
+    # cropping the later
+    if path.startswith("./") or path.startswith(".\\"): path = path[2:]
+    elif path == ".": path = ""
     
-    return relative_path.rstrip("/")
+    relative_path = os.path.join(cwd, path)
+  
+  return relative_path
 
 def call(command, suppress_exc = True):
   """





More information about the tor-commits mailing list