shakemap.utils.dependencies

shakemap.utils.dependencies.sha_sum(fname)[source]

Returns the sha256 checksum of a file.

Parameters:

fname (str) – Path to a file.

Returns:

The sha256 checksum as a hex string.

Return type:

str

class shakemap.utils.dependencies.DepNode(deps, cmd, child=None)[source]

Bases: object

A helper class to create a dependency tree made up of “nodes” with parents, children, and data.

Create a new node. When called without a child node, this will be the root node of a tree. When called with a child, this node will be a parent of the child node.

Parameters:
  • deps (list) – A list of (file, required (bool)) that are the dependencies of cmd.

  • cmd (str) – The name of the ShakeMap coremod command.

  • child (class DepNode) – The child of the created node; if None, the node will be the root node of a tree.

parents()[source]

Returns the parents of the calling node.

Parameters:

none

Returns:

Returns a list of parent nodes of the calling node.

Return type:

list

child()[source]

Returns the child of the calling node.

Parameters:

none

Returns:

Returns the child node of the calling node or None if the calling node is the root.

Return type:

class DepNode or None

deps()[source]

Returns the dependency list of the calling node.

Parameters:

none

Returns:

A list of (file (str), required (bool)) tuples that are the

dependencies of the node’s cmd.

Return type:

list

cmd()[source]

Returns the command stored in the calling node.

Parameters:

none

Returns:

The command stored in the node.

Return type:

str

level()[source]

Returns the tree level of the calling node.

Parameters:

none

Returns:

The tree level of the node.

Return type:

int

getLeaves()[source]

Returns all the leaf nodes (i.e., nodes with no parents) in the tree that starts at the calling node.

Parameters:

none

Returns:

A list of leaf nodes (i.e., nodes with no parents) in the tree that starts at the calling node.

Return type:

list

class shakemap.utils.dependencies.CommandDatabase(classes, eventid, install_path=None, data_path=None)[source]

Bases: object

A class to keep track of dependencies.

Create a new (or open an exsiting) dependency database for checking the status of command dependencies.

Parameters:
  • classes (dict) – A dictionary commands and their associated data as produced by the ‘shake’ program’s _get_command_classes() function.

  • eventid (str) – The event ID of the event being processed.

Returns:

An instance of the CommandDatabase class.

Return type:

class CommandDatabase

close()[source]

Closes the object and associated databases

getDependencyStatus(cmd)[source]

Return the status of the specified command and its ancestors.

Parameters:

cmd (str) – The command name of one of the configured modules for shake (i.e., the “coremods”)

Returns:

A list of tuples of type (command, status) where the status is one of:

missing-depencencies: the command cannot run because of

missing dependencies

out-of-date: the dependencies are newer than the output, so

the command should be run

okay: The output is up to date relative to the dependencies

Return type:

list

updateCommand(cmd)[source]

Update the command and dependency checksums of a command that has just been run.

Parameters:

cmd (str) – The name of the command that has just been run.

Returns:

Nothing.

Return type:

nothing