Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: cleanup getnodeversion.py for readability #29648

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions tools/getnodeversion.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from __future__ import print_function
import os
import re

node_version_h = os.path.join(
os.path.dirname(__file__),
'..',
'src',
'node_version.h')

f = open(node_version_h)
def get_major_minor_patch(text):
for line in text.splitlines():
if line.startswith('#define NODE_MAJOR_VERSION'):
major = line.split()[2]
elif line.startswith('#define NODE_MINOR_VERSION'):
minor = line.split()[2]
elif line.startswith('#define NODE_PATCH_VERSION'):
patch = line.split()[2]
return major, minor, patch

for line in f:
if re.match('^#define NODE_MAJOR_VERSION', line):
major = line.split()[2]
if re.match('^#define NODE_MINOR_VERSION', line):
minor = line.split()[2]
if re.match('^#define NODE_PATCH_VERSION', line):
patch = line.split()[2]

print('%(major)s.%(minor)s.%(patch)s'% locals())
node_version_h = os.path.join(os.path.dirname(__file__),
'..',
'src',
'node_version.h')
with open(node_version_h) as in_file:
print('.'.join(get_major_minor_patch(in_file.read())))