11cb0ef41Sopenharmony_cifrom __future__ import print_function 21cb0ef41Sopenharmony_ciimport os 31cb0ef41Sopenharmony_ciimport re 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_cidef get_version(): 71cb0ef41Sopenharmony_ci node_version_h = os.path.join( 81cb0ef41Sopenharmony_ci os.path.dirname(__file__), 91cb0ef41Sopenharmony_ci '..', 101cb0ef41Sopenharmony_ci 'src', 111cb0ef41Sopenharmony_ci 'node_version.h') 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci f = open(node_version_h) 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci regex = '^#define NODE_MODULE_VERSION [0-9]+' 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci for line in f: 181cb0ef41Sopenharmony_ci if re.match(regex, line): 191cb0ef41Sopenharmony_ci major = line.split()[2] 201cb0ef41Sopenharmony_ci return major 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci raise Exception('Could not find pattern matching %s' % regex) 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciif __name__ == '__main__': 261cb0ef41Sopenharmony_ci print(get_version()) 27