Skip to content

Commit

Permalink
Refactor: Resolve remaining flake8 violations
Browse files Browse the repository at this point in the history
- E304 blank lines found after function decorator
- E402 module level import not at top of file
- E741 ambiguous variable name 'l'
- F522 '...'.format(...) has unused named argument(s): end
- W601 .has_key() is deprecated, use 'in'

Change-Id: I2607e7bb195f6175a7b331e89870fa23e225e31c
Signed-off-by: Thanh Ha <[email protected]>
  • Loading branch information
zxiiro committed Oct 9, 2021
1 parent 8968dfe commit 0480e69
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 120
# E203 and W503 are not python-black compatible
ignore = E203,W503
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
sys.path.insert(0, os.path.abspath(".."))

from docs_conf.conf import * # noqa
from pbr.version import VersionInfo
from pbr.version import VersionInfo # noqa

version = str(VersionInfo("lftools"))
release = str(VersionInfo("lftools"))
Expand Down
1 change: 0 additions & 1 deletion lftools/cli/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def s3(ctx, s3_bucket, s3_path, build_url, workspace, pattern):
@click.argument("nexus-url", envvar="NEXUS_URL")
@click.argument("repo-id", envvar="REPO_ID")
@click.argument("file-name", envvar="FILE_NAME")

# Maven Config
@click.option("-b", "--maven-bin", envvar="MAVEN_BIN", help="Path of maven binary.")
@click.option("-gs", "--global-settings", envvar="GLOBAL_SETTINGS_FILE", help="Global settings file.")
Expand Down
4 changes: 2 additions & 2 deletions lftools/cli/infofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def create_info_file(ctx, gerrit_url, gerrit_project, directory, empty, tsc_appr
name: ''
link: ''
""".format(
tsc_approval, end=""
tsc_approval
)
empty_committer = """ - name: ''
email: ''
Expand All @@ -151,7 +151,7 @@ def create_info_file(ctx, gerrit_url, gerrit_project, directory, empty, tsc_appr
print("repositories:")
print(" - {}".format(gerrit_project))
print("committers:")
print(" - <<: *{1}_{0}_ptl".format(project_underscored, umbrella, end=""))
print(" - <<: *{1}_{0}_ptl".format(project_underscored, umbrella))
if not empty:
this = helper_yaml4info(ldap_group)
print(this, end="")
Expand Down
14 changes: 7 additions & 7 deletions lftools/cli/ldap_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def ldap_connect(ldap_object):
ldap_object.protocol_version = ldap.VERSION3
ldap_object.simple_bind_s()
except ldap.LDAPError as e:
if type(e.message) == dict and e.message.has_key("desc"):
if type(e.message) == dict and "desc" in e.message:
print(e.message["desc"])
else:
print(e)
Expand Down Expand Up @@ -159,24 +159,24 @@ def user_to_csv(user):
)

def main(groups):
"""Preform an LDAP query."""
l = ldap.initialize(ldap_server)
ldap_connect(l)
"""Perform an LDAP query."""
ldap_obj = ldap.initialize(ldap_server)
ldap_connect(ldap_obj)
for arg in groups:
groups = ldap_query(l, ldap_group_base, "cn=%s" % arg, ["member"])
groups = ldap_query(ldap_obj, ldap_group_base, "cn=%s" % arg, ["member"])
group_dict = package_groups(groups)
cut_length = len(ldap_group_base) + 1
for group_bar in group_dict:
group_name = group_bar["name"][3:-cut_length]
for user in group_bar["members"]:
user = user.decode("utf-8")
user_info = ldap_query(l, ldap_user_base, user, ["uid", "cn", "mail"])
user_info = ldap_query(ldap_obj, ldap_user_base, user, ["uid", "cn", "mail"])
try:
print("%s,%s" % (group_name, user_to_csv(user_info)))
except Exception:
eprint("Error parsing user: %s" % user)
continue
ldap_disconnect(l)
ldap_disconnect(ldap_obj)

main(groups)

Expand Down
2 changes: 1 addition & 1 deletion lftools/openstack/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_stack_resources(stack_name):
resources = []

def _is_nested(resource):
link_types = [l["rel"] for l in resource.links]
link_types = [link["rel"] for link in resource.links]
if "nested" in link_types:
return True
return False
Expand Down

0 comments on commit 0480e69

Please sign in to comment.