|
1 | 1 | from __future__ import print_function
|
2 | 2 | import os
|
3 |
| -import re |
4 | 3 |
|
5 |
| -node_version_h = os.path.join( |
6 |
| - os.path.dirname(__file__), |
7 |
| - '..', |
8 |
| - 'src', |
9 |
| - 'node_version.h') |
10 | 4 |
|
11 |
| -f = open(node_version_h) |
| 5 | +def get_major_minor_patch(text): |
| 6 | + for line in text.splitlines(): |
| 7 | + if line.startswith('#define NODE_MAJOR_VERSION'): |
| 8 | + major = line.split()[2] |
| 9 | + elif line.startswith('#define NODE_MINOR_VERSION'): |
| 10 | + minor = line.split()[2] |
| 11 | + elif line.startswith('#define NODE_PATCH_VERSION'): |
| 12 | + patch = line.split()[2] |
| 13 | + return major, minor, patch |
12 | 14 |
|
13 |
| -for line in f: |
14 |
| - if re.match('^#define NODE_MAJOR_VERSION', line): |
15 |
| - major = line.split()[2] |
16 |
| - if re.match('^#define NODE_MINOR_VERSION', line): |
17 |
| - minor = line.split()[2] |
18 |
| - if re.match('^#define NODE_PATCH_VERSION', line): |
19 |
| - patch = line.split()[2] |
20 | 15 |
|
21 |
| -print('%(major)s.%(minor)s.%(patch)s'% locals()) |
| 16 | +node_version_h = os.path.join(os.path.dirname(__file__), |
| 17 | + '..', |
| 18 | + 'src', |
| 19 | + 'node_version.h') |
| 20 | +with open(node_version_h) as in_file: |
| 21 | + print('.'.join(get_major_minor_patch(in_file.read()))) |
0 commit comments