Skip to content

Commit b7488c2

Browse files
cclaussBridgeAR
authored andcommitted
tools: cleanup getnodeversion.py for readability
PR-URL: #29648 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 5d60adf commit b7488c2

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

tools/getnodeversion.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
from __future__ import print_function
22
import os
3-
import re
43

5-
node_version_h = os.path.join(
6-
os.path.dirname(__file__),
7-
'..',
8-
'src',
9-
'node_version.h')
104

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
1214

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]
2015

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

Comments
 (0)