1+ import datetime
2+ import fnmatch
13import os
24import re
5+ import shutil
36import sys
4- import fnmatch
57import tempfile
6- import shutil
7- import datetime
8-
9- copyright_str = '''
10- /*
11- * Copyright (c) %s Roc Streaming authors
12- *
13- * This Source Code Form is subject to the terms of the Mozilla Public
14- * License, v. 2.0. If a copy of the MPL was not distributed with this
15- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
16- */
17- ''' % datetime .datetime .now ().year
8+ import textwrap
9+
10+ copyright_str = textwrap .dedent ('''
11+ /*
12+ * Copyright (c) {} Roc Streaming authors
13+ *
14+ * This Source Code Form is subject to the terms of the Mozilla Public
15+ * License, v. 2.0. If a copy of the MPL was not distributed with this
16+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
17+ */
18+ ''' ).format (datetime .datetime .now ().year )
1819
1920def is_header (path ):
2021 return re .search ('\.h$' , path )
@@ -51,12 +52,12 @@ def make_guard(path):
5152def make_doxygen_path (path ):
5253 path = '/' .join (path .split (os .sep ))
5354 path = re .sub ('^\.?/' , '' , path )
54- return '@file %s' % path
55+ return '@file ' + path
5556
5657def make_doxygen_brief (text ):
5758 if not text .endswith ('.' ):
5859 text += '.'
59- return '@brief %s' % text
60+ return '@brief ' + text
6061
6162def format_file (output , path ):
6263 def fprint (s ):
@@ -140,7 +141,7 @@ def fprint(s):
140141 continue
141142
142143 if re .match (r'^\s*//!\s*@file' , line ):
143- fprint ('//! %s' % make_doxygen_path (path ))
144+ fprint ('//! {}' . format ( make_doxygen_path (path ) ))
144145 else :
145146 fprint (line )
146147
@@ -152,8 +153,8 @@ def fprint(s):
152153 else :
153154 if not has_doxygen :
154155 if is_header (path ):
155- fprint ('//! %s' % make_doxygen_path (path ))
156- fprint ('//! %s' % make_doxygen_brief (brief ))
156+ fprint ('//! {}' . format ( make_doxygen_path (path ) ))
157+ fprint ('//! {}' . format ( make_doxygen_brief (brief ) ))
157158 section = 'guard'
158159 else :
159160 section = 'body'
@@ -165,12 +166,12 @@ def fprint(s):
165166 m = re .match (r'#\s*(ifndef|define)' , line )
166167 if m :
167168 has_guard = True
168- fprint ('#%s %s' % (m .group (1 ), make_guard (path )))
169+ fprint ('#{} {}' . format (m .group (1 ), make_guard (path )))
169170 continue
170171 else :
171172 if not has_guard :
172- fprint ('#ifndef %s' % make_guard (path ))
173- fprint ('#define %s' % make_guard (path ))
173+ fprint ('#ifndef {}' . format_file ( make_guard (path ) ))
174+ fprint ('#define {}' . format_file ( make_guard (path ) ))
174175 fprint ('' )
175176 section = 'body'
176177
@@ -182,7 +183,7 @@ def fprint(s):
182183
183184 if is_header (path ):
184185 fprint ('' )
185- fprint ('#endif // %s' % make_guard (path ))
186+ fprint ('#endif // {}' . format ( make_guard (path ) ))
186187
187188def walk_dir (directory , patterns ):
188189 for root , dirs , files in os .walk (directory ):
0 commit comments