5
5
import argparse
6
6
import re
7
7
import os
8
+ import datetime
8
9
9
10
travis_dir = os .path .dirname (os .path .abspath (__file__ ))
10
11
base_dir = os .path .abspath (travis_dir + "/../" )
11
12
13
+ def write_header_file (version ):
14
+ hvs = version .split ('.' )
15
+ intversion = int (hvs [0 ]) * 1000000 + int (hvs [1 ]) * 1000 + int (hvs [2 ])
16
+ now = datetime .datetime .now ()
17
+
18
+ text = f'''/**
19
+ * @file WebSocketsVersion.h
20
+ * @date { now .strftime ("%d.%m.%Y" )}
21
+ * @author Markus Sattler
22
+ *
23
+ * Copyright (c) 2015 Markus Sattler. All rights reserved.
24
+ * This file is part of the WebSockets for Arduino.
25
+ *
26
+ * This library is free software; you can redistribute it and/or
27
+ * modify it under the terms of the GNU Lesser General Public
28
+ * License as published by the Free Software Foundation; either
29
+ * version 2.1 of the License, or (at your option) any later version.
30
+ *
31
+ * This library is distributed in the hope that it will be useful,
32
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
33
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34
+ * Lesser General Public License for more details.
35
+ *
36
+ * You should have received a copy of the GNU Lesser General Public
37
+ * License along with this library; if not, write to the Free Software
38
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
39
+ *
40
+ */
41
+
42
+ #ifndef WEBSOCKETSVERSION_H_
43
+ #define WEBSOCKETSVERSION_H_
44
+
45
+ #define WEBSOCKETS_VERSION "{ version } "
46
+
47
+ #define WEBSOCKETS_VERSION_MAJOR { hvs [0 ]}
48
+ #define WEBSOCKETS_VERSION_MINOR { hvs [1 ]}
49
+ #define WEBSOCKETS_VERSION_PATCH { hvs [2 ]}
50
+
51
+ #define WEBSOCKETS_VERSION_INT { intversion }
52
+
53
+ #endif /* WEBSOCKETSVERSION_H_ */
54
+ '''
55
+ with open (f'{ base_dir } /src/WebSocketsVersion.h' , 'w' ) as f :
56
+ f .write (text )
57
+
58
+
12
59
def get_library_properties_version ():
13
60
library_properties = {}
14
61
with open (f'{ base_dir } /library.properties' , 'r' ) as f :
15
62
library_properties = configparser .ConfigParser ()
16
63
library_properties .read_string ('[root]\n ' + f .read ())
17
64
return library_properties ['root' ]['version' ]
18
65
66
+
19
67
def get_library_json_version ():
20
68
library_json = {}
21
69
with open (f'{ base_dir } /library.json' , 'r' ) as f :
22
70
library_json = json .load (f )
23
71
return library_json ['version' ]
24
72
73
+
25
74
def get_header_versions ():
26
75
data = {}
27
76
define = re .compile ('^#define WEBSOCKETS_VERSION_?(.*) "?([0-9\.]*)"?$' )
@@ -31,8 +80,8 @@ def get_header_versions():
31
80
if m :
32
81
name = m [1 ]
33
82
if name == "" :
34
- name = "VERSION"
35
- data [name ] = m [2 ]
83
+ name = "VERSION"
84
+ data [name ] = m [2 ]
36
85
return data
37
86
38
87
@@ -46,7 +95,7 @@ def get_header_versions():
46
95
47
96
if args .update :
48
97
library_properties_version = get_library_properties_version ()
49
-
98
+
50
99
with open (f'{ base_dir } /library.json' , 'r' ) as f :
51
100
library_json = json .load (f )
52
101
@@ -55,6 +104,8 @@ def get_header_versions():
55
104
with open (f'{ base_dir } /library.json' , 'w' ) as f :
56
105
json .dump (library_json , f , indent = 4 , sort_keys = True )
57
106
107
+ write_header_file (library_properties_version )
108
+
58
109
59
110
library_json_version = get_library_json_version ()
60
111
library_properties_version = get_library_properties_version ()
@@ -76,6 +127,6 @@ def get_header_versions():
76
127
if header_version ['PATCH' ] != hvs [2 ]:
77
128
raise Exception ('header PATCH version wrong!' )
78
129
79
- intversion = int (hvs [0 ]) * 1000000 + int (hvs [1 ]) * 1000 + int (hvs [2 ])
130
+ intversion = int (hvs [0 ]) * 1000000 + int (hvs [1 ]) * 1000 + int (hvs [2 ])
80
131
if int (header_version ['INT' ]) != intversion :
81
- raise Exception ('header INT version wrong!' )
132
+ raise Exception ('header INT version wrong!' )
0 commit comments