Skip to content

Commit c09f4fa

Browse files
committed
api: allow to prefix packages with a +
When adding a + to the beginning of a package name it will modify the order of packages and thereby fix dependency issues of OPKG. This is more of a advanced user feature. Signed-off-by: Paul Spooren <mail@aparcar.org>
1 parent bea4952 commit c09f4fa

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

asu/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from rq import Connection, Queue
55

66
from .build import build
7-
from .common import get_request_hash
7+
from .common import get_request_hash, remove_prefix
88

99
bp = Blueprint("api", __name__, url_prefix="/api")
1010

@@ -84,7 +84,7 @@ def validate_packages(req):
8484
else:
8585
tr.add(p)
8686

87-
req["packages"] = tr
87+
req["packages"] = list(map(lambda x: remove_prefix(x, "+"), sorted(tr)))
8888

8989
# store request packages temporary in Redis and create a diff
9090
temp = str(uuid4())

asu/common.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,18 @@ def verify_usign(sig_file: Path, msg_file: Path, pub_key: str) -> bool:
174174
return True
175175
except nacl.exceptions.CryptoError:
176176
return False
177+
178+
179+
def remove_prefix(text, prefix):
180+
"""Remove prefix from text
181+
182+
TODO: remove once 3.8 is dropped
183+
184+
Args:
185+
text (str): text to remove prefix from
186+
prefix (str): prefix to remove
187+
188+
Returns:
189+
str: text without prefix
190+
"""
191+
return text[text.startswith(prefix) and len(prefix) :]

tests/test_common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,9 @@ def test_verify_usign():
6868
os.close(sig_fd)
6969
os.unlink(msg_path)
7070
os.unlink(sig_path)
71+
72+
73+
def test_remove_prefix():
74+
assert remove_prefix("test", "test") == ""
75+
assert remove_prefix("+test", "+") == "test"
76+
assert remove_prefix("++test", "+") == "+test"

0 commit comments

Comments
 (0)