Why is the shutil module called shutil?

rantingrick rantingrick at gmail.com
Mon Sep 26 00:50:17 CEST 2011


Here is a *very* rough outline of my ideas. There are probably a few
mistakes in there. I've decided on three main main objects. A File
object, a Path object, and a Dir object.


## START ENLIGHTENMENT ##

class Path:
    def __init__(self, path):
    #
    # Properties about the path:
    drive => str
    directory => str
    filename => str
    extension => str
    uncshare[1]=> ???
    #
    # Mutations.
    def coerce(self) => File or Dir
    def normalize(self): => ip or Path? #normcase/normpath
    def expand_user(self): => ip or Path?
    def expand_vars(self): => ip or Path?
    def absolute(self) => ip or Path? #realpath/abspath
    def strip(self) => ip => remove one extension.
    def chmod(self, mode) => None
    def chown(self, uid, gid) => None [1]
    def rename(self, newname) => None
    def access(self, mode): => None #access
    def chroot(self) => None
    #
    # Introspection.
    def is_valid(self): # exists
    def is_absolute(self): #isabs
    def is_directory(self): #isdir
    def is_file(self): #isfile
    def is_link(self): #islnk
    def is_mount(self): #ismount
    def is_identical(self, other): #issamefile
    def time_accessed(self): #atime
    def time_modified(self): #mtime
    def time_changed(self): #ctime
##    def utime(self, times) => None
    #
    # Inspection.
    def info_stat(self): #stat
    def info_lstat(self): #lstat
    def info_statvfs(self): #statvfs
    #
    # Extraction.
    def basename(self): => str
        #Do we need basename when properties exist?
    def partition(self) => (drive, path, filename, extension)
        #Do we need partition when properties exist?
    def splitunc(self): ???
    def splitall(self): ???
    def relpathto(self, dest): => ???
    def pathconf(self, name): #pathconfig
    #
    # Modifying operations on links
    def link(self, newpath): ...
    def symlink(self, newlink): ...
    def readlink(self): ...
    def readlinkabs(self): ...

class File:
    def new(path)
    (...All existing file methods here...)
    #
    # Mutate, Clone, Destroy.
    def rename(self, newname) => ip or File?
    def delete(self, overwrites=3) => None
    def copy(self, dst) => File
    def unlink(self) => None    #
    #
    # Attribute mutation.
    def update(self) => None #touch
    def copy_mode(src) => None #copymode
    def copy_stat(src) => None #copystat
    def update_mode(dst) => None
    def update_stat(dst) => None
    #
    # Other
    def bytes(self): => int => 1292894
    def size(self, fmtstr="{0:0.2f}") => str => "1.23 MB"
    def backup(self) => filename.bak{count}


class Dir:
    def new(path)
    def open(path)
    #
    # Mutate, Clone, Destroy.
    def delete(self, onerror=None): => None
    def copy(self, dst, symlinks=True): => Dir
    #
    # Introspection.
    def get_paths(self, pattern=None): [Path, Path, ...]
    def get_dirs(self, pattern=None): => [Dir, Dir, ...]
    def get_files(self, pattern=None): => [File, File, ...]
    #
    def walk_paths(self, pattern=None): itereach->PathObj
    def walk_dirs(self, pattern=None): itereach->DirObj
    def walk_files(self, pattern=None): itereach->FileObj
    #
    def match(self, pattern) => bool
    def glob(self, pattern): => [Path, Path, ...]

    #######################################
    # Not sure what to do with these yet.
    #######################################
    def startfile(self)
        # startfile should part of os anyway.

## END ENLIGHTENMENT ##




More information about the Python-list mailing list