Skip to content

Instantly share code, notes, and snippets.

@jrepp
Created October 14, 2017 23:52
Show Gist options
  • Select an option

  • Save jrepp/1e019ff9f8dc26b53da4bf8a23ee27b0 to your computer and use it in GitHub Desktop.

Select an option

Save jrepp/1e019ff9f8dc26b53da4bf8a23ee27b0 to your computer and use it in GitHub Desktop.
Python script to extract define tokens from the C++ build constants
#define BUILD_ID 42123
#define BUILD_NAME "branches/GM-2"
#define BUILD_ID_TYPE 5
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