pycloudlib.util module

Helpers for shell string and processing.

pycloudlib.util.chmod(path, mode)[source]

Run chmod on a file or directory.

  • path – string of path to run on
  • mode – int of mode to apply

Create tag with current timestamp.

Parameters:tag – string, Base tag to be used
An updated tag with current timestamp

Make sure dir is writable.

Parameters:path – path to determine if writable
Returns:boolean with result

Make a temporary directory.

Parameters:prefix – optional, temproary dir name prefix (default: pycloudlib)
Returns:tempfile object that was created

Delete a file.

Parameters:path – run unlink on specific path

Return a string that can shuffled through ‘sh’ and execute cmd.

In Python subprocess terms:
check_output(cmd) == check_output(shell_pack(cmd), shell=True)
Parameters:cmd – list or string of command to pack up
Returns:base64 encoded string

Quote a shell string.

Parameters:cmd – command to quote
Returns:quoted string

Produce string safe shell string.

Create a string that can be passed to $(set – <string>) to produce the same array that cmd represents.

Internally we utilize ‘getopt’s ability/knowledge on how to quote strings to be safe for shell. This implementation could be changed to be pure python. It is just a matter of correctly escaping or quoting characters like: ‘ ” ^ & $ ; ( ) …

Parameters:cmd – command as a list
Returns:shell safe string
pycloudlib.util.subp(args, data=None, env=None, shell=False, rcs=(0, ), shortcircuit_stdin=True)[source]

Subprocess wrapper.

  • args – command to run
  • data – data to pass
  • env – optional env to use
  • shell – optional shell to use
  • rcs – tuple of successful exit codes, default: (0)
  • shortcircuit_stdin – bind stdin to /dev/null if no data is given

Tuple of out, err, return_code

pycloudlib.util.touch(path, mode=None)[source]

Ensure a directory exists with a specific mode, it not create it.

  • path – path to directory to create
  • mode – optional, mode to set directory to
pycloudlib.util.update_nested(mapping, update)[source]

Update mapping with update value at given update key.


original_dict = {‘a’: {‘b’: {‘c’: ‘d’}}} update = {‘a’: {‘b’: {‘c’: ‘e’}}} update_nested(original_dict, update) original_dict == {‘a’: {‘b’: {‘c’: ‘e’}}}


Ensure tag will work as name for clouds that use it.