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

Commit 9e911fe

Browse files
Format code with Black
1 parent 2e2d90e commit 9e911fe

File tree

2 files changed

+67
-15
lines changed

2 files changed

+67
-15
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ optional arguments:
3434
| `sudo ubports-qa remove xenial_-_somebranch` | Remove the `xenial_-_somebranch` ppa and upgrade all packages |
3535
| `ubports-qa list` | List all installed testing-PPAs |
3636
| `sudo ubports-qa update` | Upgrade all packages |
37+
38+
39+
### Contributing
40+
41+
When modifying the ubports-qa script, run [black](https://github.com/ambv/black) before you commit. This helps to reduce the diffs between commits and keeps formatting simple.

ubports-qa

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ import requests
1414
GITHUB_API_PULLREQUEST = "https://api.github.com/repos/ubports/{repo}/pulls/{num}"
1515
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
18+
1819

1920
class Status(Enum):
2021
SUCCESS = 1
2122
BULDING = 2
2223
FAILED = 3
2324

24-
class WritableRootFS():
25+
26+
class WritableRootFS:
2527
"""
2628
A class to be used with the `with` statement to mount `/` read-write, for example::
2729
@@ -31,6 +33,7 @@ class WritableRootFS():
3133
`/` will be remounted read-only on close, unless the file /userdata/.writable_image
3234
exists.
3335
"""
36+
3437
def __enter__(self):
3538
self.attempt_writable_mount()
3639

@@ -54,35 +57,45 @@ class WritableRootFS():
5457
print_error("Failed to remount root filesystem read-only.")
5558
print_error("Please consider rebooting your device.")
5659

60+
5761
def ensure_root():
5862
if not IS_ROOT:
5963
die("Insufficient permissions, please run with sudo.")
6064

65+
6166
def apt_update():
6267
try:
6368
subprocess.run(["apt", "update"], check=True)
6469
except subprocess.CalledProcessError:
6570
print_error("Failed to run 'apt update'. See the output above for details.")
6671

72+
6773
def apt_upgrade():
6874
try:
6975
subprocess.run(["apt", "upgrade"], check=True)
7076
except subprocess.CalledProcessError:
7177
print_error("Failed to run 'apt upgrade'. See the output above for details.")
7278

79+
7380
def get_list_file(branch):
7481
return "/etc/apt/sources.list.d/ubports-{}.list".format(branch)
7582

83+
7684
def get_pref_file(branch):
7785
return "/etc/apt/preferences.d/ubports-{}.pref".format(branch)
7886

87+
7988
def list_exists(branch):
8089
return os.path.isfile(get_list_file(branch))
8190

91+
8292
def list_lists():
83-
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-")]
93+
return [
94+
f.split("ubports-")[1].split(".list")[0]
95+
for f in os.listdir("/etc/apt/preferences.d")
96+
if os.path.isfile(f) and f.startswith("ubports-")
97+
]
98+
8699

87100
def add_list(branch):
88101
if list_exists(branch):
@@ -92,24 +105,28 @@ def add_list(branch):
92105
with open(get_list_file(branch), "w+") as repo_list:
93106
repo_list.write("deb http://repo.ubports.com/ {} main".format(branch))
94107

108+
95109
def remove_list(branch):
96110
# If it does not exist, just ignore
97111
if not list_exists(branch):
98112
return
99113
os.remove(get_list_file(branch))
100114

115+
101116
def get_github_pr(repo, num):
102117
ret = requests.get(GITHUB_API_PULLREQUEST.format(repo=repo, num=num))
103118
if ret.status_code != 200:
104119
die("Pull-Request not found")
105120
return ret.json()
106121

122+
107123
def get_jenkins_build(repo, ref):
108124
ret = requests.get(JENKINS_API_BUILD.format(repo=repo, ref=ref))
109125
if ret.status_code != 200:
110126
die("Jenkins build not found")
111127
return ret.json()
112128

129+
113130
def get_issue_status(repo, ref):
114131
build = get_jenkins_build(repo, ref)["latestRun"]
115132
print(build)
@@ -120,18 +137,22 @@ def get_issue_status(repo, ref):
120137

121138
return Status.FAILED
122139

140+
123141
def get_issue_branch(repo, num):
124142
return get_github_pr(repo, num)["head"]["ref"]
125143

144+
126145
def print_error(error_message):
127146
"""Prints error_message in red"""
128-
print('\033[91m' + error_message + '\033[0m')
147+
print("\033[91m" + error_message + "\033[0m")
148+
129149

130150
def die(error_message):
131151
"""Prints error_message in red and exits with status 3"""
132152
print_error(error_message)
133153
exit(3)
134154

155+
135156
def install_command(args):
136157
"""Install a PPA or Pull Request"""
137158
if args.pr != -1:
@@ -147,6 +168,7 @@ def install_command(args):
147168
apt_update()
148169
apt_upgrade()
149170

171+
150172
def remove_command(args):
151173
"""Remove and uninstall a PPA"""
152174
if not list_exists(args.repo):
@@ -156,32 +178,57 @@ def remove_command(args):
156178
apt_update()
157179
apt_upgrade()
158180

181+
159182
def list_command(args):
160183
"""List installed PPAs"""
161184
print(" ".join(list_lists()))
162185

186+
163187
def update_command(args):
164188
"""Update all packages using apt"""
165189
with WritableRootFS():
166190
apt_update()
167191
apt_upgrade()
168192

169-
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.')
170-
subparsers = parser.add_subparsers(help='')
171193

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.')
173-
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.')
174-
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)
194+
parser = argparse.ArgumentParser(
195+
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."
196+
)
197+
subparsers = parser.add_subparsers(help="")
198+
199+
parser_install = subparsers.add_parser(
200+
"install",
201+
help=install_command.__doc__,
202+
description="Install a ppa or pull-request. See http://docs.ubports.com/en/latest/about/process/ppa.html.",
203+
)
204+
parser_install.add_argument(
205+
"repo",
206+
type=str,
207+
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.",
208+
)
209+
parser_install.add_argument(
210+
"pr",
211+
type=int,
212+
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.",
213+
nargs="?",
214+
default=-1,
215+
)
175216
parser_install.set_defaults(func=install_command)
176217

177-
parser_remove = subparsers.add_parser('remove', help=remove_command.__doc__, description='Remove and uninstall a ppa')
178-
parser_remove.add_argument('repo', type=str, help='Name of the ppa')
218+
parser_remove = subparsers.add_parser(
219+
"remove", help=remove_command.__doc__, description="Remove and uninstall a ppa"
220+
)
221+
parser_remove.add_argument("repo", type=str, help="Name of the ppa")
179222
parser_remove.set_defaults(func=remove_command)
180223

181-
parser_list = subparsers.add_parser('list', help=list_command.__doc__, description='List installed PPAs')
224+
parser_list = subparsers.add_parser(
225+
"list", help=list_command.__doc__, description="List installed PPAs"
226+
)
182227
parser_list.set_defaults(func=list_command)
183228

184-
parser_update = subparsers.add_parser('update', help=update_command.__doc__, description='Update all packages using apt')
229+
parser_update = subparsers.add_parser(
230+
"update", help=update_command.__doc__, description="Update all packages using apt"
231+
)
185232
parser_update.set_defaults(func=update_command)
186233

187234
try:

0 commit comments

Comments
 (0)