Module Suitcase


[Contents] [Prev] [Next]
Table of Contents

Introduction

KPs don't normally need to import this module or instantiate its classes. They receive an instance of its main class, SuitcaseFilesystem, as the return value of the get_suitcase() method of the KOS bastion. Instances of the other two classes are accessible through this class.

Some other tools in the KOE use this module explicitly to simplify the use of the suitcase part of the KP representation object.

Classes

SuitcaseFilesystem (repr) -> instance
This class provides an interface to the KP's suitcase that ``feels'' like Python's os module. Methods are listed below. The data attribute path is an instance of the SuitcaseFilesystemPath class described below. Other data attributes are not available. The suitcase filesystem uses a '/' as a delimiter, '.' for the current directory, and '..' for the parent directory. There is no environment, path separator, or default path associated with the suitcase filesystem.

SuitcaseFilesystemPath (sfs) -> instance
This class provides an additional interface to the KP's suitcase that ``feels'' like Python's os.path interface. Methods are listed below.

SuitcaseFile (sfs, path[, mode]) -> instance
This class implements a file object returned by the open() method of the SuitcaseFilesystem class above. It behaves similar to standard Python open file objects, and is in fact implemented as a subclass of the standard Python library class StringIO.StringIO. Methods are listed below.

SuitcaseFilesystem Objects

Instances of the SuitcaseFilesystem class have the following methods. Unless noted otherwise, these raise IOError for exceptions. For more elaborate descriptions of the very similar standard functions see the section on standard module posix in the Python Library Reference (except that the open() method here is more like Python's built-in open() function than like posix.open()).

mkdir (path)
Create a directory.

open (path[, mode]) -> file-like instance
Open a file; mode can be 'r' for reading or 'w' for writing ('a' mode and the '+' modes are not supported). Return an instance of SuitcaseFile.

open_gz (path[, mode[, compessionlevel]]) -> file-like instance
Open a compressed file. If the gzip module cannot be imported, this raises the Nogzip exception. The argument mode is as for open() above. When opening for writing, compressionlevel is the desired compression level, from 0 (least compression, fastest) to 9 (maximum compression, slowest), defaulting to 9.

chdir (path)
Change the current working directory.

getcwd () -> string
Return the full pathname of the current working directory.

listdir (path) -> list of strings
Return a list of names of files in a directory.

unlink (path)
remove (path)
Remove a file (two names for the same function).

rmdir (path)
Remove a directory.

SuitcaseFilesystemPath Objects

Instances of the SuitcaseFilesystemPath class have the following methods. For descriptions see the section on standard module posixpath in the Python Library Reference.

exists (path) -> Boolean
isdir (path) -> Boolean
isfile (path) -> Boolean
normcase (path) -> string
isabs (path) -> Boolean
split (path) -> (string, string)
join (path1, *paths) -> string
splitext (path) -> (string, string)
splitdrive (path) -> (string, string)
basename (path) -> string
dirname (path) -> string
commonprefix (path) -> string
samefile (path1, path2) -> Boolean
sameopenfile (file1, file2) -> Boolean
normpath (path) -> string
walk (root, func, arg)

SuitcaseFile Objects

Instances of the SuitcaseFile class have the following methods. For descriptions see the section on file objects in the Python Library Reference.

read ([nbytes]) -> string
readline () -> string
readlines () -> list of strings
write (string)
writelines (list)
tell () -> integer
seek (pos[, how])
flush ()
isatty () -> Boolean (always false)
close ()

There is no fileno() method.

Exception

Nogzip
Raised when the gzip module cannot be imported successfully.

Table of Contents

[Contents] [Prev] [Next]
Copyright © 1998 by the Corporation for National Research Initiatives.