Helper functions and data structures used by pavements.
Specifies that this function is a task.
Note that this decorator does not actually replace the function object. It just keeps track of the task and sets an is_task flag on the function object.
Specifies tasks upon which this task depends.
req can be a string or a list of strings with the names of the tasks. You can call this decorator multiple times and the various requirements are added on. You can also call with the requirements as a list of arguments.
The requirements are called in the order presented in the list.
Wraps a function that performs a destructive operation, so that nothing will happen when a dry run is requested.
Runs func with the given arguments and keyword arguments. If this is a dry run, print the message rather than running the function.
DEPRECATED. Just call the task instead.
Calls the desired task, including any tasks upon which that task depends. options is an optional dictionary that will be added to the option lookup search order.
You can always call a task directly by calling the function directly. But, if you do so the dependencies aren’t called. call_task ensures that these are called.
Note that call_task will only call the task once during a given build as long as the options remain the same. If the options are changed, the task will be called again.
GONE. There is no equivalent in Paver 1.0. Calling this will raise an exception.
A set of dotted-notation keys that must be present in the options for this task to be relevant.
Runs an external command. If capture is True, the output of the command will be captured and returned as a string. If the command has a non-zero return code raise a BuildFailure. You can pass ignore_error=True to allow non-zero return codes to be allowed to pass silently, silently into the night.
If the dry_run option is True, the command will not actually be run.
Represents a filesystem path.
For documentation on individual methods, consult their counterparts in os.path.
Return true if current user has access to this path.
mode - One of the constants os.F_OK, os.R_OK, os.W_OK, os.X_OK
D.dirs() -> List of this directory’s subdirectories.
The elements of the list are path objects. This does not walk recursively into subdirectories (but see path.walkdirs).
With the optional ‘pattern’ argument, this only lists directories whose names match the given pattern. For example:
d.dirs('build-*')
Clean up a filename by calling expandvars(), expanduser(), and normpath() on it.
This is commonly everything needed to clean up a filename read from a configuration file, for example.
D.files() -> List of the files in this directory.
The elements of the list are path objects. This does not walk into subdirectories (see path.walkfiles).
With the optional ‘pattern’ argument, this only lists files whose names match the given pattern. For example:
d.files('*.pyc')
Return True if self.name matches the given pattern.
Return the name of the owner of this file or directory.
This follows symbolic links.
On Windows, this returns a name of the form ur’DOMAINUser Name’. On Windows, a group can own a file or directory.
Return a list of path objects that match the pattern.
pattern - a path relative to this directory, with wildcards.
For example, path(‘/users’).glob(‘/bin/‘) returns a list of all the files users have in their bin directories.
Open this file, read all lines, return them in a list.
This uses ‘U’ mode in Python 2.3 and later.
D.listdir() -> List of items in this directory.
Use D.files() or D.dirs() instead if you want a listing of just files or just subdirectories.
The elements of the list are path objects.
With the optional ‘pattern’ argument, this only lists items whose names match the given pattern.
The name of this file or directory without the full path.
For example, path(‘/usr/local/lib/libpython.so’).name == ‘libpython.so’
The same as path.name, but with one file extension stripped off.
For example, path(‘/home/guido/python.tar.gz’).name == ‘python.tar.gz’, but path(‘/home/guido/python.tar.gz’).namebase == ‘python.tar’
This path’s parent directory, as a new path object.
For example, path(‘/usr/local/lib/libpython.so’).parent == path(‘/usr/local/lib’)
Calculate the md5 hash for this file.
This reads through the entire file.
Return the path to which this symbolic link points.
The result may be an absolute or a relative path.
Return the path to which this symbolic link points.
The result is always an absolute path.
Return a relative path from self to dest.
If there is no relative path from self to dest, for example if they reside on different drives in Windows, then this returns dest.abspath().
Return a list of the path components in this path.
The first item in the list will be a path. Its value will be either os.curdir, os.pardir, empty, or the root directory of this path (for example, ‘/’ or ‘C:\’). The other items in the list will be strings.
path.path.joinpath(*result) will yield the original path.
p.splitdrive() -> Return (p.drive, <the rest of p>).
Split the drive specifier from this path. If there is no drive specifier, p.drive is empty, so the return value is simply (path(‘’), p). This is always the case on Unix.
p.splitext() -> Return (p.stripext(), p.ext).
Split the filename extension from this path and return the two parts. Either part may be empty.
The extension is everything from ‘.’ to the end of the last path segment. This has the property that if (a, b) == p.splitext(), then a + b == p.
p.stripext() -> Remove one file extension from the path.
For example, path(‘/home/guido/python.tar.gz’).stripext() returns path(‘/home/guido/python.tar’).
Open this file, read it in, return the content as a string.
This uses ‘U’ mode in Python 2.3 and later, so ‘rn’ and ‘r’ are automatically translated to ‘n’.
Optional arguments:
D.walk() -> iterator over files and subdirs, recursively.
The iterator yields path objects naming each child item of this directory and its descendants. This requires that D.isdir().
This performs a depth-first traversal of the directory tree. Each directory is returned just before all its children.
The errors= keyword argument controls behavior when an error occurs. The default is ‘strict’, which causes an exception. The other allowed values are ‘warn’, which reports the error via warnings.warn(), and ‘ignore’.
D.walkdirs() -> iterator over subdirs, recursively.
With the optional ‘pattern’ argument, this yields only directories whose names match the given pattern. For example, mydir.walkdirs('*test') yields only directories with names ending in ‘test’.
The errors= keyword argument controls behavior when an error occurs. The default is ‘strict’, which causes an exception. The other allowed values are ‘warn’, which reports the error via warnings.warn(), and ‘ignore’.
D.walkfiles() -> iterator over files in D, recursively.
The optional argument, pattern, limits the results to files with names that match the pattern. For example, mydir.walkfiles('*.tmp') yields only files with the .tmp extension.
Open this file and write the given bytes to it.
Default behavior is to overwrite any existing file. Call p.write_bytes(bytes, append=True) to append instead.
Write the given lines of text to this file.
By default this overwrites any existing file at this path.
This puts a platform-specific newline sequence on every line. See ‘linesep’ below.
lines - A list of strings.
Use the keyword argument append=True to append lines to the file. The default is to overwrite the file. Warning: When you use this with Unicode data, if the encoding of the existing data in the file is different from the encoding you specify with the encoding= parameter, the result is mixed-encoding data, which can really confuse someone trying to read the file later.
Write the given text to this file.
The default behavior is to overwrite any existing file; to append instead, use the ‘append=True’ keyword argument.
There are two differences between path.write_text() and path.write_bytes(): newline handling and Unicode handling. See below.
Parameters:
- text - str/unicode - The text to be written.
- encoding - str - The Unicode encoding that will be used. This is ignored if ‘text’ isn’t a Unicode string.
- errors - str - How to handle Unicode encoding errors. Default is ‘strict’. See help(unicode.encode) for the options. This is ignored if ‘text’ isn’t a Unicode string.
- linesep - keyword argument - str/unicode - The sequence of characters to be used to mark end-of-line. The default is os.linesep. You can also specify None; this means to leave all newlines as they are in ‘text’.
- append - keyword argument - bool - Specifies what to do if the file already exists (True: append to the end of it; False: overwrite it.) The default is False.
— Newline handling.
write_text() converts all standard end-of-line sequences (‘n’, ‘r’, and ‘rn’) to your platform’s default end-of-line sequence (see os.linesep; on Windows, for example, the end-of-line marker is ‘rn’).
If you don’t like your platform’s default, you can override it using the ‘linesep=’ keyword argument. If you specifically want write_text() to preserve the newlines as-is, use ‘linesep=None’.
This applies to Unicode text the same as to 8-bit text, except there are three additional standard Unicode end-of-line sequences: u’x85’, u’rx85’, and u’u2028’.
(This is slightly different from when you open a file for writing with fopen(filename, “w”) in C or file(filename, ‘w’) in Python.)
— Unicode
If ‘text’ isn’t Unicode, then apart from newline handling, the bytes are written verbatim to the file. The ‘encoding’ and ‘errors’ arguments are not used and must be omitted.
If ‘text’ is Unicode, it is first converted to bytes using the specified ‘encoding’ (or the default encoding if ‘encoding’ isn’t specified). The ‘errors’ argument applies only to this conversion.
Sets the command line options that can be set for this task. This uses the same format as the distutils command line option parser. It’s a list of tuples, each with three elements: long option name, short option, description.
If the long option name ends with ‘=’, that means that the option takes a value. Otherwise the option is just boolean. All of the options will be stored in the options dict with the name of the task. Each value that gets stored in that dict will be stored with a key that is based on the long option name (the only difference is that - is replaced by _).