Utilities and platform-specific fixes
The portability fixes try to provide a consistent behavior of the Waf API through Python versions 2.3 to 3.X and across different platforms (win32, linux, etc)
Arbitrary null value for a md5 hash. This value must be changed when the hash value is replaced (size)
Constant representing the permissions for regular files (0644 raises a syntax error on python 3)
Constant representing the permissions for executable files (0755 raises a syntax error on python 3)
List of characters to use when displaying the throbber (progress bar)
Index of the current throbber character (progress bar)
Read an entire file into a string, in practice the wrapper node.read(..) should be used instead of this method:
def build(ctx):
from waflib import Utils
txt = Utils.readf(self.path.find_node('wscript').abspath())
txt = ctx.path.find_node('wscript').read()
Parameters: |
|
---|---|
Return type: | string |
Returns: | Content of the file |
Compute a hash value for a file by using md5. This method may be replaced by a faster version if necessary. The following uses the file size and the timestamp value:
import stat
from waflib import Utils
def h_file(filename):
st = os.stat(filename)
if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
m = Utils.md5()
m.update(str(st.st_mtime))
m.update(str(st.st_size))
m.update(filename)
return m.digest()
Utils.h_file = h_file
Parameters: | filename (string) – path to the file to hash |
---|---|
Returns: | hash of the file contents |
Return the hexadecimal representation of a string
Parameters: | s (string) – string to convert |
---|
Convert a string, tuple or version number into an integer. The number is supposed to have at most 4 digits:
from waflib.Utils import num2ver
num2ver('1.3.2') == num2ver((1,3,2)) == num2ver((1,3,2,0))
Parameters: | ver (string or tuple of numbers) – a version number |
---|
Extract the stack to display exceptions
Returns: | a string represening the last exception |
---|
Convert a string argument to a list by splitting on spaces, and pass through a list argument unchanged:
from waflib.Utils import to_list
lst = to_list("a b c d")
Parameters: | sth – List or a string of items separated by spaces |
---|---|
Return type: | list |
Returns: | Argument converted to list |
Parse a string with key = value pairs into a dictionary:
from waflib import Utils
x = Utils.str_to_dict('''
a = 1
b = test
''')
Parameters: | s (string) – String to parse |
---|---|
Return type: | dict |
Returns: | Dictionary containing parsed key-value pairs |
Split a path by / or . This function is not like os.path.split
Parameters: | path (string) – path to split |
---|---|
Returns: | list of strings |
Ensure that a directory exists (similar to mkdir -p).
Parameters: | dir (string) – Path to directory |
---|
Set default attributes on a class instance
Parameters: |
|
---|
Convert a string to an identifier suitable for C defines.
Parameters: | s (string) – String to convert |
---|---|
Return type: | string |
Returns: | Identifier suitable for C defines |
Hash lists. For tuples, using hash(tup) is much more efficient
Parameters: | lst (list of strings) – list to hash |
---|---|
Returns: | hash of the list |
Hash functions
Parameters: | fun (function) – function to hash |
---|---|
Returns: | hash of the function |
Replace ${VAR} with the value of VAR taken from a dict or a config set:
from waflib import Utils
s = Utils.subst_vars('${PREFIX}/bin', env)
Parameters: |
|
---|
Return the binary format based on the unversioned platform name.
Parameters: | key (string) – platform name |
---|---|
Returns: | string representing the binary format |
Return the unversioned platform name. Some Python platform names contain versions, that depend on the build environment, e.g. linux2, freebsd6, etc. This returns the name without the version number. Exceptions are os2 and win32, which are returned verbatim.
Return type: | string |
---|---|
Returns: | Unversioned platform name |
Bases: object
Simple object for timing the execution of commands. Its string representation is the current time:
from waflib.Utils import Timer
timer = Timer()
a_few_operations()
s = str(timer)
Read property files, used by msvc.py
Parameters: | path (string) – file to read |
---|