This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
generate_repo_extra.py
executable file
·141 lines (112 loc) · 4.36 KB
/
generate_repo_extra.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/python3
# Copyright (C) 2017 Marius Gripsgard <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import requests
import os
import sys
import subprocess
DEB_SOURCE_TEMPLATE = "deb %s %s main"
CHECK_TEMPLATE = "%sdists/%s/Release"
MAIN = "http://archive.ubuntu.com/ubuntu/"
PORTS = "http://ports.ubuntu.com/ubuntu-ports/"
BACKPORTS = "deb {} xenial-backports main restricted universe"
deb_sources_list = []
def repo_base(repo):
if repo.startswith("xenial"):
return "http://repo.ubports.com/"
else: # This includes base-less PRs
return "http://repo2.ubports.com/"
def repo_exist(repo, base):
r = requests.get(CHECK_TEMPLATE % (base, repo))
return r.status_code == 200
def add_repo_if_exists(repo):
base = repo_base(repo)
if repo_exist(repo, base):
deb_sources_list.append(DEB_SOURCE_TEMPLATE % (base, repo))
return True
else:
return False
def get_target_apt_repository():
if not os.path.isfile("ubports.target_apt_repository.buildinfo"):
print("ERROR: ubports.target_apt_repository.buildinfo does not exist!")
sys.exit(1)
return
with open("ubports.target_apt_repository.buildinfo") as f:
target_apt_repository = f.read()
return target_apt_repository.strip()
def ubports_depends_exist():
return os.path.isfile("ubports.depends")
def enable_backports():
return os.path.isfile("ubports.backports.buildinfo")
def get_archive():
arch = subprocess.check_output(
["dpkg", "--print-architecture"]).decode("utf8").strip()
return MAIN if arch == "amd64" or arch == "i386" else PORTS
def get_ubports_depends():
if not ubports_depends_exist():
return
with open("ubports.depends") as f:
depend = f.readlines()
# Overflow check
if len(depend) > 20:
print("ERROR: depend overflow size %s" % len(depend))
return
depend = [x.strip() for x in depend]
return depend
def is_extension(target_apt_repository):
return "_-_" in target_apt_repository
def extension_get_repos(target_apt_repository):
if not is_extension(target_apt_repository):
return
split_list = target_apt_repository.split("_-_")
repos = [split_list[0]]
for i in split_list[1:-1]:
repos.append("%s_-_%s" % (repos[-1], i))
return repos
target_apt_repository = get_target_apt_repository()
print(target_apt_repository)
# Working repo
if not add_repo_if_exists(target_apt_repository):
print("WARNING: branch repo '%s' does not exist, please ignore if this is a new branch" % target_apt_repository)
# Extension repo
if is_extension(target_apt_repository):
base_extensions = extension_get_repos(target_apt_repository)
print(base_extensions)
for base_extension in base_extensions:
if not add_repo_if_exists(base_extension):
print("ERROR: Extension repo '%s' do not exist" % base_extension)
sys.exit(1)
# Depends file
if ubports_depends_exist():
depends_file = get_ubports_depends()
if not depends_file:
print("ERROR: get_ubports_depends failed")
sys.exit(1)
for _depend in depends_file:
if is_extension(_depend):
base_extensions = extension_get_repos(_depend)
print(base_extensions)
for base_extension in base_extensions:
if not add_repo_if_exists(base_extension):
print("ERROR: Extension repo '%s' do not exist" % base_extension)
sys.exit(1)
if not add_repo_if_exists(_depend):
print("ERROR: ubports.depends repo '%s' do not exist" % _depend)
sys.exit(1)
if enable_backports():
deb_sources_list.append(BACKPORTS.format(get_archive()))
deb_sources = ",".join(deb_sources_list)
with open("ubports.repos_extra", "w") as f:
f.write(deb_sources)