38
38
#
39
39
# pylint: disable=C0103,C0116,W0511,R0912,R0914,R0915
40
40
41
+ import argparse
41
42
import os
42
- import sys
43
43
import re
44
- import argparse
45
- from subprocess import Popen , PIPE , STDOUT
46
- from datetime import datetime
47
- from shutil import copytree , rmtree , copyfile
44
+ import sys
48
45
46
+ from datetime import datetime
47
+ from shutil import copyfile , copytree , rmtree
48
+ from subprocess import PIPE , STDOUT , Popen
49
49
50
50
##############################################################################
51
51
#
57
57
58
58
debian_support_dir = "cpydist/data/deb"
59
59
60
- no_debug_filter = r'^(byte-compiling|copying|creating /|dpkg-source: warning: ignoring deletion)'
60
+ no_debug_filter = (
61
+ r"^(byte-compiling|copying|creating /|dpkg-source: warning: ignoring deletion)"
62
+ )
61
63
62
64
script_name = os .path .basename (__file__ ).replace (".py" , "" )
63
65
71
73
72
74
parser = argparse .ArgumentParser (description = __doc__ )
73
75
74
- parser .add_argument ("source_directory" ,
75
- nargs = 1 ,
76
- help = "Source directory" )
77
- parser .add_argument ("--with-mysql-capi" ,
78
- action = "store" ,
79
- default = "" ,
80
- help = "" )
81
- parser .add_argument ("--with-openssl-include-dir" ,
82
- action = "store" ,
83
- default = "" ,
84
- help = "" )
85
- parser .add_argument ("--with-openssl-lib-dir" ,
86
- action = "store" ,
87
- default = "" ,
88
- help = "" )
89
- parser .add_argument ("--with-protobuf-include-dir" ,
90
- action = "store" ,
91
- default = "" ,
92
- help = "" )
93
- parser .add_argument ("--with-protobuf-lib-dir" ,
94
- action = "store" ,
95
- default = "" ,
96
- help = "" )
97
- parser .add_argument ("--with-protoc" ,
98
- action = "store" ,
99
- default = "" ,
100
- help = "" )
101
- parser .add_argument ("--extra-compile-args" ,
102
- action = "store" ,
103
- default = "" ,
104
- help = "" )
105
- parser .add_argument ("--extra-link-args" ,
106
- action = "store" ,
107
- default = "" ,
108
- help = "" )
109
- parser .add_argument ("--label" ,
110
- action = "store" ,
111
- default = "" ,
112
- help = "" )
113
- parser .add_argument ("--byte-code-only" ,
114
- action = "store_const" ,
115
- const = "1" ,
116
- default = "" ,
117
- help = "" )
118
- parser .add_argument ("--skip-vendor" ,
119
- action = "store_const" ,
120
- const = "1" ,
121
- default = "" ,
122
- help = "" )
123
- parser .add_argument ("--dry-run" ,
124
- action = "store_true" ,
125
- help = "Run without modifying anything" )
126
- parser .add_argument ("--debug" , "-d" ,
127
- action = "count" ,
128
- default = 0 ,
129
- dest = "debug" ,
130
- help = "Enable debug trace output" )
76
+ parser .add_argument ("source_directory" , nargs = 1 , help = "Source directory" )
77
+ parser .add_argument ("--with-mysql-capi" , action = "store" , default = "" , help = "" )
78
+ parser .add_argument ("--with-openssl-include-dir" , action = "store" , default = "" , help = "" )
79
+ parser .add_argument ("--with-openssl-lib-dir" , action = "store" , default = "" , help = "" )
80
+ parser .add_argument ("--with-protobuf-include-dir" , action = "store" , default = "" , help = "" )
81
+ parser .add_argument ("--with-protobuf-lib-dir" , action = "store" , default = "" , help = "" )
82
+ parser .add_argument ("--with-protoc" , action = "store" , default = "" , help = "" )
83
+ parser .add_argument ("--extra-compile-args" , action = "store" , default = "" , help = "" )
84
+ parser .add_argument ("--extra-link-args" , action = "store" , default = "" , help = "" )
85
+ parser .add_argument ("--label" , action = "store" , default = "" , help = "" )
86
+ parser .add_argument (
87
+ "--byte-code-only" , action = "store_const" , const = "1" , default = "" , help = ""
88
+ )
89
+ parser .add_argument (
90
+ "--skip-vendor" , action = "store_const" , const = "1" , default = "" , help = ""
91
+ )
92
+ parser .add_argument (
93
+ "--dry-run" , action = "store_true" , help = "Run without modifying anything"
94
+ )
95
+ parser .add_argument (
96
+ "--debug" ,
97
+ "-d" ,
98
+ action = "count" ,
99
+ default = 0 ,
100
+ dest = "debug" ,
101
+ help = "Enable debug trace output" ,
102
+ )
131
103
132
104
options = parser .parse_args ()
133
105
145
117
# A a convention, start debug messages in uppercase. Except debug
146
118
# messages, start in lowercase unless a symbol like "OSError"
147
119
120
+
148
121
def print_splash (msg ):
149
122
print ()
150
123
print ("########" )
151
124
print ("######## WARNING: %s" % (msg ))
152
125
print ("########" )
153
126
127
+
154
128
def print_info (msg ):
155
129
if options .debug :
156
130
print ("DEBUG[%s]: %s" % (script_name , msg ))
157
131
else :
158
132
print ("INFO[%s]: %s" % (script_name , msg ))
159
133
134
+
160
135
def print_warning (msg ):
161
136
print ("WARNING[%s]: %s" % (script_name , msg ))
162
137
138
+
163
139
def print_error (msg ):
164
140
print ("ERROR[%s]: %s" % (script_name , msg ))
165
141
sys .exit (1 )
166
142
167
- def print_debug (msg , level = 1 ):
143
+
144
+ def print_debug (msg , level = 1 ):
168
145
if options .debug and level <= options .debug :
169
146
print ("DEBUG[%s]: %s" % (script_name , msg ))
170
147
148
+
171
149
# ----------------------------------------------------------------------
172
150
# Read the "CHANGES.txt" file for entries
173
151
# ----------------------------------------------------------------------
174
152
153
+
175
154
def get_changes ():
176
155
"""Get changes from CHANGES.txt."""
177
156
log_lines = []
@@ -190,6 +169,7 @@ def get_changes():
190
169
191
170
return log_lines
192
171
172
+
193
173
##############################################################################
194
174
#
195
175
# Basic verification and adjusting current directory
@@ -217,8 +197,12 @@ def get_changes():
217
197
218
198
sys .path .insert (0 , os .path .join (cwd , "lib" ))
219
199
220
- from mysql .connector .version import EDITION , VERSION , VERSION_EXTRA # pylint: disable=C0413
221
- from mysql .connector .utils import linux_distribution # pylint: disable=C0413
200
+ from mysql .connector .utils import linux_distribution # pylint: disable=C0413
201
+ from mysql .connector .version import ( # pylint: disable=C0413
202
+ EDITION ,
203
+ VERSION ,
204
+ VERSION_EXTRA ,
205
+ )
222
206
223
207
version_text_short = "{0}.{1}.{2}" .format (* VERSION [0 :3 ])
224
208
@@ -239,8 +223,7 @@ def get_changes():
239
223
sign = False
240
224
edition = EDITION
241
225
codename = linux_dist [2 ].lower ()
242
- version_extra = "-{0}" .format (VERSION_EXTRA ) \
243
- if VERSION_EXTRA else ""
226
+ version_extra = "-{0}" .format (VERSION_EXTRA ) if VERSION_EXTRA else ""
244
227
245
228
# Get if commercial from the directory name
246
229
is_commercial = bool ("commercial" in os .path .basename (cwd ))
@@ -255,14 +238,14 @@ def get_changes():
255
238
"name" : product_name ,
256
239
"label" : "-%s" % options .label if options .label else "" ,
257
240
"version" : version_text_short ,
258
- "version_extra" : version_extra
241
+ "version_extra" : version_extra ,
259
242
}
260
243
261
244
basename_orig_tar = "%(name)s%(label)s_%(version)s%(version_extra)s.orig" % {
262
245
"name" : product_name ,
263
246
"label" : "-%s" % options .label if options .label else "" ,
264
247
"version" : version_text_short ,
265
- "version_extra" : version_extra
248
+ "version_extra" : version_extra ,
266
249
}
267
250
268
251
print_info ("basename_tar : %s" % (basename_tar ))
@@ -285,6 +268,7 @@ def get_changes():
285
268
#
286
269
##############################################################################
287
270
271
+
288
272
def rename_tar ():
289
273
290
274
# Here "orig" is not "original", but the TAR naming the Deb build needs
@@ -294,12 +278,14 @@ def rename_tar():
294
278
295
279
copyfile (tarball , orig_tarball )
296
280
281
+
297
282
##############################################################################
298
283
#
299
284
# Function to pupulate the "debian" directory
300
285
#
301
286
##############################################################################
302
287
288
+
303
289
def populate_debian ():
304
290
"""Copy and make files ready in the debian/ folder."""
305
291
@@ -325,26 +311,28 @@ def populate_debian():
325
311
match = regex .match (line )
326
312
if match :
327
313
version = match .groups ()[0 ]
328
- line = line .replace (version ,
329
- "{0}.{1}.{2}-1" .format (* VERSION [0 :3 ]))
314
+ line = line .replace (version , "{0}.{1}.{2}-1" .format (* VERSION [0 :3 ]))
330
315
if first_line :
331
316
if options .label :
332
317
line = line .replace (
333
318
"mysql-connector-python" ,
334
- "mysql-connector-python-%s" % (options .label ))
319
+ "mysql-connector-python-%s" % (options .label ),
320
+ )
335
321
line = line .replace ("UNRELEASED" , codename )
336
- line = line .replace ("-1" ,
337
- "{version_extra}-1{platform}{version}"
338
- .format (platform = platform ,
339
- version = platform_version ,
340
- version_extra = version_extra ))
322
+ line = line .replace (
323
+ "-1" ,
324
+ "{version_extra}-1{platform}{version}" .format (
325
+ platform = platform ,
326
+ version = platform_version ,
327
+ version_extra = version_extra ,
328
+ ),
329
+ )
341
330
first_line = False
342
331
if "* Changes here." in line :
343
332
for change in log_lines :
344
333
new_changelog .append (change )
345
334
elif line .startswith (" --" ) and "@" in line :
346
- utcnow = datetime .utcnow ().strftime (
347
- "%a, %d %b %Y %H:%M:%S +0000" )
335
+ utcnow = datetime .utcnow ().strftime ("%a, %d %b %Y %H:%M:%S +0000" )
348
336
line = re .sub (r"( -- .* <.*@.*> ).*" , r"\1" + utcnow , line )
349
337
new_changelog .append (line + "\n " )
350
338
else :
@@ -360,7 +348,10 @@ def populate_debian():
360
348
with open (control_file , "r" ) as fp :
361
349
control = fp .readlines ()
362
350
363
- print_info ("changing control '%s' Source, Package and Conflicts fields" % (control_file ))
351
+ print_info (
352
+ "changing control '%s' Source, Package and Conflicts fields"
353
+ % (control_file )
354
+ )
364
355
365
356
new_control = []
366
357
add_label_regex = re .compile (r"^((?:Source|Package): mysql-connector-python)" )
@@ -401,12 +392,14 @@ def populate_debian():
401
392
with open (control_file , "w" ) as fp :
402
393
fp .write (new_control )
403
394
395
+
404
396
##############################################################################
405
397
#
406
398
# Function to create the package
407
399
#
408
400
##############################################################################
409
401
402
+
410
403
def make_dpkg ():
411
404
"""Create Debian package in the source distribution folder."""
412
405
@@ -418,26 +411,24 @@ def make_dpkg():
418
411
print_info ("creating Debian package using '%s'" % (cmd ))
419
412
420
413
env = os .environ .copy ()
421
- env ["MYSQL_CAPI" ] = options .with_mysql_capi
422
- env ["OPENSSL_INCLUDE_DIR" ] = options .with_openssl_include_dir
423
- env ["OPENSSL_LIB_DIR" ] = options .with_openssl_lib_dir
414
+ env ["MYSQL_CAPI" ] = options .with_mysql_capi
415
+ env ["OPENSSL_INCLUDE_DIR" ] = options .with_openssl_include_dir
416
+ env ["OPENSSL_LIB_DIR" ] = options .with_openssl_lib_dir
424
417
env ["MYSQLXPB_PROTOBUF_INCLUDE_DIR" ] = options .with_protobuf_include_dir
425
- env ["MYSQLXPB_PROTOBUF_LIB_DIR" ] = options .with_protobuf_lib_dir
426
- env ["MYSQLXPB_PROTOC" ] = options .with_protoc
427
- env ["WITH_CEXT" ] = "1"
428
- env ["EXTRA_COMPILE_ARGS" ] = options .extra_compile_args
429
- env ["EXTRA_LINK_ARGS" ] = options .extra_link_args
430
- env ["SKIP_VENDOR" ] = options .skip_vendor
431
- env ["LABEL" ] = options .label or "0"
432
- env ["BYTE_CODE_ONLY" ] = options .byte_code_only
433
- env ["DH_VERBOSE" ] = "1"
418
+ env ["MYSQLXPB_PROTOBUF_LIB_DIR" ] = options .with_protobuf_lib_dir
419
+ env ["MYSQLXPB_PROTOC" ] = options .with_protoc
420
+ env ["WITH_CEXT" ] = "1"
421
+ env ["EXTRA_COMPILE_ARGS" ] = options .extra_compile_args
422
+ env ["EXTRA_LINK_ARGS" ] = options .extra_link_args
423
+ env ["SKIP_VENDOR" ] = options .skip_vendor
424
+ env ["LABEL" ] = options .label or "0"
425
+ env ["BYTE_CODE_ONLY" ] = options .byte_code_only
426
+ env ["DH_VERBOSE" ] = "1"
434
427
435
428
success = True
436
- with Popen (cmd ,
437
- stdout = PIPE ,
438
- stderr = STDOUT ,
439
- universal_newlines = True ,
440
- env = env ) as proc :
429
+ with Popen (
430
+ cmd , stdout = PIPE , stderr = STDOUT , universal_newlines = True , env = env
431
+ ) as proc :
441
432
stdout , stderr = proc .communicate ()
442
433
for line in stdout .split ("\n " ):
443
434
if "error:" in line or "E: " in line :
@@ -459,6 +450,7 @@ def make_dpkg():
459
450
460
451
return success
461
452
453
+
462
454
##############################################################################
463
455
#
464
456
# Well, now call the functions
0 commit comments