chiptools.common.utils module
- class chiptools.common.utils.LogWrapper(logfn)[source]
Bases:
object
Simple class to provide a file interface using a logger message function
- chiptools.common.utils.call(command, path=None, shell=False)[source]
Call the executable in the given path, any messages the program generates will be routed to stdout and stderr.
- chiptools.common.utils.get_date_string()[source]
Return a pretty formatted date string to indicate the time of an event.
- chiptools.common.utils.iterate_tests(test_suite_or_case)[source]
Iterate through all of the test cases in ‘test_suite_or_case’.
- chiptools.common.utils.parse_range(astr)[source]
Parse the input string numeric range and return a set of numbers. >>> parse_range(‘1-3, 5, 8, 10’) [1, 2, 3, 5, 8, 10] >>> parse_range(‘1, 2, 3, 4, 5’) [1, 2, 3, 4, 5] >>> parse_range(‘1-5, 9-5’) # Negative ranges are ignored [1, 2, 3, 4, 5]
- chiptools.common.utils.popen_quiet(command, path=None)[source]
Call the executable in the given path and return the standard output and error streams.
- chiptools.common.utils.popen_throws_ex(command, path=None, quiet=False)[source]
Call the executable in the given path, hiding standard output unless the return value is an error. If the return value is an error raise an exception for the caller to handle.
- chiptools.common.utils.relative_path_to_abs(path, root='/home/nerdboy/src/chiptools/docs')[source]
If the path is relative convert it into an absolute path. This is the same as calling os.path.abspath(path), but with an option to override the default root of os.getcwd() and with normalisation and expansion of environment variables on the input path.
- chiptools.common.utils.seconds_to_timestring(duration)[source]
Return a formatted time-string for the given duration in seconds. Provides auto-rescale/formatting for values down to ns resolution >>> seconds_to_timestring(1.0) ‘1.0s’ >>> seconds_to_timestring(100e-3) ‘100.0ms’ >>> seconds_to_timestring(500e-6) ‘500.0us’ >>> seconds_to_timestring(20000.0) ‘20000.0s’ >>> seconds_to_timestring(453e-9) ‘453.0ns’ >>> seconds_to_timestring(3000e-9) ‘3.0us’ >>> seconds_to_timestring(100e-12) ‘0.1ns’
- chiptools.common.utils.self_test(modname='chiptools.__init__')[source]
Basic sanity check using mod import.
- chiptools.common.utils.subgraph(graph, root)[source]
Given a graph represented by a dictionary of key (node) and value (set of child nodes) and a root node, return a new graph representing the root node and its hierarchy. >>> graph = { … 2 : set([11]), … 9 : set([11, 8]), … 10 : set([11, 3]), … 11 : set([5, 7]), … 8 : set([7, 3]), … 5 : set(), … 7 : set(), … 3 : set([5]) … } >>> subgraph(graph, 8) {8: {3, 7}, 3: {5}, 5: set(), 7: set()}
- chiptools.common.utils.time_delta_string(start_time, end_time)[source]
Return a string representing the time delta in ms >>> time_delta_string(50e-3, 100e-3) ‘50.0ms’
- chiptools.common.utils.topological_sort(graph)[source]
Perform a topological sort on the graph and return a list of sorted nodes. The graph is represented as a dictionary where each key is a node and the value is a list/set of connected child nodes. >>> graph = { … 2 : set([11]), … 9 : set([11, 8]), … 10 : set([11, 3]), … 11 : set([5, 7]), … 8 : set([7, 3]), … 5 : set(), … 7 : set(), … 3 : set() … } >>> topological_sort(graph) [3, 7, 5, 8, 11, 2, 9, 10]