55import argparse
66import re
77import os
8+ import datetime
89
910travis_dir = os .path .dirname (os .path .abspath (__file__ ))
1011base_dir = os .path .abspath (travis_dir + "/../" )
1112
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+
1259def get_library_properties_version ():
1360 library_properties = {}
1461 with open (f'{ base_dir } /library.properties' , 'r' ) as f :
1562 library_properties = configparser .ConfigParser ()
1663 library_properties .read_string ('[root]\n ' + f .read ())
1764 return library_properties ['root' ]['version' ]
1865
66+
1967def get_library_json_version ():
2068 library_json = {}
2169 with open (f'{ base_dir } /library.json' , 'r' ) as f :
2270 library_json = json .load (f )
2371 return library_json ['version' ]
2472
73+
2574def get_header_versions ():
2675 data = {}
2776 define = re .compile ('^#define WEBSOCKETS_VERSION_?(.*) "?([0-9\.]*)"?$' )
@@ -31,8 +80,8 @@ def get_header_versions():
3180 if m :
3281 name = m [1 ]
3382 if name == "" :
34- name = "VERSION"
35- data [name ] = m [2 ]
83+ name = "VERSION"
84+ data [name ] = m [2 ]
3685 return data
3786
3887
@@ -46,7 +95,7 @@ def get_header_versions():
4695
4796if args .update :
4897 library_properties_version = get_library_properties_version ()
49-
98+
5099 with open (f'{ base_dir } /library.json' , 'r' ) as f :
51100 library_json = json .load (f )
52101
@@ -55,6 +104,8 @@ def get_header_versions():
55104 with open (f'{ base_dir } /library.json' , 'w' ) as f :
56105 json .dump (library_json , f , indent = 4 , sort_keys = True )
57106
107+ write_header_file (library_properties_version )
108+
58109
59110library_json_version = get_library_json_version ()
60111library_properties_version = get_library_properties_version ()
@@ -76,6 +127,6 @@ def get_header_versions():
76127 if header_version ['PATCH' ] != hvs [2 ]:
77128 raise Exception ('header PATCH version wrong!' )
78129
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 ])
80131 if int (header_version ['INT' ]) != intversion :
81- raise Exception ('header INT version wrong!' )
132+ raise Exception ('header INT version wrong!' )
0 commit comments