Skip to content

Commit

Permalink
A supposedly better implementation of auto expanduser feature of path #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Mar 8, 2018
1 parent a1302ad commit 48c4e79
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/sos/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def fileMD5(filename, partial=True):
return md5.hexdigest()


class BaseTarget:
class BaseTarget(object):
'''A base class for all targets (e.g. a file)'''
def __init__(self, *args):
self._sigfile = None
Expand Down Expand Up @@ -427,11 +427,16 @@ class path(type(Path())):
'R': lambda x: x,
}

def __new__(cls, *args, **kwargs):
if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath
#def __new__(cls, *args, **kwargs):
# if cls is Path:
# cls = WindowsPath if os.name == 'nt' else PosixPath
#
# return cls._from_parts(args).expanduser()

return cls._from_parts(args).expanduser()
def _init(self, template=None):
super(path, self)._init(template)
if self._parts and self._parts[0] == '~':
self._parts = self.expanduser()._parts

def is_external(self):
try:
Expand Down Expand Up @@ -487,8 +492,8 @@ def __init__(self, *args):
self._md5 = None
self._attachments = []

def _init(self):
super(file_target, self)._init()
def _init(self, template=None):
super(file_target, self)._init(template)
self._md5 = None
self._attachments = []

Expand Down

0 comments on commit 48c4e79

Please sign in to comment.