# watchme.utils package

## Submodules

## watchme.utils.fileio module

Copyright (C) 2019 Vanessa Sochat.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

The watcher is actually a connection to crontab. This is what helps to schedule the watched to check for changes at some frequency, and update the files.

`watchme.utils.fileio.``copyfile`(source, destination, force=True)

  copy a file from a source to its destination.

`watchme.utils.fileio.``generate_temporary_file`(folder=None, prefix='watchme', ext=None)

  write a temporary file, in base directory with a particular extension.

  Parameters

    - folder (the base directory to write in.)

    - prefix (the prefix to use)

    - ext (the extension to use.)

`watchme.utils.fileio.``get_host`()

  return the hostname

`watchme.utils.fileio.``get_tmpdir`(prefix='', create=True)

  get a temporary directory for an operation. If SREGISTRY_TMPDIR is set, return that. Otherwise, return the output of tempfile.mkdtemp

  Parameters

    - prefix (Given a need for a sandbox (or similar), we will need to)

    - create a subfolder *within* the SREGISTRY_TMPDIR.

    - create (boolean to determine if we should create folder (True))

`watchme.utils.fileio.``get_user`()

  return the active user

`watchme.utils.fileio.``get_userhome`()

  get the user home based on the effective uid

`watchme.utils.fileio.``mkdir_p`(path)

  mkdir_p attempts to get the same functionality as mkdir -p

  param path: the path to create.

`watchme.utils.fileio.``print_json`(json_obj)

  just dump the json in a “pretty print” format

`watchme.utils.fileio.``read_file`(filename, mode='r', readlines=True)

  write_file will open a file, “filename” and write content, “content” and properly close the file

`watchme.utils.fileio.``read_json`(filename, mode='r')

  read_json reads in a json file and returns the data structure as dict.

`watchme.utils.fileio.``write_file`(filename, content, mode='w')

  write_file will open a file, “filename” and write content, “content” and properly close the file

`watchme.utils.fileio.``write_json`(json_obj, filename, mode='w', print_pretty=True)

  write_json will (optionally,pretty print) a json object to file

  Parameters

    - json_obj (the dict to print to json)

    - filename (the output file to write to)

    - pretty_print (if True, will use nicer formatting)

## watchme.utils.terminal module

Copyright (C) 2019 Vanessa Sochat.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

`watchme.utils.terminal.``convert2boolean`(arg)

  convert2boolean is used for environmental variables that must be returned as boolean

`watchme.utils.terminal.``get_installdir`()

  get_installdir returns the installation directory of the application

`watchme.utils.terminal.``get_watchme_env`(prefix='WATCHMEENV_')

  get any environment variables that start with WATCMEENV_, return the dictionary to the user.

`watchme.utils.terminal.``run_command`(cmd, sudo=False)

  run_command uses subprocess to send a command to the terminal.

  Parameters

    - cmd (the command to send, should be a list for subprocess)

    - error_message (the error message to give to user if fails,)

    - if none specified, will alert that command failed.

`watchme.utils.terminal.``which`(software, strip_newline=True)

  get_install will return the path to where an executable is installed.

## Module contents