From b7488c2a5c5e354809e98a1a02b2be5a8ef907f8 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 21 Sep 2019 21:54:27 +0200 Subject: [PATCH] tools: cleanup getnodeversion.py for readability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/29648 Reviewed-By: Anna Henningsen Reviewed-By: David Carlier Reviewed-By: Michaƫl Zasso Reviewed-By: Ben Noordhuis Reviewed-By: Richard Lau Reviewed-By: Ruben Bridgewater --- tools/getnodeversion.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tools/getnodeversion.py b/tools/getnodeversion.py index c9f82160c0f386..b362950dd3661a 100644 --- a/tools/getnodeversion.py +++ b/tools/getnodeversion.py @@ -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())))