msl.equipment.resources.utils module

Utility functions/classes to help create modules in the msl.equipment.resources package.

msl.equipment.resources.utils.camelcase_to_underscore(text)[source]

Converts CamelCaseText to camel_case_text.

Parameters

text (str) – The camel-case text to be converted.

Returns

str – The text converted to lowercase and separated by underscores.

msl.equipment.resources.utils.get_lines(path, remove_comments=True)[source]

Returns the lines in a C/C++ header file that are not empty.

Also strips the whitespace from each line and can optionally remove the comments.

Parameters
  • path (str) – The path to a C/C++ header file.

  • remove_comments (bool, optional) – Whether to remove the comments.

Returns

list of str – The list of lines in the header file.

class msl.equipment.resources.utils.CHeader(path, remove_comments=True)[source]

Bases: object

Parses a C/C++ header file to determine the constants, enums, structs, callbacks and the function signatures.

Parameters
  • path (str) – The path to the header file.

  • remove_comments (bool, optional) – Whether to remove the comments.

constants(ignore_ifdef=True)[source]

Finds the #define statements that are in the C/C++ header file.

Parameters

ignore_ifdef (bool, optional) – Whether to ignore the #define statements in between the #ifdef and #endif statements.

Returns

dict – A dictionary of all the #define constants (as strings).

enums()[source]
Returns

dict – The enums that are defined in the C/C++ header file. The value for each dictionary key is a tuple of (the enum name, the enum data type, a dict of name-value pairs).

structs()[source]
Returns

dict – The structs that are defined in the C/C++ header file.

callbacks()[source]
Returns

dict – The callbacks that are defined in the C/C++ header file.

functions(regex)[source]

Returns the function signatures.

Parameters

regex (str) –

The regex must contain 2 groups, (return type)(function name), and it must match the function declaration up until, but excluding, the ( which begins the argument declarations.

For example,

If the function declarations are similar to FILTERFLIPPERDLL_API unsigned int __cdecl FF_GetTransitTime(const char * serialNo); then the value of regex could be r'_API\s+([\w\s]+?)__cdecl\s+(\w+)'

If the function declarations are similar to PREF0 PREF1 PICO_STATUS PREF2 PREF3 (ps6000OpenUnit)(int16_t *handle, int8_t *serial); then the value of regex could be r'PREF0\s+PREF1\s+(\w+)\s+PREF2\s+PREF3\s+\((\w+)\)'

Returns

dict – The function signature. The key is the function name and the value is a list of [return type, [(argument data type, argument name), ... ] ].

get_lines()[source]
Returns

list of str – The lines in the C/C++ header file.

get_struct_imports()[source]
Returns

list of str – The list of structs that must be imported for the C/C++ functions.

Note

Must call functions() first.

static get_text_between_brackets(lines, index, bracket1, bracket2)[source]

Get all the text (excluding comments) between two brackets.

Parameters
  • lines (list of str) – A list of lines, see get_lines().

  • index (int) – The current index in lines.

  • bracket1 (str) – One of {, (, or [

  • bracket2 (str) – One of }, ) or ]

Returns

  • str – The text between bracket1 and bracket2.

  • int – The current index in lines.