Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource tool #276

Merged
merged 31 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
333aa4d
Add resource accessor tool
dchassin Jan 15, 2025
1b4da18
Add checks for resources without index or content
dchassin Jan 15, 2025
25c34f5
Add test_resource.glm
dchassin Jan 15, 2025
00cc2d0
Update test_eia_recs.glm
dchassin Jan 15, 2025
16adefb
Update test_template_option.glm
dchassin Jan 15, 2025
33d4959
Update resource.py
dchassin Jan 15, 2025
ef22ce0
Merge branch 'develop' into develop-add-resources
dchassin Jan 17, 2025
964043d
Added support for buildings resources
dchassin Jan 18, 2025
59a3fe0
Merge branch 'develop-add-resources' of https://github.com/dchassin/g…
dchassin Jan 18, 2025
c4d0954
Add elevation resource
dchassin Jan 19, 2025
bf55b48
Update resource.py
dchassin Jan 19, 2025
59d30b4
Update autotests
dchassin Jan 19, 2025
b129e36
Update resource.csv
dchassin Jan 19, 2025
20ee290
Add resource mimetypes
dchassin Jan 19, 2025
76f2976
Update resource.py
dchassin Jan 20, 2025
1e9f20b
Add support for code resource
dchassin Jan 20, 2025
290cf77
Update index
dchassin Jan 20, 2025
2868fe2
Add support for code resources
dchassin Jan 20, 2025
085bfba
Update resource.py
dchassin Jan 20, 2025
4a0e964
Update resource.py
dchassin Jan 20, 2025
f8bb5d8
WIP
dchassin Jan 20, 2025
1177d1c
WIP
dchassin Jan 22, 2025
bc9bdb0
Add geodata resource
dchassin Jan 22, 2025
8ae5ea6
Add icons resource
dchassin Jan 22, 2025
78e3c29
Add library resources
dchassin Jan 22, 2025
02918a5
Add models resource
dchassin Jan 22, 2025
a75a0e5
Add tariff resource
dchassin Jan 22, 2025
5ef1e7b
Add template resource
dchassin Jan 22, 2025
0c40b5a
Add version (index only)
dchassin Jan 22, 2025
a9d548f
Add support for main call in framework
dchassin Jan 22, 2025
ebc023f
Update framework docs
dchassin Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ $(prefix)/src:
@chmod -R 775 $(prefix)/src

index: weather library template
@echo Updating file index...
@git ls-files | grep -v '^\.' | grep -v '/\.' > index

html-local: module-html developer-html troubleshooting-html
@mkdir -p $(prefix)/share/doc/developer
Expand Down
82 changes: 52 additions & 30 deletions docs/Tools/Framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ Example:
~~~
import framework as app

def main(argv):
def main(argv:list[str]) -> int:

# handle no options case -- typically a cry for help
if len(argv) == 1:

print("
".join([x for x in __doc__.split("
") if x.startswith("Syntax: ")]))
return app.E_SYNTAX
app.syntax(__doc__)

# handle stardard app arguments --debug, --warning, --verbose, --quiet, --silent
args = app.read_stdargs(argv)
Expand All @@ -40,45 +37,30 @@ def main(argv):
if key in ["-h","--help","help"]:
print(__doc__,file=sys.stdout)

# TODO: add options here
# add your options here

else:
error(f"'{key}={value}' is invalid")

app.error(f"'{key}={value}' is invalid")
return app.E_INVALID

# TODO: code implementation here, if any
# implement your code here

# normal termination condigion
return app.E_OK

if __name__ == "__main__":

try:

# TODO: development testing -- delete when done writing code
if not sys.argv[0]:
sys.argv = ["selftest","--debug"]

rc = main(sys.argv)
exit(rc)

except KeyboardInterrupt:

exit(app.E_INTERRUPT)

except Exception as exc:
app.run(main)
~~~

if app.DEBUG:
raise exc

if not app.QUIET:
e_type,e_value,e_trace = sys.exc_info()
tb = app.traceback.TracebackException(e_type,e_value,e_trace).stack[1]
print(f"EXCEPTION [{app.EXEFILE}@{tb.lineno}]: ({e_type.__name__}) {e_value}",file=sys.stderr)

exit(app.E_EXCEPTION)
~~~
# Classes

## ApplicationError

Application exception

# Functions

Expand Down Expand Up @@ -148,6 +130,10 @@ Arguments:

Messages are suppressed when the `--quiet` option is used.

If `--debug` is enabled, an exception is raised with a traceback.

If the exit `code` is specified, exit is called with the code.


---

Expand All @@ -159,6 +145,8 @@ Arguments:

* `exc`: exception to raise

If `exc` is a string, an `ApplicationError` exception is raised.


---

Expand All @@ -172,6 +160,8 @@ Arguments:

* `bin`: enable direct call to gridlabd binary (bypasses shell and faster)

* `output_to`: run postprocessor on output to stdout

* `kwargs`: options to pass to `subpocess.run`

Returns:
Expand Down Expand Up @@ -249,6 +239,38 @@ Returns:
* Remaining arguments


---

## `run() -> None`

Run a main function under this app framework

Arguments:

* `main`: the main function to run

* `exit`: the exit function to call (default is `exit`)

* `print`: the print funtion to call on exceptions (default is `print`)

This function does not return. When the app is done it calls exit.


---

## `syntax() -> None`

Print syntax message

Arguments:

* `docs`: the application's __doc__ string

* `print`: the print function to use (default is `print`)

This function does not return. When the function is done it calls exit(E_SYNTAX)


---

## `verbose() -> None`
Expand Down
1 change: 1 addition & 0 deletions docs/Tools/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ DOCS_UTILITIES += docs/Tools/Edit.md
DOCS_UTILITIES += docs/Tools/Location.md
DOCS_UTILITIES += docs/Tools/Mapping.md
DOCS_UTILITIES += docs/Tools/Moutils.md
DOCS_UTILITIES += docs/Tools/Resource.md
DOCS_UTILITIES += docs/Tools/Unitcalc.md
46 changes: 46 additions & 0 deletions docs/Tools/Mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ See also:

# Classes

## ApplicationError

Application exception

---

## Map

Mapping class
Expand Down Expand Up @@ -244,6 +250,10 @@ Arguments:

Messages are suppressed when the `--quiet` option is used.

If `--debug` is enabled, an exception is raised with a traceback.

If the exit `code` is specified, exit is called with the code.


---

Expand All @@ -255,6 +265,8 @@ Arguments:

* `exc`: exception to raise

If `exc` is a string, an `ApplicationError` exception is raised.


---

Expand Down Expand Up @@ -285,6 +297,8 @@ Arguments:

* `bin`: enable direct call to gridlabd binary (bypasses shell and faster)

* `output_to`: run postprocessor on output to stdout

* `kwargs`: options to pass to `subpocess.run`

Returns:
Expand Down Expand Up @@ -377,6 +391,38 @@ Returns:
* Remaining arguments


---

## `run() -> None`

Run a main function under this app framework

Arguments:

* `main`: the main function to run

* `exit`: the exit function to call (default is `exit`)

* `print`: the print funtion to call on exceptions (default is `print`)

This function does not return. When the app is done it calls exit.


---

## `syntax() -> None`

Print syntax message

Arguments:

* `docs`: the application's __doc__ string

* `print`: the print function to use (default is `print`)

This function does not return. When the function is done it calls exit(E_SYNTAX)


---

## `verbose() -> None`
Expand Down
140 changes: 140 additions & 0 deletions docs/Tools/Resource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
[[/Tools/Resource]] -- Online resource accessor

Syntax: `gridlabd resource [OPTIONS ...]`

Options:

* `--content=RESOURCE,INDEX`: download RESOURCE located at INDEX

* `--debug`: enable traceback on exceptions

* `-h|--help|help`: get this help

* `--format=[raw|csv|json]`: output format

* `--index=RESOURCE`: get index for RESOURCE

* `--list[=FORMAT[,OPTIONS[,...]]`: list the available resources

* `--quiet`: suppress error output

* `--properties=RESOURCE`: get a list of resource properties

* `--silent`: suppress all output exception results

* `--test[=PATTERN]`: test resources matching pattern (default is '.*')

* `--verbose`: enable verbose output

* `--warning`: disable warning output

Description:

The online resource accessor delivers online resources to GridLAB-D applications.

Valid formats include `json` and `csv` (the default is 'raw').

Examples:

The following command lists the released versions

gridlabd resource --index=version

The following command lists the properties on the online weather resources

gridlabd resource --properties=weather

The following command retrieves the online weather data for the specified location

gridlabd resource --content=weather,WA-Seattle_Seattletacoma_Intl_A.tmy3



# Classes

## Resource

Resource class

### `Resource()`

Construct resource object

Arguments:

* `file`: resource file (default is $GLD_ETC/resource.csv)


### `Resource.content(kwargs:dict) -> str`

Get resource content

Arguments:

* `**kwargs`: options (see `properties()`)

Returns:

* Resource contents


### `Resource.headers(kwargs:dict) -> Union`

Get resource header



### `Resource.index(kwargs:dict) -> Union`

Get resource index (if any)



### `Resource.list(pattern:str) -> list`

Get a list of available resources

Argument


### `Resource.properties(passthru:str, kwargs:dict) -> dict`

Get resource properties



---

## ResourceError

Resource exception

# Functions

## `main() -> int`

Resource tool main routine

Arguments:

* `argv`: command line arguments

Returns:

* Exit code


---

## `test() -> None`

Run tests on resources that match the specified pattern

Arguments:

* `pattern`: the resource name as a regular expression

Returns:

* Exit code: E_OK on success, E_FAILED on failure

4 changes: 2 additions & 2 deletions docs/makemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
E_SYNTAX = 3
E_EXCEPTION = 9

IGNORE = ['TypeVar']
IGNORE = ['TypeVar','Union']

class MakemdError(Exception):
def __init__(self,msg,exitcode=None):
Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(self,msg,exitcode=None):
# output classes
first = True
for item in [getattr(module,x) for x in dir(module) if inspect.isclass(getattr(module,x))]:
if not item.__doc__ or item.__name__ in IGNORE:
if not item.__doc__ or item.__name__ in IGNORE or isinstance(item,type(os)):
continue
if first:
print("\n# Classes",file=md)
Expand Down
Loading
Loading