-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install ev-cli locally and depend on templates files for generation
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
- Loading branch information
1 parent
9e315b5
commit 04559b2
Showing
4 changed files
with
96 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env -S python3 -tt | ||
# -*- coding: utf-8 -*- | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright Pionix GmbH and Contributors to EVerest | ||
# | ||
""" | ||
author: kai-uwe.hermann@pionix.de | ||
""" | ||
|
||
import argparse | ||
from importlib.metadata import Distribution, PackageNotFoundError | ||
import json | ||
|
||
|
||
__version__ = '0.1.0' | ||
|
||
|
||
class EVerestParsingException(SystemExit): | ||
pass | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description='EVerest get package location') | ||
parser.add_argument('--version', action='version', | ||
version=f'%(prog)s {__version__}') | ||
parser.add_argument('--package-name', type=str, | ||
help='Name of the package that the location should be retrieved from', default=None) | ||
args = parser.parse_args() | ||
|
||
if not 'package_name' in args or not args.package_name: | ||
raise EVerestParsingException('Please provide a valid package name') | ||
|
||
direct_url = "" | ||
try: | ||
direct_url = Distribution.from_name( | ||
args.package_name).read_text('direct_url.json') | ||
except PackageNotFoundError as e: | ||
raise EVerestParsingException(e) | ||
url = json.loads(direct_url).get('url', None) | ||
|
||
if url and url.startswith('file://'): | ||
url = url.replace('file://', '') | ||
print(f'{url}') | ||
else: | ||
raise EVerestParsingException() | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
main() | ||
except EVerestParsingException as e: | ||
raise SystemExit(e) |