Skip to content

Commit

Permalink
api: allow to prefix packages with a +
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
aparcar committed Apr 16, 2023
1 parent bea4952 commit c09f4fa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions asu/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from rq import Connection, Queue

from .build import build
from .common import get_request_hash
from .common import get_request_hash, remove_prefix

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

Expand Down Expand Up @@ -84,7 +84,7 @@ def validate_packages(req):
else:
tr.add(p)

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

This comment has been minimized.

Copy link
@1715173329

1715173329 Apr 19, 2023

Member

I got this error on 0.7.19:

asu-worker-1  |   File "/home/build/.local/lib/python3.9/site-packages/asu/build.py", line 223, in build
asu-worker-1  |     remove_packages = (default_packages | profile_packages) - req["packages"]
asu-worker-1  | TypeError: unsupported operand type(s) for -: 'set' and 'list'

Is it a typo error? list(map(... -> set(map(...?


# store request packages temporary in Redis and create a diff
temp = str(uuid4())
Expand Down
15 changes: 15 additions & 0 deletions asu/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,18 @@ def verify_usign(sig_file: Path, msg_file: Path, pub_key: str) -> bool:
return True
except nacl.exceptions.CryptoError:
return False


def remove_prefix(text, prefix):
"""Remove prefix from text
TODO: remove once 3.8 is dropped
Args:
text (str): text to remove prefix from
prefix (str): prefix to remove
Returns:
str: text without prefix
"""
return text[text.startswith(prefix) and len(prefix) :]
6 changes: 6 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@ def test_verify_usign():
os.close(sig_fd)
os.unlink(msg_path)
os.unlink(sig_path)


def test_remove_prefix():
assert remove_prefix("test", "test") == ""
assert remove_prefix("+test", "+") == "test"
assert remove_prefix("++test", "+") == "+test"

0 comments on commit c09f4fa

Please sign in to comment.