Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit 2e2d90e

Browse files
Lint with Pylint
1 parent 22a6a0e commit 2e2d90e

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

ubports-qa

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import argparse
1111
from enum import Enum
1212
import requests
1313

14-
GITHUB_API_PULLREQUEST="https://api.github.com/repos/ubports/{repo}/pulls/{num}"
15-
JENKINS_API_BUILD="https://ci.ubports.com/blue/rest/organizations/jenkins/pipelines/{repo}/branches/{ref}"
14+
GITHUB_API_PULLREQUEST = "https://api.github.com/repos/ubports/{repo}/pulls/{num}"
15+
JENKINS_API_BUILD = "https://ci.ubports.com/blue/rest/organizations/jenkins/pipelines/{repo}/branches/{ref}"
1616

17-
is_root = (os.geteuid() == 0)
17+
IS_ROOT = (os.geteuid() == 0)
1818

1919
class Status(Enum):
2020
SUCCESS = 1
@@ -34,7 +34,7 @@ class WritableRootFS():
3434
def __enter__(self):
3535
self.attempt_writable_mount()
3636

37-
def __exit__(self, type, value, traceback):
37+
def __exit__(self, exc_type, value, traceback):
3838
self.attempt_unmount()
3939

4040
@classmethod
@@ -55,7 +55,7 @@ class WritableRootFS():
5555
print_error("Please consider rebooting your device.")
5656

5757
def ensure_root():
58-
if not is_root:
58+
if not IS_ROOT:
5959
die("Insufficient permissions, please run with sudo.")
6060

6161
def apt_update():
@@ -81,16 +81,16 @@ def list_exists(branch):
8181

8282
def list_lists():
8383
return [f.split("ubports-")[1].split(".list")[0]
84-
for f in os.listdir("/etc/apt/preferences.d")
85-
if os.path.isfile(f) and f.startswith("ubports-")]
84+
for f in os.listdir("/etc/apt/preferences.d")
85+
if os.path.isfile(f) and f.startswith("ubports-")]
8686

8787
def add_list(branch):
8888
if list_exists(branch):
8989
return
9090
if requests.get("http://repo.ubports.com/dists/" + branch).status_code != 200:
9191
die("PPA not found")
92-
with open(get_list_file(branch),"w+") as list:
93-
list.write("deb http://repo.ubports.com/ {} main".format(branch))
92+
with open(get_list_file(branch), "w+") as repo_list:
93+
repo_list.write("deb http://repo.ubports.com/ {} main".format(branch))
9494

9595
def remove_list(branch):
9696
# If it does not exist, just ignore
@@ -117,22 +117,23 @@ def get_issue_status(repo, ref):
117117
return Status.SUCCESS
118118
elif build["result"] == "BULDING":
119119
return Status.BULDING
120-
else:
121-
return Status.FAILED
120+
121+
return Status.FAILED
122122

123123
def get_issue_branch(repo, num):
124124
return get_github_pr(repo, num)["head"]["ref"]
125125

126-
def print_error(error):
127-
"""Prints red text found in error"""
128-
print('\033[91m' + error + '\033[0m')
126+
def print_error(error_message):
127+
"""Prints error_message in red"""
128+
print('\033[91m' + error_message + '\033[0m')
129129

130-
def die(m):
131-
"""Prints red text m and exits with status 3"""
132-
print_error(m)
130+
def die(error_message):
131+
"""Prints error_message in red and exits with status 3"""
132+
print_error(error_message)
133133
exit(3)
134134

135135
def install_command(args):
136+
"""Install a PPA or Pull Request"""
136137
if args.pr != -1:
137138
args.repo.replace("ubports/", "")
138139
ref = get_issue_branch(args.repo, args.pr)
@@ -147,6 +148,7 @@ def install_command(args):
147148
apt_upgrade()
148149

149150
def remove_command(args):
151+
"""Remove and uninstall a PPA"""
150152
if not list_exists(args.repo):
151153
die("Repo {} is not installed".format(args.repo))
152154
with WritableRootFS():
@@ -155,34 +157,36 @@ def remove_command(args):
155157
apt_upgrade()
156158

157159
def list_command(args):
160+
"""List installed PPAs"""
158161
print(" ".join(list_lists()))
159162

160163
def update_command(args):
164+
"""Update all packages using apt"""
161165
with WritableRootFS():
162166
apt_update()
163167
apt_upgrade()
164168

165169
parser = argparse.ArgumentParser(description='The UBports QA scripts allow you to efficiently manage PPAs from repo.ubports.com for testing deb components. See http://docs.ubports.com/en/latest/about/process/ppa.html.')
166170
subparsers = parser.add_subparsers(help='')
167171

168-
parser_install = subparsers.add_parser('install', help='Install a ppa or pull-request', description='Install a ppa or pull-request. See http://docs.ubports.com/en/latest/about/process/ppa.html.')
172+
parser_install = subparsers.add_parser('install', help=install_command.__doc__, description='Install a ppa or pull-request. See http://docs.ubports.com/en/latest/about/process/ppa.html.')
169173
parser_install.add_argument('repo', type=str, help='Name of a PPA on repo.ubports.com. Alternatively, if the \'pr\' argument is provided, the name of a git repository can be specified to automatically add the PPA from a pull-request.')
170174
parser_install.add_argument('pr', type=int, help='Numeric ID of a pull-request on the git repository specified in the \'repo\' argument. If \'repo\' is supposed to be the name of a ppa, the \'pr\' argument should not be specified.', nargs='?', default=-1)
171175
parser_install.set_defaults(func=install_command)
172176

173-
parser_remove = subparsers.add_parser('remove', help='Remove and uninstall a PPA', description='Remove and uninstall a ppa')
177+
parser_remove = subparsers.add_parser('remove', help=remove_command.__doc__, description='Remove and uninstall a ppa')
174178
parser_remove.add_argument('repo', type=str, help='Name of the ppa')
175179
parser_remove.set_defaults(func=remove_command)
176180

177-
parser_list = subparsers.add_parser('list', help='List installed PPAs', description='List installed PPAs')
181+
parser_list = subparsers.add_parser('list', help=list_command.__doc__, description='List installed PPAs')
178182
parser_list.set_defaults(func=list_command)
179183

180-
parser_update = subparsers.add_parser('update', help='Update all packages using apt', description='Update all packages using apt')
184+
parser_update = subparsers.add_parser('update', help=update_command.__doc__, description='Update all packages using apt')
181185
parser_update.set_defaults(func=update_command)
182186

183187
try:
184-
args = parser.parse_args()
185-
args.func(args)
188+
ARGS = parser.parse_args()
189+
ARGS.func(ARGS)
186190
except IOError as e:
187191
# We weren't allowed to do something with a file.
188192
# Either we aren't root or the disk is read-only.

0 commit comments

Comments
 (0)