Created
October 14, 2017 23:52
-
-
Save jrepp/1e019ff9f8dc26b53da4bf8a23ee27b0 to your computer and use it in GitHub Desktop.
Python script to extract define tokens from the C++ build constants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define BUILD_ID 42123 | |
| #define BUILD_NAME "branches/GM-2" | |
| #define BUILD_ID_TYPE 5 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| def main(): | |
| bag = {} | |
| exprs = [ | |
| ( re.compile(r'^#define BUILD_ID\s+(\d+)'), 'build_id' ), | |
| ( re.compile(r'^#define BUILD_NAME\s+"(\S+)"'), 'build_name' ), | |
| ] | |
| with open('buildver.h', 'r') as f: | |
| for l in f.readlines(): | |
| for expr, var in exprs: | |
| m = expr.match(l) | |
| if m and len(m.groups()) > 0: | |
| bag[var] = m.group(1) | |
| for k, v in bag.iteritems(): | |
| print('{} -> {}'.format(k, v)) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment