cola.utils – Miscellaneous helpers

This module provides miscellaneous utility functions.

class cola.utils.ProgressIndicator(prefix='', f=<open file '<stdout>', mode 'w' at 0x4039d078>)

Simple progress indicator.

Displayed as a spinning character by default, but can be customized by passing custom messages that overrides the spinning character.

finish(msg='done', noprefix=False)
Finalize progress indication with the given message.
popprefix()
Remove the last prefix from the prefix stack.
pushprefix(prefix)
Append the given prefix onto the prefix stack.
cola.utils.add_parents(path_entry_set)
Iterate over each item in the set and add its parent directories.
cola.utils.basename(path)

An os.path.basename() implementation that always uses ‘/’

Avoid os.path.basename because git’s output always uses ‘/’ regardless of platform.

cola.utils.checksum(path)
Return a cheap md5 hexdigest for a path.
cola.utils.debug(msg, *args)
Print a debug message to stderr when DEBUG is enabled.
cola.utils.die(msg, *args)
Print as error message to stderr and exit the program.
cola.utils.dirname(path)

An os.path.dirname() implementation that always uses ‘/’

Avoid os.path.dirname because git’s output always uses ‘/’ regardless of platform.

cola.utils.error(msg, *args)
Print an error message to stderr.
cola.utils.file_icon(filename)
Returns the full path to an icon file corresponding to filename”s contents.
cola.utils.fork(args)
Launch a command in the background.
cola.utils.grep(pattern, items, squash=True)
Greps a list for items that match a pattern and return a list of matching items. If only one item matches, return just that item.
cola.utils.ident_file_type(filename)
Returns an icon based on the contents of filename.
cola.utils.is_broken()
Is it windows or mac? (e.g. is running git-mergetool non-trivial?)
cola.utils.is_darwin()
Return True on OSX.
cola.utils.is_debian()
Is it debian?
cola.utils.is_linux()
Is this a linux machine?
cola.utils.is_win32()
Return True on win32
cola.utils.notify(msg, *args)
Print a message to stderr.
cola.utils.quote_repopath(repopath)
Quote a path for nt/dos only.
cola.utils.run_cmd(command)

Run arguments as a command and return output.

>>> run_cmd(["echo", "hello", "world"])
'hello world'
cola.utils.run_command(args, cwd=None, shell=False, add_env=None, flag_error=True)

Run the given command to completion, and return its results.

This provides a simpler interface to the subprocess module.

The results are formatted as a 3-tuple: (exit_code, output, errors)

If flag_error is enabled, Error messages will be produced if the subprocess terminated with a non-zero exit code and/or stderr output.

The other arguments are passed on to start_command().

cola.utils.sanitize(s)
Removes shell metacharacters from a string.
cola.utils.slurp(path)
Slurps a filepath into a string.
cola.utils.start_command(args, cwd=None, shell=False, add_env=None, stdin=-1, stdout=-1, stderr=-1)

Start the given command, and return a subprocess object.

This provides a simpler interface to the subprocess module.

cola.utils.strip_prefix(prefix, string)
Return string, without the prefix. Blow up if string doesn’t start with prefix.
cola.utils.sublist(a, b)
Subtracts list b from list a and returns the resulting list.
cola.utils.warn(msg, *args)
Print a warning message to stderr.
cola.utils.win32_abspath(exe)
Return the absolute path to an .exe if it exists
cola.utils.win32_expand_paths(args)
Expand filenames after the double-dash
cola.utils.write(path, contents)
Writes a string to a file.

Previous topic

cola.settings – Settings manager

Next topic

cola.qt – Qt Widget

This Page