generated from kamangir/blue-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from kamangir/global-power-plant-database-2024…
…-12-07-58SSQh global-power-plant-database
- Loading branch information
Showing
29 changed files
with
659 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#! /usr/bin/env bash | ||
|
||
function blue_geo_ingest() { | ||
local options=$1 | ||
local do_publish=$(abcli_option_int "$options" publish 0) | ||
local do_upload=$(abcli_option_int "$options" upload 0) | ||
|
||
local object_name=${2:-void} | ||
|
||
local version=$(python3 -m blue_geo.objects get \ | ||
--what version \ | ||
--object_name $object_name) | ||
version=$(abcli_option "$options" version $version) | ||
|
||
local full_object_name=$object_name-$version | ||
|
||
local template_object_name=$(python3 -m blue_geo.objects get \ | ||
--what template_name \ | ||
--object_name $object_name) | ||
[[ ! -z "$template_object_name" ]] && | ||
abcli_clone \ | ||
- \ | ||
$template_object_name \ | ||
$full_object_name | ||
|
||
abcli_log "ingesting $full_object_name ..." | ||
|
||
python3 -m blue_geo.objects ingest \ | ||
--object_name $object_name \ | ||
--version $version \ | ||
"${@:3}" | ||
local status="$?" | ||
|
||
[[ "$do_upload" == 1 ]] && | ||
abcli_upload - $full_object_name | ||
|
||
[[ "$do_publish" == 1 ]] && | ||
abcli_publish \ | ||
~download,tar \ | ||
$full_object_name | ||
|
||
return $status | ||
} |
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,19 @@ | ||
#! /usr/bin/env bash | ||
|
||
function test_blue_geo_ingest() { | ||
local options=$1 | ||
local list_of_objects=$(abcli_option "$options" objects global-power-plant-database) | ||
|
||
local object_name | ||
for object_name in $(echo $list_of_objects | tr + " "); do | ||
|
||
blue_geo_ingest \ | ||
upload,publish,$options \ | ||
$object_name | ||
[[ $? -ne 0 ]] && return 1 | ||
|
||
abcli_hr | ||
done | ||
|
||
return 0 | ||
} |
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,41 @@ | ||
from typing import List | ||
|
||
from blue_options.terminal import show_usage, xtra | ||
|
||
from blue_geo.objects import special_objects | ||
|
||
|
||
def help_ingest( | ||
tokens: List[str], | ||
mono: bool, | ||
) -> str: | ||
options = "".join( | ||
[ | ||
"publish,upload", | ||
xtra(",version=<v1>", mono=mono), | ||
] | ||
) | ||
|
||
args = [ | ||
"[--overwrite 1]", | ||
] | ||
|
||
return show_usage( | ||
[ | ||
"@geo", | ||
"ingest", | ||
f"[{options}]", | ||
"<object-name>", | ||
] | ||
+ args, | ||
"ingest <object-name>.", | ||
{ | ||
"object-name: {}".format( | ||
" | ".join( | ||
"{}[-{}]".format(key, object_module.version) | ||
for key, object_module in special_objects.items() | ||
) | ||
): [], | ||
}, | ||
mono=mono, | ||
) |
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,48 @@ | ||
import os | ||
|
||
from blue_objects import file, README | ||
from blue_objects.env import ABCLI_PUBLIC_PREFIX | ||
|
||
from blue_geo import NAME, VERSION, ICON, REPO_NAME | ||
from blue_geo.objects import special_objects | ||
|
||
|
||
def build() -> bool: | ||
return all( | ||
README.build( | ||
path=os.path.join( | ||
file.path(__file__), | ||
f"md/{suffix}", | ||
), | ||
macros=macros, | ||
ICON=ICON, | ||
NAME=NAME, | ||
VERSION=VERSION, | ||
REPO_NAME=REPO_NAME, | ||
) | ||
for suffix, macros, in [ | ||
( | ||
f"{object_name}.md".replace("-", "_"), | ||
{ | ||
"--object-name--": [ | ||
"💾 [{}-{}]({}/{}-{}.tar.gz)".format( | ||
object_name, | ||
special_objects[object_name].version, | ||
ABCLI_PUBLIC_PREFIX, | ||
object_name, | ||
special_objects[object_name].version, | ||
), | ||
], | ||
"--urls--": sorted( | ||
[ | ||
f" - {title}: {url}" | ||
for title, url in special_objects[object_name].url.items() | ||
] | ||
), | ||
}, | ||
) | ||
for object_name in [ | ||
"global-power-plant-database", | ||
] | ||
] | ||
) |
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,9 @@ | ||
from typing import Dict | ||
from types import ModuleType | ||
|
||
|
||
from blue_geo.objects import global_power_plant_database | ||
|
||
special_objects: Dict[str, ModuleType] = { | ||
"global-power-plant-database": global_power_plant_database, | ||
} |
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,89 @@ | ||
import argparse | ||
from types import ModuleType | ||
|
||
from blueness import module | ||
from blueness.argparse.generic import sys_exit | ||
|
||
from blue_geo import NAME | ||
from blue_geo.objects import special_objects | ||
from blue_geo.logger import logger | ||
|
||
NAME = module.name(__file__, NAME) | ||
|
||
|
||
parser = argparse.ArgumentParser(NAME) | ||
parser.add_argument( | ||
"task", | ||
type=str, | ||
help="get | ingest", | ||
) | ||
parser.add_argument( | ||
"--object_name", | ||
default="", | ||
type=str, | ||
help=", ".join(special_objects.keys()), | ||
) | ||
parser.add_argument( | ||
"--version", | ||
type=str, | ||
default="", | ||
help="defaults to <object_name>.version", | ||
) | ||
parser.add_argument( | ||
"--what", | ||
default="template_name", | ||
type=str, | ||
help="template_name | version", | ||
) | ||
parser.add_argument( | ||
"--default", | ||
default="void", | ||
type=str, | ||
) | ||
parser.add_argument( | ||
"--overwrite", | ||
default=0, | ||
type=int, | ||
help="0|1", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
success = False | ||
if args.task == "get": | ||
success = True | ||
output = args.default | ||
|
||
if args.object_name in special_objects: | ||
object_module: ModuleType = special_objects[args.object_name] | ||
|
||
if args.what == "template_name": | ||
output = object_module.template_name | ||
elif args.what == "version": | ||
output = object_module.version | ||
|
||
print(output) | ||
elif args.task == "ingest": | ||
if args.object_name in special_objects: | ||
object_module: ModuleType = special_objects[args.object_name] | ||
|
||
version = args.version | ||
if not version: | ||
version = object_module.version | ||
|
||
success = object_module.ingest( | ||
object_name=args.object_name, | ||
version=version, | ||
overwrite=args.overwrite == 1, | ||
) | ||
else: | ||
logger.error( | ||
"{}: object not found, expected one of {}.".format( | ||
args.object_name, | ||
", ".join(special_objects.keys()), | ||
) | ||
) | ||
else: | ||
success = None | ||
|
||
sys_exit(logger, NAME, args.task, success) |
Oops, something went wrong.