enums.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 import re
3 import os
4 import sys
5 import argparse
6 
7 
8 ENUM_H_REGEXP = r'^[ ]*(RS2_\w+)'
9 ENUM_CPP_REGEXP = r'^[ ]*_FORCE_SET_ENUM\((\w+)\)'
10 ENUM_JS_REGEXP = r'RS2\.(RS2_\w+)'
11 
12 
13 def files_gen(path, ends):
14  for root, dirs, files in os.walk(path):
15  for file in files:
16  if file.endswith(ends):
17  yield os.path.join(root, file)
18 
19 
20 def get_first_by_regexp(line, regexp):
21  res = re.findall(regexp, line)
22  if res:
23  return res[0]
24  return ''
25 
26 
27 def get_enums_from_folder(folder_path, ends, regexp):
28  file_paths = files_gen(folder_path, ends)
29  enums = []
30  for file_path in file_paths:
31  enums += get_enums_from_file(file_path, regexp)
32  return enums
33 
34 
35 def get_enums_from_file(file_path, regexp):
36  enums = []
37  with open(file_path) as f:
38  for line in f:
39  enum = get_first_by_regexp(line, regexp)
40  if enum:
41  enums.append(enum)
42 
43  return enums
44 
45 
46 def run(include_folder_path, addon_folder_path):
47 
48  include_enums = get_enums_from_folder(include_folder_path, '.h', ENUM_H_REGEXP)
49  cpp_enums = get_enums_from_folder(addon_folder_path, '.cpp', ENUM_CPP_REGEXP)
50  # js_enums = get_enums_from_file(js_file_path, ENUM_JS_REGEXP)
51 
52  include_enums.sort()
53  cpp_enums.sort()
54  # js_enums.sort()
55 
56  # print(len(include_enums), len(cpp_enums), len(js_enums))
57  return list(set(include_enums) - set(cpp_enums))
58 
59 
60 if __name__ == '__main__':
61  parser = argparse.ArgumentParser(description='Ping script')
62  parser.add_argument('-i', action='store', dest='include_folder_path', required=True)
63  parser.add_argument('-a', action='store', dest='addon_folder_path', required=True)
64  parser.add_argument('-v', '--verbose', action='store_true', help='print not user enums')
65 
66  args = parser.parse_args()
67 
68  missed = run(args.include_folder_path, args.addon_folder_path)
69 
70  if missed:
71  missed.sort()
72  message = "[ERROR] Node.js wrapper has missing enum values: %s" % (', '.join(missed))
73  sys.exit(message if args.verbose else 1)
74 
75  sys.exit()
def get_first_by_regexp(line, regexp)
Definition: enums.py:20
std::string join(const std::string &base, const std::string &path)
Definition: filesystem.h:113
def get_enums_from_folder(folder_path, ends, regexp)
Definition: enums.py:27
def get_enums_from_file(file_path, regexp)
Definition: enums.py:35
def run(include_folder_path, addon_folder_path)
Definition: enums.py:46
def files_gen(path, ends)
Definition: enums.py:13


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:14