Back to index

obnam  1.1
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
obnamlib.vfs_local.LocalFS Class Reference
Inheritance diagram for obnamlib.vfs_local.LocalFS:
Inheritance graph
[legend]
Collaboration diagram for obnamlib.vfs_local.LocalFS:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def maybe_crash
def reinit
def getcwd
def chdir
def lock
def unlock
def join
def remove
def rename
def lstat
def get_username
def get_groupname
def llistxattr
def lgetxattr
def lsetxattr
def lchown
def chmod
def lutimes
def link
def readlink
def symlink
def open
def exists
def isdir
def mknod
def mkdir
def makedirs
def rmdir
def cat
def write_file
def overwrite_file
def listdir
def listdir2

Public Attributes

 crash_limit
 crash_counter
 cwd

Static Public Attributes

int chunk_size = 1024

Private Member Functions

def _write_to_tempfile

Detailed Description

A VFS implementation for local filesystems.

Definition at line 48 of file vfs_local.py.


Constructor & Destructor Documentation

def obnamlib.vfs_local.LocalFS.__init__ (   self,
  baseurl,
  create = False 
)

Definition at line 54 of file vfs_local.py.

00054 
00055     def __init__(self, baseurl, create=False):
00056         tracing.trace('baseurl=%s', baseurl)
00057         tracing.trace('create=%s', create)
00058         obnamlib.VirtualFileSystem.__init__(self, baseurl)
00059         self.reinit(baseurl, create=create)
00060 
00061         # For testing purposes, allow setting a limit on write operations
00062         # after which an exception gets raised. If set to None, no crash.
00063         self.crash_limit = None
00064         self.crash_counter = 0

Here is the call graph for this function:


Member Function Documentation

def obnamlib.vfs_local.LocalFS._write_to_tempfile (   self,
  pathname,
  contents 
) [private]

Definition at line 288 of file vfs_local.py.

00288 
00289     def _write_to_tempfile(self, pathname, contents):
00290         path = self.join(pathname)
00291         dirname = os.path.dirname(path)
00292         if not os.path.exists(dirname):
00293             tracing.trace('os.makedirs(%s)' % dirname)
00294             os.makedirs(dirname)
00295 
00296         fd, tempname = tempfile.mkstemp(dir=dirname)
00297         os.close(fd)
00298         f = self.open(tempname, 'wb')
00299 
00300         pos = 0
00301         while pos < len(contents):
00302             chunk = contents[pos:pos+self.chunk_size]
00303             f.write(chunk)
00304             pos += len(chunk)
00305             self.bytes_written += len(chunk)
00306         f.close()
00307         return tempname

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.vfs_local.LocalFS.cat (   self,
  pathname 
)

Definition at line 255 of file vfs_local.py.

00255 
00256     def cat(self, pathname):
00257         pathname = self.join(pathname)
00258         f = self.open(pathname, 'rb')
00259         chunks = []
00260         while True:
00261             chunk = f.read(self.chunk_size)
00262             if not chunk:
00263                 break
00264             chunks.append(chunk)
00265             self.bytes_read += len(chunk)
00266         f.close()
00267         data = ''.join(chunks)
00268         return data

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.chdir (   self,
  pathname 
)

Definition at line 96 of file vfs_local.py.

00096 
00097     def chdir(self, pathname):
00098         tracing.trace('LocalFS(%s).chdir(%s)', self.baseurl, pathname)
00099         newcwd = os.path.abspath(self.join(pathname))
00100         if not os.path.isdir(newcwd):
00101             raise OSError('%s is not a directory' % newcwd)
00102         self.cwd = newcwd

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.chmod (   self,
  pathname,
  mode 
)

Definition at line 184 of file vfs_local.py.

00184 
00185     def chmod(self, pathname, mode):
00186         tracing.trace('chmod %s %o', pathname, mode)
00187         os.chmod(self.join(pathname), mode)

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.exists (   self,
  pathname 
)

Definition at line 229 of file vfs_local.py.

00229 
00230     def exists(self, pathname):
00231         return os.path.exists(self.join(pathname))

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.vfs_local.LocalFS.get_groupname (   self,
  gid 
)

Definition at line 159 of file vfs_local.py.

00159 
00160     def get_groupname(self, gid):
00161         return grp.getgrgid(gid)[0]

def obnamlib.vfs_local.LocalFS.get_username (   self,
  uid 
)

Definition at line 156 of file vfs_local.py.

00156 
00157     def get_username(self, uid):
00158         return pwd.getpwuid(uid)[0]

Definition at line 93 of file vfs_local.py.

00093 
00094     def getcwd(self):
00095         return self.cwd

def obnamlib.vfs_local.LocalFS.isdir (   self,
  pathname 
)

Definition at line 232 of file vfs_local.py.

00232 
00233     def isdir(self, pathname):
00234         return os.path.isdir(self.join(pathname))

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.join (   self,
  pathname 
)

Definition at line 118 of file vfs_local.py.

00118 
00119     def join(self, pathname):
00120         return os.path.join(self.cwd, pathname)

Here is the caller graph for this function:

def obnamlib.vfs_local.LocalFS.lchown (   self,
  pathname,
  uid,
  gid 
)

Definition at line 180 of file vfs_local.py.

00180 
00181     def lchown(self, pathname, uid, gid): # pragma: no cover
00182         tracing.trace('lchown %s %d %d', pathname, uid, gid)
00183         os.lchown(self.join(pathname), uid, gid)

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.lgetxattr (   self,
  filename,
  attrname 
)

Definition at line 168 of file vfs_local.py.

00168 
00169     def lgetxattr(self, filename, attrname): # pragma: no cover
00170         ret = obnamlib._obnam.lgetxattr(self.join(filename), attrname)
00171         if type(ret) is int:
00172             raise OSError((ret, os.strerror(ret), filename))
00173         return ret

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.link (   self,
  existing,
  new 
)

Definition at line 199 of file vfs_local.py.

00199 
00200     def link(self, existing, new):
00201         tracing.trace('existing=%s', existing)
00202         tracing.trace('new=%s', new)
00203         os.link(self.join(existing), self.join(new))
00204         self.maybe_crash()

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.listdir (   self,
  dirname 
)

Definition at line 308 of file vfs_local.py.

00308 
00309     def listdir(self, dirname):
00310         return os.listdir(self.join(dirname))

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.vfs_local.LocalFS.listdir2 (   self,
  dirname 
)

Definition at line 311 of file vfs_local.py.

00311 
00312     def listdir2(self, dirname):
00313         result = []
00314         for name in self.listdir(dirname):
00315             try:
00316                 st = self.lstat(os.path.join(dirname, name))
00317             except OSError, e: # pragma: no cover
00318                 st = e
00319             result.append((name, st))
00320         return result
00321 

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.llistxattr (   self,
  filename 
)

Definition at line 162 of file vfs_local.py.

00162 
00163     def llistxattr(self, filename): # pragma: no cover
00164         ret = obnamlib._obnam.llistxattr(self.join(filename))
00165         if type(ret) is int:
00166             raise OSError((ret, os.strerror(ret), filename))
00167         return [s for s in ret.split('\0') if s]

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.lock (   self,
  lockname,
  data 
)

Definition at line 103 of file vfs_local.py.

00103 
00104     def lock(self, lockname, data):
00105         tracing.trace('lockname=%s', lockname)
00106         try:
00107             self.write_file(lockname, data)
00108         except OSError, e:
00109             if e.errno == errno.EEXIST:
00110                 raise obnamlib.LockFail("Lock %s already exists" % lockname)
00111             else:
00112                 raise # pragma: no cover

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.lsetxattr (   self,
  filename,
  attrname,
  attrvalue 
)

Definition at line 174 of file vfs_local.py.

00174 
00175     def lsetxattr(self, filename, attrname, attrvalue): # pragma: no cover
00176         ret = obnamlib._obnam.lsetxattr(self.join(filename), 
00177                                         attrname, attrvalue)
00178         if ret != 0:
00179             raise OSError((ret, os.strerror(ret), filename))

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.lstat (   self,
  pathname 
)

Definition at line 131 of file vfs_local.py.

00131 
00132     def lstat(self, pathname):
00133         (ret, dev, ino, mode, nlink, uid, gid, rdev, size, blksize, blocks,
00134          atime_sec, atime_nsec, mtime_sec, mtime_nsec, 
00135          ctime_sec, ctime_nsec) = obnamlib._obnam.lstat(self.join(pathname))
00136         if ret != 0:
00137             raise OSError((ret, os.strerror(ret), pathname))
00138         return obnamlib.Metadata(
00139                     st_dev=dev,
00140                     st_ino=ino,
00141                     st_mode=mode,
00142                     st_nlink=nlink,
00143                     st_uid=uid,
00144                     st_gid=gid,
00145                     st_rdev=rdev,
00146                     st_size=size,
00147                     st_blksize=blksize,
00148                     st_blocks=blocks,
00149                     st_atime_sec=atime_sec,
00150                     st_atime_nsec=atime_nsec,
00151                     st_mtime_sec=mtime_sec,
00152                     st_mtime_nsec=mtime_nsec,
00153                     st_ctime_sec=ctime_sec,
00154                     st_ctime_nsec=ctime_nsec
00155                 )

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.vfs_local.LocalFS.lutimes (   self,
  pathname,
  atime_sec,
  atime_nsec,
  mtime_sec,
  mtime_nsec 
)

Definition at line 188 of file vfs_local.py.

00188 
00189     def lutimes(self, pathname, atime_sec, atime_nsec, mtime_sec, mtime_nsec):
00190         assert atime_sec is not None
00191         assert atime_nsec is not None
00192         assert mtime_sec is not None
00193         assert mtime_nsec is not None
00194         ret = obnamlib._obnam.utimensat(self.join(pathname), 
00195                                         atime_sec, atime_nsec, 
00196                                         mtime_sec, mtime_nsec)
00197         if ret != 0:
00198             raise OSError(ret, os.strerror(ret), pathname)

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.makedirs (   self,
  pathname 
)

Definition at line 245 of file vfs_local.py.

00245 
00246     def makedirs(self, pathname):
00247         tracing.trace('makedirs %s', pathname)
00248         os.makedirs(self.join(pathname))
00249         self.maybe_crash()

Here is the call graph for this function:

Definition at line 65 of file vfs_local.py.

00065 
00066     def maybe_crash(self): # pragma: no cover
00067         if self.crash_limit is not None:
00068             self.crash_counter += 1
00069             if self.crash_counter >= self.crash_limit:
00070                 raise Exception('Crashing as requested after %d writes' %
00071                                     self.crash_counter)

Here is the caller graph for this function:

def obnamlib.vfs_local.LocalFS.mkdir (   self,
  pathname 
)

Definition at line 240 of file vfs_local.py.

00240 
00241     def mkdir(self, pathname):
00242         tracing.trace('mkdir %s', pathname)
00243         os.mkdir(self.join(pathname))
00244         self.maybe_crash()

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.mknod (   self,
  pathname,
  mode 
)

Definition at line 235 of file vfs_local.py.

00235 
00236     def mknod(self, pathname, mode):
00237         tracing.trace('pathmame=%s', pathname)
00238         tracing.trace('mode=%o', mode)
00239         os.mknod(self.join(pathname), mode)

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.open (   self,
  pathname,
  mode 
)

Definition at line 214 of file vfs_local.py.

00214 
00215     def open(self, pathname, mode):
00216         tracing.trace('pathname=%s', pathname)
00217         tracing.trace('mode=%s', mode)
00218         f = LocalFSFile(self.join(pathname), mode)
00219         tracing.trace('opened %s', pathname)
00220         try:
00221             flags = fcntl.fcntl(f.fileno(), fcntl.F_GETFL)
00222             flags |= os.O_NOATIME
00223             fcntl.fcntl(f.fileno(), fcntl.F_SETFL, flags)
00224         except IOError, e: # pragma: no cover
00225             tracing.trace('fcntl F_SETFL failed: %s', repr(e))
00226             return f # ignore any problems setting flags
00227         tracing.trace('returning ok')
00228         return f

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.vfs_local.LocalFS.overwrite_file (   self,
  pathname,
  contents 
)

Definition at line 281 of file vfs_local.py.

00281 
00282     def overwrite_file(self, pathname, contents):
00283         tracing.trace('overwrite_file %s', pathname)
00284         tempname = self._write_to_tempfile(pathname, contents)
00285         path = self.join(pathname)
00286         os.rename(tempname, path)
00287         self.maybe_crash()
                

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.readlink (   self,
  pathname 
)

Definition at line 205 of file vfs_local.py.

00205 
00206     def readlink(self, pathname):
00207         return os.readlink(self.join(pathname))

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.reinit (   self,
  baseurl,
  create = False 
)

Definition at line 72 of file vfs_local.py.

00072 
00073     def reinit(self, baseurl, create=False):
00074         # We fake chdir so that it doesn't mess with the caller's 
00075         # perception of current working directory. This also benefits
00076         # unit tests. To do this, we store the baseurl as the cwd.
00077         tracing.trace('baseurl=%s', baseurl)
00078         tracing.trace('create=%s', create)
00079         self.cwd = os.path.abspath(baseurl)
00080         if not self.isdir('.'):
00081             if create:
00082                 tracing.trace('creating %s', baseurl)
00083                 try:
00084                     os.mkdir(baseurl)
00085                 except OSError, e: # pragma: no cover
00086                     # The directory might have been created concurrently
00087                     # by someone else!
00088                     if e.errno != errno.EEXIST:
00089                         raise
00090             else:
00091                 err = errno.ENOENT
00092                 raise OSError(err, os.strerror(err), self.cwd)

Here is the caller graph for this function:

def obnamlib.vfs_local.LocalFS.remove (   self,
  pathname 
)

Definition at line 121 of file vfs_local.py.

00121 
00122     def remove(self, pathname):
00123         tracing.trace('remove %s', pathname)
00124         os.remove(self.join(pathname))
00125         self.maybe_crash()

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.vfs_local.LocalFS.rename (   self,
  old,
  new 
)

Definition at line 126 of file vfs_local.py.

00126 
00127     def rename(self, old, new):
00128         tracing.trace('rename %s %s', old, new)
00129         os.rename(self.join(old), self.join(new))
00130         self.maybe_crash()

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.rmdir (   self,
  pathname 
)

Definition at line 250 of file vfs_local.py.

00250 
00251     def rmdir(self, pathname):
00252         tracing.trace('rmdir %s', pathname)
00253         os.rmdir(self.join(pathname))
00254         self.maybe_crash()

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.symlink (   self,
  existing,
  new 
)

Definition at line 208 of file vfs_local.py.

00208 
00209     def symlink(self, existing, new):
00210         tracing.trace('existing=%s', existing)
00211         tracing.trace('new=%s', new)
00212         os.symlink(existing, self.join(new))
00213         self.maybe_crash()

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.unlock (   self,
  lockname 
)

Definition at line 113 of file vfs_local.py.

00113 
00114     def unlock(self, lockname):
00115         tracing.trace('lockname=%s', lockname)
00116         if self.exists(lockname):
00117             self.remove(lockname)

Here is the call graph for this function:

def obnamlib.vfs_local.LocalFS.write_file (   self,
  pathname,
  contents 
)

Definition at line 269 of file vfs_local.py.

00269 
00270     def write_file(self, pathname, contents):
00271         tracing.trace('write_file %s', pathname)
00272         tempname = self._write_to_tempfile(pathname, contents)
00273         path = self.join(pathname)
00274         try:
00275             os.link(tempname, path)
00276         except OSError, e: # pragma: no cover
00277             os.remove(tempname)
00278             raise
00279         os.remove(tempname)
00280         self.maybe_crash()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 52 of file vfs_local.py.

Definition at line 63 of file vfs_local.py.

Definition at line 62 of file vfs_local.py.

Definition at line 78 of file vfs_local.py.


The documentation for this class was generated from the following file: