pymake.utils.usgsprograms module#

Utility functions to extract target information from the USGS database.

Information for a target is extracted from the USGS application database. Available functionality includes:

  1. Get a list of available targets

  2. Get data for a specific target

  3. Get a dictionary with the data for all targets

  4. Get the current version of a target

  5. Get a list indicating if single and double precision versions of the target application should be built

  6. Functions to load, update, and export a USGS-style “code.json” json file containing information in the USGS application database

The available pymake targets are defined in usgsprograms.toml, which is in this directory, and are listed by usgs_program_data.list_targets().

class dotdict[source]#

Bases: dict

dot.notation access to dictionary attributes.

class usgs_program_data[source]#

Bases: object

USGS program database class.

static export_json(fpth='code.json', appdir=None, prog_data=None, current=False, update=True, write_markdown=False, partial_json=False, zip_path=None, verbose=False)[source]#

Export USGS program data as a json file.

Parameters:
  • fpth (str) – Path for the json file to be created. Default is “code.json”

  • appdir (str) – path for code.json. Overrides code.json path defined in fpth. Default is None.

  • prog_data (dict) – User-specified program database. If prog_data is None, it will be created from the USGS program database

  • current (bool) – If False, all USGS program targets are listed. If True, only USGS program targets that are defined as current are listed. Default is False.

  • update (bool) – If True, existing targets in the user-specified program database with values in the USGS program database. If False, existing targets in the user-specified program database will not be updated. Default is True.

  • write_markdown (bool) – If True, write markdown file that includes the target name, version, and the last-modified date of the download asset (url). Default is False.

  • partial_json (bool) – Create a partial code.json based on targets in the parent path for the code.json file. Default is False.

  • zip_path (str) – Zip code.json into zip_path. (default is None)

  • verbose (bool) – boolean for verbose output to terminal

static get_keys(current=False)[source]#

Get target keys from the USGS program database.

Parameters:

current (bool) – If False, all USGS program targets are listed. If True, only USGS program targets that are defined as current are listed. Default is False.

Returns:

keys – list of USGS program targets

Return type:

list

static get_precision(key)[source]#

Get the dictionary for a specified target.

Parameters:

key (str) – Target USGS program

Returns:

precision – List

Return type:

list

static get_program_dict()[source]#

Get the complete USGS program database.

Returns:

program_dict – Dictionary with USGS program attributes for all targets

Return type:

dict

static get_target(key)[source]#

Get the dictionary for a specified target.

Parameters:

key (str) – Target USGS program that may have a path and an extension

Returns:

program_dict – Dictionary with USGS program attributes for the specified key

Return type:

dict

static get_version(key)[source]#

Get the current version of the specified target.

Parameters:

key (str) – Target USGS program

Returns:

version – current version of the specified target

Return type:

str

static list_json(fpth='code.json')[source]#

List an existing code json file.

Parameters:

fpth (str) – Path for the json file to be listed. Default is “code.json”

static list_targets(current=False)[source]#

Print a list of the available USGS program targets.

Parameters:

current (bool) – If False, all USGS program targets are listed. If True, only USGS program targets that are defined as current are listed. Default is False.

static load_json(fpth='code.json')[source]#

Load an existing code json file. Basic error checking is done to make sure the file contains the correct keys.

Parameters:

fpth (str) – Path for the json file to be created. Default is “code.json”

Returns:

json_dict – Valid USGS program database

Return type:

dict

static update_json(fpth='code.json', temp_dict=None)[source]#

UPDATE an existing code json file.

Parameters:
  • fpth (str) – Path for the json file to be listed. Default is “code.json”

  • temp_dict (dict) – Dictionary with USGS program data for a target