Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #180 from aeroevan/windows_fixup
Browse files Browse the repository at this point in the history
Start using posixpath where appropriate.
  • Loading branch information
Wouter de Bie committed Jan 25, 2016
2 parents 8e170f8 + 145709a commit f4ec5cb
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions snakebite/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import logging
import os
import os.path
import posixpath
import fnmatch
import inspect
import socket
Expand Down Expand Up @@ -507,11 +508,11 @@ def _handle_delete(self, path, node, recurse):
else:
suffix_path = path[1:]

trash_path = os.path.join(self.trash, "Current", suffix_path)
trash_path = posixpath.join(self.trash, "Current", suffix_path)
if trash_path.endswith("/"):
trash_path = trash_path[:-1]

base_trash_path = os.path.join(self.trash, "Current", os.path.dirname(suffix_path))
base_trash_path = posixpath.join(self.trash, "Current", posixpath.dirname(suffix_path))
if base_trash_path.endswith("/"):
base_trash_path = base_trash_path[:-1]

Expand Down Expand Up @@ -542,7 +543,7 @@ def __should_move_to_trash(self, path):
return False
if path.startswith(self.trash):
return False # Path already in trash
if os.path.dirname(self.trash).startswith(path):
if posixpath.dirname(self.trash).startswith(path):
raise Exception("Cannot move %s to the trash, as it contains the trash" % path)

return True
Expand Down Expand Up @@ -620,7 +621,7 @@ def _handle_touchz(self, path, node, replication, blocksize):
response = self._create_file(path, replication, blocksize, overwrite=True)
else:
# Check if the parent directory exists
parent = self._get_file_info(os.path.dirname(path))
parent = self._get_file_info(posixpath.dirname(path))
if not parent:
raise DirectoryException("touchz: `%s': No such file or directory" % path)
else:
Expand Down Expand Up @@ -724,7 +725,7 @@ def _handle_copyToLocal(self, path, node, dst, check_crc):
if not self.base_source:
# base_source is shared for whole dir tree, and can
# be computed only once per dir tree
self.base_source = os.path.dirname(path)
self.base_source = posixpath.dirname(path)
self.base_source = self.base_source if self.base_source.endswith("/") else self.base_source + "/"

# If input destination is an existing directory, include toplevel
Expand Down Expand Up @@ -1049,7 +1050,7 @@ def _is_zero_length(self, should_check, node):

def _get_full_path(self, path, node):
if node.path:
return os.path.join(path, node.path)
return posixpath.join(path, node.path)
else:
return path

Expand Down Expand Up @@ -1176,7 +1177,7 @@ def _find_items(self, paths, processor, include_toplevel=False, include_children
'''

if not paths:
paths = [os.path.join("/user", get_current_username())]
paths = [posixpath.join("/user", get_current_username())]

# Expand paths if necessary (/foo/{bar,baz} --> ['/foo/bar', '/foo/baz'])
paths = glob.expand_paths(paths)
Expand Down Expand Up @@ -1221,7 +1222,7 @@ def _find_items(self, paths, processor, include_toplevel=False, include_children
# Recurse into directories
if recurse and self._is_dir(node):
# Construct the full path before processing
full_path = os.path.join(path, node.path)
full_path = posixpath.join(path, node.path)
for item in self._find_items([full_path],
processor,
include_toplevel=False,
Expand Down Expand Up @@ -1291,7 +1292,7 @@ def _glob_find(self, path, processor, include_toplevel):
yield item
elif rest:
# we have more rest, but it's not magic, which is either a file or a directory
final_path = os.path.join(full_path, rest)
final_path = posixpath.join(full_path, rest)
fi = self._get_file_info(final_path)
if fi and self._is_dir(fi.fs):
for n in self._get_dir_listing(final_path):
Expand Down Expand Up @@ -1326,14 +1327,14 @@ def _get_file_info(self, path):
return self.service.getFileInfo(request)

def _join_user_path(self, path):
return os.path.join("/user", get_current_username(), path)
return posixpath.join("/user", get_current_username(), path)

def _remove_user_path(self, path):
dir_to_remove = os.path.join("/user", get_current_username())
dir_to_remove = posixpath.join("/user", get_current_username())
return path.replace(dir_to_remove+'/', "", 1)

def _normalize_path(self, path):
return os.path.normpath(re.sub('/+', '/', path))
return posixpath.normpath(re.sub('/+', '/', path))

class HAClient(Client):
''' Snakebite client with support for High Availability
Expand Down

0 comments on commit f4ec5cb

Please sign in to comment.