2. Code Documentation

2.1. repobuddy – Root package

repobuddy module.

2.2. repobuddy.arg_parser - Argument Parser

exception repobuddy.arg_parser.ArgParserError(error_str=None, exit_prog_without_error=False)[source]

Bases: repobuddy.utils.RepoBuddyBaseException

Exception raised by ArgParser.

Variables:exit_prog_without_error – Set to True if ArgParser completed parsing the command line arguments without any errors, otherwise False.
__init__(error_str=None, exit_prog_without_error=False)[source]

Initializer.

Parameters:
  • error_str (str) – The error string to store in the exception.
  • exit_prog_without_error (Boolean) – If True indicates that the program exited without any errors, otherwise not. The instance variable exit_prog_without_error stores this value.
class repobuddy.arg_parser.ArgParser(handlers)[source]

Bases: object

Parses command line arguments for repobuddy.

__init__(handlers)[source]

Initializer.

Parameters:handlers (dict) – A dictionary with command names as keys and the handler functions as values.
Returns:None
parse(args)[source]

Parse the command line arguments to repobuddy.

Parameters:args (list of strings) – List of command line arguments.
Returns:None
Raises:ArgParserError on parsing errors.

2.3. repobuddy.client_info – Client Info

exception repobuddy.client_info.ClientInfoError(error_str)[source]

Bases: repobuddy.utils.RepoBuddyBaseException

Exception raised by ClientInfo.

__init__(error_str)[source]

Initializer.

Parameters:error_str (str) – The error string to store in the exception.
class repobuddy.client_info.ClientInfo(config_file_name=None)[source]

Bases: object

Parses/Stores/Retrieves the client configuration.

__init__(config_file_name=None)[source]

Initializer.

Parameters:

config_file_name (str) – The name of the config file. If config_file_name is set to None, the configuration is just stored in-memory until write() is invoked. Instead if config_file_name is specified, the config file is opened, parsed and the instance represents the state of the config file.

Raises:

ClientInfoError when config_file_name is not None and any of the following conditions are met:

  • Failed to open the config file.
  • Parsing errors have been detected.
  • Validating the config failed.
set_client_spec(client_spec_name)[source]

Set the client_spec in the config.

Parameters:client_spec_name (str) – The value for client_spec in the config.
Returns:None
Raises:ClientInfoError if the config does not already have the RepoBuddyClientInfo section.
set_manifest(manifest_xml)[source]

Set the manifest in the config.

Parameters:manifest_xml (str) – The value for manifest in the config.
Returns:None
Raises:ClientInfoError if the config does not have the RepoBuddyClientInfo section.
get_client_spec()[source]

Get the value of client_spec in the config.

Returns:The value of client_spec in the config.
Return type:str
Raises:ClientInfoError if the config does not have the client_spec option.
get_manifest()[source]

Get the value of manifest in the config.

Returns:The value of manifest in the config.
Return type:str
Raises:ClientInfoError if the config does not have the manifest option.
write(file_name=None)[source]

Write the config to a file.

If file_name is set to None, the filename passed during the class initialization is used instead. If there was a file name specified during both initialization, as well as in the parameter file_name, this method’s parameter takes precedece, and the file name specififed during initialization remains unmodified.

Parameters:

file_name (str) – The name of the file to write the config into.

Returns:

None

Raises:

ClientInfoError when any of the following conditions are met:

  • file_name parameter is None and no file name was provided during initialization.
  • validation of the config failed.
  • writing the config to the file failed.

2.4. repobuddy.command_handler - Command Handler

exception repobuddy.command_handler.CommandHandlerError(error_str)[source]

Bases: repobuddy.utils.RepoBuddyBaseException

Exception raised by CommandHandler.

__init__(error_str)[source]
class repobuddy.command_handler.CommandHandler[source]

Bases: object

Provides handlers for the repobuddy commands.

__init__()[source]

Initializer.

get_handlers()[source]

Get the command handlers.

Returns:Dictionary with command names as keys and the methods as values.
Return type:dict
init_command_handler(args)[source]

Handler for the init command.

Returns:None
Raises:CommandHandlerError on errors.
status_command_handler(_args)[source]

Handler for the status command.

Returns:None
Raises:CommandHandlerError on errors.

2.5. repobuddy.git_wrapper - Git Wrapper

exception repobuddy.git_wrapper.GitWrapperError(error_str, is_git_error, git_error_msg='')[source]

Bases: repobuddy.utils.RepoBuddyBaseException

Exception raised by GitWrapper.

Variables:is_git_error – Set to True if GitWrapper got back a non-zero status after executing of any of the git commands, otherwise False.
__init__(error_str, is_git_error, git_error_msg='')[source]

Initializer.

Parameters:error_str (str) – The error string to store in the exception.
class repobuddy.git_wrapper.GitWrapper(base_dir)[source]

Bases: object

Helper for invoking git.

Provides a way to access and/or control the state of a git repository. Internally, it executes git commands in the work-tree for various operations.

__init__(base_dir)[source]

Initializer.

Parameters:base_dir (str) – Absolute path of the git repository work-tree.
Returns:None
Raises:GitWrapperError if base_dir is not an absolute path.
clone(remote_url, branch, dest_dir)[source]

Clone a repo.

Executes git clone -b branch remote_url dest_dir. At the end of the clone operation, the working directory is changed to dest_dir.

Parameters:
  • remote_url (str) – URL of the repository.
  • branch (str) – Branch to checkout after the clone.
Dest_dir:

Destination path to store the cloned repository.

Returns:

None

Raises:

GitWrapperError if the git clone command fails.

update_index()[source]

Refresh the index.

Executes git update-index -q --ignore-submodules --refresh.

Returns:None
Raises:GitWrapperError if the git update-index command fails.
get_untracked_files()[source]

Get a list of all untracked files in the repository.

Returns the files in git ls-files --exclude-standard --others -- as a list.

Returns:List of untracked files.
Return type:list of str
Raises:GitWrapperError if the git ls-files command fails.
get_unstaged_files()[source]

Get a list of all unstaged files in the repository.

Returns the files in git diff-files --name-status -r --ignore-submodules -- as a list.

Returns:List of unstaged files.
Return type:list of str
Raises:GitWrapperError if the git diff-files command fails.
get_uncommitted_staged_files()[source]

Get a list of all uncommitted but staged files.

Returns the files in git diff-index --cached --name-status -r --ignore-submodules.

Returns:List of uncommitted files in the staging area.
Return type:list of str
Raises:GitWrapperError if the git diff-index command fails.
get_current_branch()[source]

Get the currently checked out branch.

Returns:Currently checked out Branch name if HEAD points to a branch, otherwise None
Return type:str
Raises:GitWrapperError on errors.
get_current_tag()[source]

Get the currently checked out tag.

Returns:The tag name which is currently checked out, None otherwise. If the commit pointed by HEAD contains more than one tag, the returned tag name could be any one of those tags.
Return type:str
Raises:GitWrapperError on errors.

2.6. repobuddy.globals - Global Definitions

exception repobuddy.globals.HelpStringsError(error_str)[source]

Bases: repobuddy.utils.RepoBuddyBaseException

Exception raised by HelpStrings.

__init__(error_str)[source]

Initializer.

Parameters:error_str (str) – The error string to store in the exception.
class repobuddy.globals.HelpStrings[source]

Definition of various strings used by the rest of repobuddy.

PROGRAM_DESCRIPTION = 'Multi-repo manager for Git'
PROGRAM_NAME = 'repobuddy'
PROGRAM_VERSION = '%(prog)s 0.3beta'
MASTER_PARSER_ARG_HELP = 'Command to invoke'
MASTER_PARSER_ARG_TITLE = 'Available Commands'
INIT_COMMAND_HELP = 'Init the current directory to set up the repos'
INIT_MANIFEST_ARG = 'The Manifest file to use for this client'
INIT_CLIENT_SPEC_ARG = 'The Client Spec in the Manifest to use for this client'
HELP_COMMAND_HELP = 'Show usage details for a command'
HELP_COMMAND_ARG = 'Command to see the help message for'
STATUS_COMMAND = 'Show status of the current client config'

2.7. repobuddy.main - Program’s Main Routine

repobuddy.main.run_repobuddy()[source]

Invoke repobuddy with the command line arguments.

The application exits with status 1 on errors, 0 otherwise.

returns: None

2.8. repobuddy.manifest_parser - Manifest Parser

exception repobuddy.manifest_parser.ManifestParserError(error_str)[source]

Bases: repobuddy.utils.RepoBuddyBaseException

Exception raised by ManifestParser.

__init__(error_str)[source]
class repobuddy.manifest_parser.Repo(url=None, branch=None, dest=None)[source]

Bases: repobuddy.utils.EqualityBase

Represents the Repository in the manifest.

__init__(url=None, branch=None, dest=None)[source]

Initializer.

Parameters:
  • url (str) – URL of the repository.
  • branch (str) – Name of the branch to checkout.
Dest:

Destination directory.

class repobuddy.manifest_parser.ClientSpec(name=None, repo_list=None)[source]

Bases: repobuddy.utils.EqualityBase

Represents the Client Spec in the manifest.

__init__(name=None, repo_list=None)[source]

Initializer.

Parameters:
  • name (str) – Name of the client spec.
  • repo_list – List of Repositories in the manifest.
Type:

list of Repo

class repobuddy.manifest_parser.Manifest(default_client_spec=None, client_spec_list=None)[source]

Bases: repobuddy.utils.EqualityBase

Represents the manifest.

__init__(default_client_spec=None, client_spec_list=None)[source]

Initializer.

Parameters:
  • default_client_spec (str) – Default client spec.
  • client_spec_list (list of ClientSpec) – List of client specs.
class repobuddy.manifest_parser.ManifestParser[source]

Bases: object

Helper class for parsing the manifest XML.

__init__()[source]

Initializer.

parse(file_handle)[source]

Parse the manifest from the stream.

Parameters:file_handle (File object.) – The stream to parse the manifest from.
Returns:None
Raises:ManifestParserError on errors.
get_manifest()[source]

Get the manifest.

Returns:The parsed manifest.
Return type:Manifest.

2.9. repobuddy.utils - Utility classes and functions

exception repobuddy.utils.RepoBuddyBaseException(error_str)[source]

Bases: exceptions.Exception

Base class of all exceptions in repobuddy.

__init__(error_str)[source]

Initializer.

Parameters:error_str (str) – The error string to store in the exception.
exception repobuddy.utils.FileLockError(error_str, is_time_out=False)[source]

Bases: repobuddy.utils.RepoBuddyBaseException

Exception raised by FileLock.

Variables:is_time_out – Set to True if a timeout occurred when trying to acquire the lock, False otherwise.
__init__(error_str, is_time_out=False)[source]

Initializer.

Parameters:
  • error_str (str) – The error string to store in the exception.
  • is_time_out – If True, the error is because of a timeout in acquiring the lock. The is_time_out instance variable in the exception object is set to this value.
class repobuddy.utils.FileLock(file_name, timeout=1, delay=0.1)[source]

Bases: object

A mutual exclusion primitive using lock files.

__init__(file_name, timeout=1, delay=0.1)[source]

Initializer.

Parameters:
  • file_name (str) – Name of the lock file to be created. Filename can be either an absolute or a relative file path.
  • timeout (float) – Maxium time in seconds until acquire() blocks in trying to acquire the lock. If timeout seconds have elapsed without successfully acquiring the lock, FileLockError is raised.
  • delay (float) – Time interval in seconds between 2 successive lock attempts.
acquire()[source]

Acquire the lock.

Acquires the lock within the designated timeout, failing which it raises FileLockError with is_time_out set to True.

Returns:None
Raises:FileLockError on errors. is_time_out is set to True only if the designated timeout has elapsed.
release()[source]

Release the lock.

Returns:None
Raises:FileLockError on errors. If the lock file has already been deleted, no exception is raised.
exception repobuddy.utils.ResourceHelperError(error_str)[source]

Bases: repobuddy.utils.RepoBuddyBaseException

Exception raised by ResourceHelper.

__init__(error_str)[source]

Initializer.

Parameters:error_str (str) – The error string to store in the exception.
class repobuddy.utils.ResourceHelper[source]

A helper class for loading resources.

classmethod open_data_file(package_name, file_name)[source]

Get a stream handle to the resource.

Parameters:
  • package_name (str) – Package name to fetch the resource from.
  • file_name (str) – Filename of the resource.
Returns:

A stream object representing the resource file.

Raises:

ResourceHelperError if unable to locate the resource file_name in package_name.

class repobuddy.utils.EqualityBase[source]

Bases: object

Rrovides equality comparison operations.

A base class which provides support for performing equality comparison on the instance. The type and the instance dictionary are used for comparison.

exception repobuddy.utils.LoggerError(error_str)[source]

Bases: exceptions.Exception

Exception raised by Logger.

__init__(error_str)[source]

Initializer.

Parameters:error_str (str) – The error string to store in the exception.
class repobuddy.utils.Logger[source]

Provides logging support for the rest of repobuddy.

Currently supported log levels are:

  • DEBUG
  • MESSAGE
  • ERROR
disable_debug = True
debug_stream = <open file '<stdout>', mode 'w'>
msg_stream = <open file '<stdout>', mode 'w'>
error_stream = <open file '<stdout>', mode 'w'>
classmethod msg(msg, append_new_line=True)[source]

Add a log entry of level MESSAGE.

Parameters:
  • msg (str) – The message to log.
  • append_new_line (Boolean) – Appends a new line after the log message when set to True.
Returns:

None

Raises:

LoggerError on errors.

classmethod debug(msg, append_new_line=True)[source]

Add a log entry of level DEBUG.

Parameters:
  • msg (str) – The message to log.
  • append_new_line (Boolean) – Appends a new line after the log message when set to True.
Returns:

None

Raises:

LoggerError on errors.

classmethod error(msg, append_new_line=True)[source]

Add a log entry of level ERROR.

Parameters:
  • msg (str) – The message to log.
  • append_new_line (Boolean) – Appends a new line after the log message when set to True.
Returns:

None

Raises:

LoggerError on errors.