cola.utils – Miscellaneous helpers

This module provides miscellaneous utility functions.

class cola.utils.DiffParser(model, filename='', cached=True, branch=None, reverse=False)

Handles parsing diff for use by the interactive index editor.

get_diff_for_offset(offset)
Returns the hunks for a particular offset.
get_diff_subset(diff, start, end)
Processes the diffs and returns a selected subset from that diff.
get_diffs()
Returns the list of diffs.
get_diffs_for_range(start, end)
Returns the hunks for a selected range.
get_offsets()
Returns the offsets.
get_spans()
Returns the line spans of each hunk.
parse_diff(diff)
Parses a diff and extracts headers, offsets, hunks, etc.
process_diff_selection(selected, offset, selection, apply_to_worktree=False)
Processes a diff selection and applies changes to the work tree or index.
set_diff_to_offset(offset)
Sets the diff selection to be the hunk at a particular offset.
set_diffs_to_range(start, end)
Sets the diff selection to be a range of hunks.
write_diff(filename, which, selected=False, noop=False)
Writes a new diff corresponding to the user’s selection.
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.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.fork(args)
Launches a command in the background.
cola.utils.get_file_icon(filename)
Returns the full path to an icon file corresponding to filename”s contents.
cola.utils.get_libexec(*args)
Returns the path to the libexec scripts dir. This currently == ‘bin’ but it may change in the future.
cola.utils.get_qm_for_locale(locale)
Returns the .qm file for a particular $LANG values.
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_debian()
Is it debian?
cola.utils.is_linux()
Is this a linux machine?
cola.utils.run_cmd(*command)

Run arguments as a command and return output.

e.g. run_cmd(“echo”, “hello”, “world”)

cola.utils.sanitize_input(input)
Removes shell metacharacters from a string.
cola.utils.slurp(path)
Slurps a filepath into a string.
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.write(path, contents)
Writes a string to a file.

Previous topic

cola.settings – Settings manager

Next topic

cola.version – Release versioning

This Page