Rizin
unix-like reverse engineering framework and cli tools
GetLz4LibraryVersion.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # #############################################################################
3 # Copyright (c) 2018-present lzutao <taolzu(at)gmail.com>
4 # All rights reserved.
5 #
6 # This source code is licensed under both the BSD-style license (found in the
7 # LICENSE file in the root directory of this source tree) and the GPLv2 (found
8 # in the COPYING file in the root directory of this source tree).
9 # #############################################################################
10 import re
11 
12 
13 def find_version_tuple(filepath):
14  version_file_data = None
15  with open(filepath) as fd:
16  version_file_data = fd.read()
17 
18  patterns = r"""#\s*define\s+LZ4_VERSION_MAJOR\s+([0-9]+).*$
19 #\s*define\s+LZ4_VERSION_MINOR\s+([0-9]+).*$
20 #\s*define\s+LZ4_VERSION_RELEASE\s+([0-9]+).*$
21 """
22  regex = re.compile(patterns, re.MULTILINE)
23  version_match = regex.search(version_file_data)
24  if version_match:
25  return version_match.groups()
26  raise Exception("Unable to find version string.")
27 
28 
29 def main():
30  import argparse
31  parser = argparse.ArgumentParser(description='Print lz4 version from lib/lz4.h')
32  parser.add_argument('file', help='path to lib/lz4.h')
33  args = parser.parse_args()
34  version_tuple = find_version_tuple(args.file)
35  print('.'.join(version_tuple))
36 
37 
38 if __name__ == '__main__':
39  main()
def find_version_tuple(filepath)