Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added many more chainable methods per #7

  • Loading branch information...
commit c8fdf978be4c52f999ae1ababbd4d549fcdacf95 1 parent fe95177
Jason R. Coombs authored
Showing with 15 additions and 0 deletions.
  1. +15 −0 path.py
15 path.py
View
@@ -911,13 +911,16 @@ def pathconf(self, name):
def utime(self, times):
""" Set the access and modified times of this file. """
os.utime(self, times)
+ return self
def chmod(self, mode):
os.chmod(self, mode)
+ return self
if hasattr(os, 'chown'):
def chown(self, uid, gid):
os.chown(self, uid, gid)
+ return self
def rename(self, new):
os.rename(self, new)
@@ -956,6 +959,7 @@ def makedirs_p(self, mode=0777):
def rmdir(self):
os.rmdir(self)
+ return self
def rmdir_p(self):
try:
@@ -963,9 +967,11 @@ def rmdir_p(self):
except OSError, e:
if e.errno != errno.ENOTEMPTY and e.errno != errno.EEXIST:
raise
+ return self
def removedirs(self):
os.removedirs(self)
+ return self
def removedirs_p(self):
try:
@@ -973,6 +979,7 @@ def removedirs_p(self):
except OSError, e:
if e.errno != errno.ENOTEMPTY and e.errno != errno.EEXIST:
raise
+ return self
# --- Modifying operations on files
@@ -987,6 +994,7 @@ def touch(self):
def remove(self):
os.remove(self)
+ return self
def remove_p(self):
try:
@@ -994,12 +1002,15 @@ def remove_p(self):
except OSError, e:
if e.errno != errno.ENOENT:
raise
+ return self
def unlink(self):
os.unlink(self)
+ return self
def unlink_p(self):
self.remove_p()
+ return self
# --- Links
@@ -1007,11 +1018,13 @@ def unlink_p(self):
def link(self, newpath):
""" Create a hard link at 'newpath', pointing to this file. """
os.link(self, newpath)
+ return self.__class__(newpath)
if hasattr(os, 'symlink'):
def symlink(self, newlink):
""" Create a symbolic link at 'newlink', pointing here. """
os.symlink(self, newlink)
+ return self.__class__(newlink)
if hasattr(os, 'readlink'):
def readlink(self):
@@ -1051,6 +1064,7 @@ def rmtree_p(self):
except OSError, e:
if e.errno != errno.ENOENT:
raise
+ return self
#
# --- Special stuff from os
@@ -1062,3 +1076,4 @@ def chroot(self):
if hasattr(os, 'startfile'):
def startfile(self):
os.startfile(self)
+ return self
Please sign in to comment.
Something went wrong with that request. Please try again.