Utilities

Note

The documentation in this section is aimed at people wishing to contribute to hubugs, and can be skipped if you are simply using the tool from the command line.

hubugs.utils.setup_environment(args)

Configure execution environment for commands dispatch.

Parameters:args (argparse.Namespace) – argparse namespace to operate on

Convenience functions

hubugs.utils.check_output(args, **kwargs)

Simple check_output implementation for Python 2.6 compatibility.

Parameters:args (list) – Command and arguments to call
Return type:str
Returns:Command output
Raises:subprocess.CalledProcessError – If command execution fails
hubugs.utils.get_editor()

Choose a suitable editor.

See git-var(1) for details.

Return type:list of str
Returns:Users chosen editor, or vi if not set
hubugs.utils.pager(text, pager='less')

Pass output through pager.

Parameters:
  • text (str) – Text to page
  • pager (bool) – Pager to use

Git/GitHub support

hubugs.utils.get_github_api()

Create a GitHub API instance.

Return type:httplib2.Http
Returns:GitHub HTTP session
hubugs.utils.get_git_config_val(key, default=None, local_only=False)

Fetch a git configuration value.

Parameters:
  • key (str) – Configuration value to fetch
  • default (str) – Default value to use, if key isn’t set
  • local_only (bool) – Fetch configuration values from repo config only
Return type:

str

Returns:

Git config value, if set

hubugs.utils.set_git_config_val(key, value, local_only=False)

Set a git configuration value.

Parameters:
  • key (str) – Configuration value to fetch
  • value (str) – Value to set
  • local_only (bool) – Set configuration values from repo config only
hubugs.utils.get_repo()

Extract GitHub project name from git/hg config.

We check the git config for hubugs.project, and then fall back to remote.origin.url. If both of these fail we check a mercurial root, to satisfy the hg-git users.

Return type:str
Returns:GitHub project name, including user
hubugs.utils.sync_labels(args)

Manage labels for a project.

Parameters:args (argparse.Namespace) – argparse namespace to operate on
Return type:list
Returns:List of project’s label names

Text formatting

hubugs.utils._colourise(text, colour)

Colour text, if possible.

Parameters:
  • text (str) – Text to colourise
  • colour (str) – Colour to display text in
Return type:

str

Returns:

Colourised text, if possible

hubugs.utils.success(text)

Output a success message.

Parameters:text (str) – Text to format
Return type:str
Returns:Bright green text, if possible
hubugs.utils.fail(text)

Output a failure message.

Parameters:text (str) – Text to format
Return type:str
Returns:Bright red text, if possible
hubugs.utils.warn(text)

Output a warning message.

Parameters:text (str) – Text to format
Return type:str
Returns:Bright yellow text, if possible