utils.get_directory_name: split into two functions

The utils.get_directory_name function was a generally useful function
but worked specifically on Job instances, preventing it from being
used with other types where it would be useful.

Generalized by making it take a string as the first argument, and
added a second argument to specify a default to return if no name is
found. Also added a get_directory_name_from_job() function which acts
like the old get_directory_name: it takes a single job instance
argument, and passes it along to get_directory_name with a default of
the job UUID.
ReplacementDict: add .fromstring static method

This takes care of parsing a string into Python literals, so that
consumers can just pass in a string and don't have to worry about
dealing directly with evaluating Python code.
main.models: add model for UnitVariable