### Navigation

- index
- modules
- next
- previous
- Home »
- Contents »
- InaSAFE’s API documentation »
- Package::safe »
- Package::safe.common »

# Module: safe.common.utilities

Utilities for InaSAFE

`safe.common.utilities.``temp_dir`(sub_dir='work')

  Obtain the temporary working directory for the operating system.

  An inasafe subdirectory will automatically be created under this and if specified, a user subdirectory under that.

  Note

  You can use this together with unique_filename to create a file in a temporary directory under the inasafe workspace. e.g.

  tmpdir = temp_dir(‘testing’) tmpfile = unique_filename(dir=tmpdir) print tmpfile /tmp/inasafe/23-08-2012/timlinux/testing/tmpMRpF_C

  Args:
    sub_dir str - optional argument which will cause an additional
      subirectory to be created e.g. /tmp/inasafe/foo/
  Returns:
    Path to the output clipped layer (placed in the system temp dir).
  Raises:
    Any errors from the underlying system calls.

`safe.common.utilities.``ugettext`(s)

  Translation support

`safe.common.utilities.``unique_filename`(**kwargs)

  Create new filename guaranteed not to exist previously

  Use mkstemp to create the file, then remove it and return the name

  If dir is specified, the tempfile will be created in the path specified otherwise the file will be created in a directory following this scheme:

  :file:`/tmp/inasafe/<dd-mm-yyyy>/<user>/impacts’

  See http://docs.python.org/library/tempfile.html for details.

  Example usage:

  tempdir = temp_dir(sub_dir=’test’) filename = unique_filename(suffix=’.keywords’, dir=tempdir) print filename /tmp/inasafe/23-08-2012/timlinux/test/tmpyeO5VR.keywords

  Or with no preferred subdir, a default subdir of ‘impacts’ is used:

  filename = unique_filename(suffix=’.shp’) print filename /tmp/inasafe/23-08-2012/timlinux/impacts/tmpoOAmOi.shp

`safe.common.utilities.``verify`(statement, message=None)

  Verification of logical statement similar to assertions Input

  > statement: expression message: error message in case statement evaluates as False

  Output
    None
  Raises
    VerificationError in case statement evaluates to False

This module forms part of the InaSAFE tool.

### Navigation

- index
- modules
- next
- previous
- Home »
- Contents »
- InaSAFE’s API documentation »
- Package::safe »
- Package::safe.common »