33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from importlib import metadata
|
|
|
|
|
|
def sanitize_profile(candidate):
|
|
if candidate is not None and candidate.has_subscription():
|
|
candidate.subscription.billing_code = candidate.subscription.get_sanitized_billing_code()
|
|
return candidate
|
|
|
|
|
|
def get_distribution():
|
|
for candidate in metadata.distributions():
|
|
if 'cli' not in candidate.name:
|
|
continue
|
|
candidate_files = candidate.files
|
|
if candidate_files is None:
|
|
continue
|
|
has_source_files = any(f.parts[0] == 'cli' for f in candidate_files)
|
|
is_editable = any('direct_url.json' in str(f) for f in candidate_files)
|
|
if has_source_files or is_editable:
|
|
return candidate
|
|
return None
|
|
|
|
|
|
def parse_composite_argument(argument: str, first_key: str, second_key: str, separator: str = ':'):
|
|
return dict(zip([first_key, second_key], argument.split(separator) + ['']))
|
|
|
|
|
|
def parse_application_argument(application_argument: str):
|
|
return parse_composite_argument(application_argument, 'application_code', 'version_number')
|
|
|
|
|
|
def parse_location_argument(location_argument: str):
|
|
return parse_composite_argument(location_argument, 'country_code', 'code')
|