Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLorenzo committed Dec 10, 2018
1 parent 03de05e commit 87aa814
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions pushapkscript/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

def extract_android_product_from_scopes(context):
prefixes = _get_scope_prefixes(context)
scopes = _extract_scopes_from_unique_prefix(
scopes=context.task['scopes'],
prefixes=prefixes
)
all_scopes_starting_with_all_prefixes = [
scope
for scope in context.task['scopes']
for prefix in prefixes
if scope.startswith(prefix)
]

scope = get_single_item_from_sequence(
scopes,
condition=lambda _: True, # scopes must just contain 1 single item
all_scopes_starting_with_all_prefixes,
condition=lambda _: True, # it must just contain 1 single item
ErrorClass=TaskVerificationError,
no_item_error_message='No scope starting with any of these prefixes {} found'.format(prefixes),
too_many_item_error_message='More than one scope found',
Expand All @@ -32,25 +35,3 @@ def _get_scope_prefixes(context):
prefix if prefix.endswith(':') else '{}:'.format(prefix)
for prefix in prefixes
]


def _extract_scopes_from_unique_prefix(scopes, prefixes):
scopes = [
scope
for scope in scopes
for prefix in prefixes
if scope.startswith(prefix)
]
_check_scopes_exist_and_all_have_the_same_prefix(scopes, prefixes)
return scopes


def _check_scopes_exist_and_all_have_the_same_prefix(scopes, prefixes):
for prefix in prefixes:
if all(scope.startswith(prefix) for scope in scopes):
break
else:
raise TaskVerificationError(
'Scopes must exist and all have the same prefix. '
'Given scopes: {}. Allowed prefixes: {}'.format(scopes, prefixes)
)

0 comments on commit 87aa814

Please sign in to comment.