Skip to content

Commit be8cdfb

Browse files
committed
Fix connector_python_pack_deb.py coding style
Change-Id: I6e38202573bd3717354b80274bb47a3d6b60d7ad
1 parent db6d47b commit be8cdfb

File tree

1 file changed

+90
-98
lines changed

1 file changed

+90
-98
lines changed

cpydist/data/deb/connector_python_pack_deb.py

Lines changed: 90 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
#
3939
# pylint: disable=C0103,C0116,W0511,R0912,R0914,R0915
4040

41+
import argparse
4142
import os
42-
import sys
4343
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
4845

46+
from datetime import datetime
47+
from shutil import copyfile, copytree, rmtree
48+
from subprocess import PIPE, STDOUT, Popen
4949

5050
##############################################################################
5151
#
@@ -57,7 +57,9 @@
5757

5858
debian_support_dir = "cpydist/data/deb"
5959

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+
)
6163

6264
script_name = os.path.basename(__file__).replace(".py", "")
6365

@@ -71,63 +73,33 @@
7173

7274
parser = argparse.ArgumentParser(description=__doc__)
7375

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+
)
131103

132104
options = parser.parse_args()
133105

@@ -145,33 +117,40 @@
145117
# A a convention, start debug messages in uppercase. Except debug
146118
# messages, start in lowercase unless a symbol like "OSError"
147119

120+
148121
def print_splash(msg):
149122
print()
150123
print("########")
151124
print("######## WARNING: %s" % (msg))
152125
print("########")
153126

127+
154128
def print_info(msg):
155129
if options.debug:
156130
print("DEBUG[%s]: %s" % (script_name, msg))
157131
else:
158132
print("INFO[%s]: %s" % (script_name, msg))
159133

134+
160135
def print_warning(msg):
161136
print("WARNING[%s]: %s" % (script_name, msg))
162137

138+
163139
def print_error(msg):
164140
print("ERROR[%s]: %s" % (script_name, msg))
165141
sys.exit(1)
166142

167-
def print_debug(msg, level = 1):
143+
144+
def print_debug(msg, level=1):
168145
if options.debug and level <= options.debug:
169146
print("DEBUG[%s]: %s" % (script_name, msg))
170147

148+
171149
# ----------------------------------------------------------------------
172150
# Read the "CHANGES.txt" file for entries
173151
# ----------------------------------------------------------------------
174152

153+
175154
def get_changes():
176155
"""Get changes from CHANGES.txt."""
177156
log_lines = []
@@ -190,6 +169,7 @@ def get_changes():
190169

191170
return log_lines
192171

172+
193173
##############################################################################
194174
#
195175
# Basic verification and adjusting current directory
@@ -217,8 +197,12 @@ def get_changes():
217197

218198
sys.path.insert(0, os.path.join(cwd, "lib"))
219199

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+
)
222206

223207
version_text_short = "{0}.{1}.{2}".format(*VERSION[0:3])
224208

@@ -239,8 +223,7 @@ def get_changes():
239223
sign = False
240224
edition = EDITION
241225
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 ""
244227

245228
# Get if commercial from the directory name
246229
is_commercial = bool("commercial" in os.path.basename(cwd))
@@ -255,14 +238,14 @@ def get_changes():
255238
"name": product_name,
256239
"label": "-%s" % options.label if options.label else "",
257240
"version": version_text_short,
258-
"version_extra": version_extra
241+
"version_extra": version_extra,
259242
}
260243

261244
basename_orig_tar = "%(name)s%(label)s_%(version)s%(version_extra)s.orig" % {
262245
"name": product_name,
263246
"label": "-%s" % options.label if options.label else "",
264247
"version": version_text_short,
265-
"version_extra": version_extra
248+
"version_extra": version_extra,
266249
}
267250

268251
print_info("basename_tar : %s" % (basename_tar))
@@ -285,6 +268,7 @@ def get_changes():
285268
#
286269
##############################################################################
287270

271+
288272
def rename_tar():
289273

290274
# Here "orig" is not "original", but the TAR naming the Deb build needs
@@ -294,12 +278,14 @@ def rename_tar():
294278

295279
copyfile(tarball, orig_tarball)
296280

281+
297282
##############################################################################
298283
#
299284
# Function to pupulate the "debian" directory
300285
#
301286
##############################################################################
302287

288+
303289
def populate_debian():
304290
"""Copy and make files ready in the debian/ folder."""
305291

@@ -325,26 +311,28 @@ def populate_debian():
325311
match = regex.match(line)
326312
if match:
327313
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]))
330315
if first_line:
331316
if options.label:
332317
line = line.replace(
333318
"mysql-connector-python",
334-
"mysql-connector-python-%s" % (options.label))
319+
"mysql-connector-python-%s" % (options.label),
320+
)
335321
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+
)
341330
first_line = False
342331
if "* Changes here." in line:
343332
for change in log_lines:
344333
new_changelog.append(change)
345334
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")
348336
line = re.sub(r"( -- .* <.*@.*> ).*", r"\1" + utcnow, line)
349337
new_changelog.append(line + "\n")
350338
else:
@@ -360,7 +348,10 @@ def populate_debian():
360348
with open(control_file, "r") as fp:
361349
control = fp.readlines()
362350

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+
)
364355

365356
new_control = []
366357
add_label_regex = re.compile(r"^((?:Source|Package): mysql-connector-python)")
@@ -401,12 +392,14 @@ def populate_debian():
401392
with open(control_file, "w") as fp:
402393
fp.write(new_control)
403394

395+
404396
##############################################################################
405397
#
406398
# Function to create the package
407399
#
408400
##############################################################################
409401

402+
410403
def make_dpkg():
411404
"""Create Debian package in the source distribution folder."""
412405

@@ -418,26 +411,24 @@ def make_dpkg():
418411
print_info("creating Debian package using '%s'" % (cmd))
419412

420413
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
424417
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"
434427

435428
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:
441432
stdout, stderr = proc.communicate()
442433
for line in stdout.split("\n"):
443434
if "error:" in line or "E: " in line:
@@ -459,6 +450,7 @@ def make_dpkg():
459450

460451
return success
461452

453+
462454
##############################################################################
463455
#
464456
# Well, now call the functions

0 commit comments

Comments
 (0)