roomservice: Set timeout when accessing GitHub

* Bypasses the literally infinite timeout for users who have
  limited access to GitHub (before: 2m13.749s, after: 0m14.354s)
* The timeouts should be enough for users who have freedom internet
  access, even ADSL network connection shouldn't take that long...

Test:
1. Execute `source build/envsetup.sh`
2. `breakfast` a existing device
3. Add "0.0.0.1 github.com" and "0.0.0.1 raw.githubusercontent.com"
   to /etc/hosts
4. `breakfast` any device, observe that it should not take up to
   minutes to quit

Change-Id: Ib90e69c75a50e66b47e6245cb6d0521351b5c71b
This commit is contained in:
Yumi Yukimura 2024-06-21 05:41:13 +08:00 committed by Bartłomiej Rudecki
parent b413b4d0e3
commit a8382ce6d6

View file

@ -68,7 +68,7 @@ def add_auth(githubreq):
if not depsonly:
githubreq = urllib.request.Request("https://gitownia.eu/tequilaOS/platform_manifest_mirror/raw/branch/staging/volcan/default.xml")
try:
result = ElementTree.fromstring(urllib.request.urlopen(githubreq).read().decode())
result = ElementTree.fromstring(urllib.request.urlopen(githubreq, timeout=10).read().decode())
except urllib.error.URLError:
print("Failed to fetch data from GitHub")
sys.exit(1)
@ -269,7 +269,7 @@ def get_default_or_fallback_revision(repo_name):
githubreq = urllib.request.Request("https://gitownia.eu/api/v1/repos/tequilaOS/" + repo_name + "/branches")
add_auth(githubreq)
result = json.loads(urllib.request.urlopen(githubreq).read().decode())
result = json.loads(urllib.request.urlopen(githubreq, timeout=5).read().decode())
if has_branch(result, default_revision):
return default_revision