Home | Trees | Indices | Help |
|
---|
|
Author: Kenneth J. Pronovici <pronovic@ieee.org>
|
|||
AbsolutePathList Class representing a list of absolute paths. |
|||
ObjectTypeList Class representing a list containing only objects with a certain type. |
|||
RegexMatchList Class representing a list containing only strings that match a regular expression. |
|||
RegexList Class representing a list of valid regular expression strings. |
|||
_Vertex Represents a vertex (or node) in a directed graph. |
|||
DirectedGraph Represents a directed graph. |
|||
PathResolverSingleton Singleton used for resolving executable paths. |
|||
UnorderedList Class representing an "unordered list". |
|||
RestrictedContentList Class representing a list containing only object with certain values. |
|||
Pipe Specialized pipe class for use by executeCommand .
|
|||
Diagnostics Class holding runtime diagnostic information. |
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
ISO_SECTOR_SIZE = 2048.0 Size of an ISO image sector, in bytes. |
|||
BYTES_PER_SECTOR = 2048.0 Number of bytes (B) per ISO sector. |
|||
BYTES_PER_KBYTE = 1024.0 Number of bytes (B) per kilobyte (kB). |
|||
BYTES_PER_MBYTE = 1048576.0 Number of bytes (B) per megabyte (MB). |
|||
BYTES_PER_GBYTE = 1073741824.0 Number of bytes (B) per megabyte (GB). |
|||
KBYTES_PER_MBYTE = 1024.0 Number of kilobytes (kB) per megabyte (MB). |
|||
MBYTES_PER_GBYTE = 1024.0 Number of megabytes (MB) per gigabyte (GB). |
|||
SECONDS_PER_MINUTE = 60.0 Number of seconds per minute. |
|||
MINUTES_PER_HOUR = 60.0 Number of minutes per hour. |
|||
HOURS_PER_DAY = 24.0 Number of hours per day. |
|||
SECONDS_PER_DAY = 86400.0 Number of seconds per day. |
|||
UNIT_BYTES = 0 Constant representing the byte (B) unit for conversion. |
|||
UNIT_KBYTES = 1 Constant representing the kilobyte (kB) unit for conversion. |
|||
UNIT_MBYTES = 2 Constant representing the megabyte (MB) unit for conversion. |
|||
UNIT_GBYTES = 4 Constant representing the gigabyte (GB) unit for conversion. |
|||
UNIT_SECTORS = 3 Constant representing the ISO sector unit for conversion. |
|||
_UID_GID_AVAILABLE = True
|
|||
_PIPE_IMPLEMENTATION =
|
|||
logger = logging.getLogger("CedarBackup2.log.util")
|
|||
outputLogger = logging.getLogger("CedarBackup2.output")
|
|||
MTAB_FILE =
|
|||
MOUNT_COMMAND =
|
|||
UMOUNT_COMMAND =
|
|||
DEFAULT_LANGUAGE =
|
|||
LANG_VAR =
|
|||
LOCALE_VARS =
|
|
|
Converts a size in one unit to a size in another unit. This is just a convenience function so that the functionality can be implemented in just one place. Internally, we convert values to bytes and then to the final unit. The available units are:
|
Get the uid/gid associated with a user/group pair This is a no-op if user/group functionality is not available on the platform.
|
Changes ownership of path to match the user and group. This is a no-op if user/group functionality is not available on the platform, or if the either passed-in user or group isNone .
|
Splits a command line string into a list of arguments. Unfortunately, there is no "standard" way to parse a command
line string, and it's actually not an easy problem to solve portably
(essentially, we have to emulate the shell argument-processing logic).
This code only respects double quotes (
|
Resolves the real path to a command through the path resolver mechanism. Both extensions and standard Cedar Backup functionality need a way to resolve the "real" location of various executables. Normally, they assume that these executables are on the system path, but some callers need to specify an alternate location. Ideally, we want to handle this configuration in a central location. The Cedar Backup path resolver mechanism (a singleton called PathResolverSingleton) provides the central location to store the mappings. This function wraps access to the singleton, and is what all functions (extensions or standard functionality) should call if they need to find a command. The passed-in command must actually be a list, in the standard form
used by all existing Cedar Backup code (something like
|
Executes a shell command, hopefully in a safe way. This function exists to replace direct calls to Instead, it's safer to pass a list of arguments in the style supported
bt Under the normal case, this function will return a tuple of
By default, The outputFile parameter exists to make it easier for a
caller to push output into a file, i.e. as a substitute for redirection
to a file. If this value is passed in, each time a line of output is
generated, it will be written to the file using
outputFile.write() . At the end, the file descriptor will be
flushed using outputFile.flush() . The caller maintains
responsibility for closing the file object appropriately.
Notes:
|
Calculates the age (in days) of a file. The "age" of a file is the amount of time since the file was
last used, per the most recent of the file's
|
Safely encodes a filesystem path. Many Python filesystem functions, such as However, this behavior often isn't as consistent as we might like. As
an example, os.listdir behavior like this:
The operating system (POSIX) does not have the inherent notion that file names are character strings. Instead, in POSIX, file names are primarily byte strings. There are some bytes which are interpreted as characters (e.g. '\x2e', which is '.', or '\x2f', which is '/'), but apart from that, most OS layers think these are just bytes. Now, most *people* think that file names are character strings. To interpret a file name as a character string, you need to know what the encoding is to interpret the file names (which are byte strings) as character strings. There is, unfortunately, no operating system API to carry the notion of a file system encoding. By convention, the locale settings should be used to establish this encoding, in particular the LC_CTYPE facet of the locale. This is defined in the environment variables LC_CTYPE, LC_ALL, and LANG (searched in this order). If LANG is not set, the "C" locale is assumed, which uses ASCII as its file system encoding. In this locale, '\xe2\x99\xaa\xe2\x99\xac' is not a valid file name (at least it cannot be interpreted as characters, and hence not be converted to Unicode). Now, your Python script has requested that all file names *should* be returned as character (ie. Unicode) strings, but Python cannot comply, since there is no way to find out what this byte string means, in terms of characters. So we have three options: 1. Skip this string, only return the ones that can be converted to Unicode. Give the user the impression the file does not exist. 2. Return the string as a byte string 3. Refuse to listdir altogether, raising an exception (i.e. return nothing) Python has chosen alternative 2, allowing the application to implement 1 or 3 on top of that if it wants to (or come up with other strategies, such as user feedback). As a solution, he suggests that rather than passing unicode paths into the filesystem functions, that I should sensibly encode the path first. That is what this function accomplishes. Any function which takes a filesystem path as an argument should encode it first, before using it for any other purpose. I confess I still don't completely understand how this works. On a system with filesystem encoding "ISO-8859-1", a pathu"\xe2\x99\xaa\xe2\x99\xac" is converted into the
string "\xe2\x99\xaa\xe2\x99\xac" . However, on a
system with a "utf-8" encoding, the result is a completely
different string:
"\xc3\xa2\xc2\x99\xc2\xaa\xc3\xa2\xc2\x99\xc2\xac" .
A quick test where I write to the first filename and open the second
proves that the two strings represent the same file on disk, which is all
I really care about.
Notes:
|
Attempts to portably return the null device on this system. The null device is something like os.devnull . Since
we want to be portable to python 2.3, getting the value in earlier
versions of Python takes some screwing around. Basically, this function
will only work on either UNIX-like systems (the default) or Windows.
|
Converts English day name to numeric day of week as from
monday would be converted to the
number 0 .
|
Indicates whether "today" is the backup starting day per configuration. If the current day's English name matches the indicated starting day, then today is a starting day.
|
Returns a "normalized" path based on a path name. A normalized path is a representation of a path that is also a valid
file name. To make a valid file name out of a complete path, we have to
convert or remove some characters that are significant to the filesystem
-- in particular, the path separator and any leading Note that this is a one-way transformation -- you can't safely derive the original path from the normalized path. To normalize a path, we begin by looking at the first character. If
the first character is '/'
or '\' character will be converted to '-' .
|
|
Format a byte quantity so it can be sensibly displayed. It's rather difficult to look at a number like "72372224 bytes" and get any meaningful information out of it. It would be more useful to see something like "69.02 MB". That's what this function does. Any time you want to display a byte value, i.e.:print "Size: %s bytes" % bytesCall this function instead: print "Size: %s" % displayBytes(bytes)What comes out will be sensibly formatted. The indicated number of digits will be listed after the decimal point, rounded based on whatever rules are used by Python's standard %f string format
specifier. (Values less than 1 kB will be listed in bytes and will not
have a decimal point, since the concept of a fractional byte is
nonsensical.)
|
Gets a reference to a named function. This does some hokey-pokey to get back a reference to a dynamically named function. For instance, say you wanted to get a reference to theos.path.isdir function. You could use:
myfunc = getFunctionReference("os.path", "isdir") Although we won't bomb out directly, behavior is pretty much undefined
if you pass in The only validation we enforce is that whatever we get back must be callable. I derived this code based on the internals of the Python unittest implementation. I don't claim to completely understand how it works.
Copyright: Some of this code, prior to customization, was originally part of the Python 2.3 codebase. Python code is copyright (c) 2001, 2002 Python Software Foundation; All Rights Reserved. |
Mounts the indicated device at the indicated mount point. For instance, to mount a CD, you might use device path/dev/cdrw , mount point /media/cdrw and
filesystem type iso9660 . You can safely use any filesystem
type that is supported by mount on your platform. If the
type is None , we'll attempt to let mount
auto-detect it. This may or may not work on all systems.
Note:
This only works on platforms that have a concept of
"mounting" a filesystem through a command-line
|
Unmounts whatever device is mounted at the indicated mount point. Sometimes, it might not be possible to unmount the mount point
immediately, if there are still files open there. Use the
If the indicated mount point is not really a mount point per
removeAfter is True , then the mount point
will be removed using os.rmdir() after the unmount action
succeeds. If for some reason the mount point is not a directory, then it
will not be removed.
Note:
This only works on platforms that have a concept of
"mounting" a filesystem through a command-line
|
Indicates whether a specific filesystem device is currently mounted. We determine whether the device is mounted by looking through the system'smtab file. This file shows every currently-mounted
filesystem, ordered by device. We only do the check if the
mtab file exists and is readable. Otherwise, we assume that
the device is not mounted.
Note: This only works on platforms that have a concept of an mtab file to show mounted volumes, like UNIXes. It won't work on Windows. |
Sanitizes the operating system environment. The operating system environment is contained in
Currently, all it does is reset the locale (removing
os.environ dictionary is modifed in-place. If
$LANG is already set to the proper value, it is not re-set,
so we can avoid the memory leaks that are documented to occur on
BSD-based systems.
|
|
|
LOCALE_VARS
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Sat Nov 15 12:16:54 2008 | http://epydoc.sourceforge.net |