utils Package

utils Package

Utilities that could be packaged in separate project.

class diecutter.utils.chdir(new_dir)

Bases: object

Context manager that change current working directory.

class diecutter.utils.temporary_directory

Bases: object

Create, yield, and finally delete a temporary directory.

>>> with temporary_directory() as directory:
...     os.path.isdir(directory)
True
>>> os.path.exists(directory)
False

Deletion of temporary directory is recursive.

>>> with temporary_directory() as directory:
...     filename = os.path.join(directory, 'sample.txt')
...     __ = open(filename, 'w').close()
...     os.path.isfile(filename)
True
>>> os.path.isfile(filename)
False
diecutter.utils.to_boolean(value)

Convert value string to boolean.

>>> from diecutter.utils.forms import to_boolean
>>> to_boolean('1')
True
>>> to_boolean('0')
False
>>> to_boolean('yes')
True
>>> to_boolean('no')
False
diecutter.utils.accepted_types(request)

Return list of accepted content types from request’s ‘accept’ header.

diecutter.utils.execute(command)

Run command (a list of arguments) and return (code, stdout, stderr).

>>> from diecutter.utils.sh import execute
>>> code, stdout, stderr = execute(['echo', '-n', 'Hello world!'])
>>> code
0
>>> stdout
'Hello world!'
>>> stderr
''

dispatchers Module

Execution control.

class diecutter.utils.dispatchers.FirstResultDispatcher(runners=[])

Bases: object

A dispatcher that return the first result got from callables.

files Module

Manage temporary directories.

class diecutter.utils.files.chdir(new_dir)

Bases: object

Context manager that change current working directory.

new_dir = None

New directory.

previous_dir = None

Remember previous value of os.getcwd().

class diecutter.utils.files.temporary_directory

Bases: object

Create, yield, and finally delete a temporary directory.

>>> with temporary_directory() as directory:
...     os.path.isdir(directory)
True
>>> os.path.exists(directory)
False

Deletion of temporary directory is recursive.

>>> with temporary_directory() as directory:
...     filename = os.path.join(directory, 'sample.txt')
...     __ = open(filename, 'w').close()
...     os.path.isfile(filename)
True
>>> os.path.isfile(filename)
False

forms Module

Forms and data validation.

diecutter.utils.forms.to_boolean(value)

Convert value string to boolean.

>>> from diecutter.utils.forms import to_boolean
>>> to_boolean('1')
True
>>> to_boolean('0')
False
>>> to_boolean('yes')
True
>>> to_boolean('no')
False

http Module

Tools around webob requests.

diecutter.utils.http.accepted_types(request)

Return list of accepted content types from request’s ‘accept’ header.

lazyapi Module

sh Module

Manage shell commands.

diecutter.utils.sh.execute(command)

Run command (a list of arguments) and return (code, stdout, stderr).

>>> from diecutter.utils.sh import execute
>>> code, stdout, stderr = execute(['echo', '-n', 'Hello world!'])
>>> code
0
>>> stdout
'Hello world!'
>>> stderr
''