1
+ #!/usr/bin/python3
2
+
3
+ import json
4
+ import configparser
5
+ import argparse
6
+ import re
7
+ import os
8
+
9
+ travis_dir = os .path .dirname (os .path .abspath (__file__ ))
10
+ base_dir = os .path .abspath (travis_dir + "/../" )
11
+
12
+ def get_library_properties_version ():
13
+ library_properties = {}
14
+ with open (f'{ base_dir } /library.properties' , 'r' ) as f :
15
+ library_properties = configparser .ConfigParser ()
16
+ library_properties .read_string ('[root]\n ' + f .read ())
17
+ return library_properties ['root' ]['version' ]
18
+
19
+ def get_library_json_version ():
20
+ library_json = {}
21
+ with open (f'{ base_dir } /library.json' , 'r' ) as f :
22
+ library_json = json .load (f )
23
+ return library_json ['version' ]
24
+
25
+ def get_header_versions ():
26
+ data = {}
27
+ define = re .compile ('^#define WEBSOCKETS_VERSION_?(.*) "?([0-9\.]*)"?$' )
28
+ with open (f'{ base_dir } /src/WebSocketsVersion.h' , 'r' ) as f :
29
+ for line in f :
30
+ m = define .match (line )
31
+ if m :
32
+ name = m [1 ]
33
+ if name == "" :
34
+ name = "VERSION"
35
+ data [name ] = m [2 ]
36
+ return data
37
+
38
+
39
+ parser = argparse .ArgumentParser (description = 'Checks and update Version files' )
40
+ parser .add_argument (
41
+ '--update' , action = argparse .BooleanOptionalAction , default = False )
42
+ parser .add_argument (
43
+ '--check' , action = argparse .BooleanOptionalAction , default = True )
44
+
45
+ args = parser .parse_args ()
46
+
47
+ if args .update :
48
+ library_properties_version = get_library_properties_version ()
49
+
50
+ with open (f'{ base_dir } /library.json' , 'r' ) as f :
51
+ library_json = json .load (f )
52
+
53
+ library_json ['version' ] = library_properties_version
54
+
55
+ with open (f'{ base_dir } /library.json' , 'w' ) as f :
56
+ json .dump (library_json , f , indent = 4 , sort_keys = True )
57
+
58
+
59
+ library_json_version = get_library_json_version ()
60
+ library_properties_version = get_library_properties_version ()
61
+ header_version = get_header_versions ()
62
+
63
+ print ("WebSocketsVersion.h" , header_version )
64
+ print (f"library.json: { library_json_version } " )
65
+ print (f"library.properties: { library_properties_version } " )
66
+
67
+ if args .check :
68
+ if library_json_version != library_properties_version or header_version ['VERSION' ] != library_properties_version :
69
+ raise Exception ('versions did not match!' )
70
+
71
+ hvs = header_version ['VERSION' ].split ('.' )
72
+ if header_version ['MAJOR' ] != hvs [0 ]:
73
+ raise Exception ('header MAJOR version wrong!' )
74
+ if header_version ['MINOR' ] != hvs [1 ]:
75
+ raise Exception ('header MINOR version wrong!' )
76
+ if header_version ['PATCH' ] != hvs [2 ]:
77
+ raise Exception ('header PATCH version wrong!' )
78
+
79
+ intversion = int (hvs [0 ]) * 1000000 + int (hvs [1 ]) * 1000 + int (hvs [2 ])
80
+ if int (header_version ['INT' ]) != intversion :
81
+ raise Exception ('header INT version wrong!' )
0 commit comments