2. Code Documentation¶
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
ifArgParser
completed parsing the command line arguments without any errors, otherwiseFalse
.-
__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 variableexit_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
.
-
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 toNone
, the configuration is just stored in-memory untilwrite()
is invoked. Instead ifconfig_file_name
is specified, the config file is opened, parsed and the instance represents the state of the config file.Raises: ClientInfoError
whenconfig_file_name
is notNone
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 theRepoBuddyClientInfo
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 theRepoBuddyClientInfo
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 theclient_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 themanifest
option.
-
write
(file_name=None)[source]¶ Write the config to a file.
If
file_name
is set toNone
, 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 parameterfile_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 isNone
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
.
-
class
repobuddy.command_handler.
CommandHandler
[source]¶ Bases:
object
Provides handlers for the
repobuddy
commands.-
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
ifGitWrapper
got back a non-zero status after executing of any of the git commands, otherwiseFalse
.
-
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
ifbase_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 theclone
operation, the working directory is changed todest_dir
.Parameters: Dest_dir: Destination path to store the cloned repository.
Returns: None
Raises: GitWrapperError
if thegit clone
command fails.
-
update_index
()[source]¶ Refresh the index.
Executes
git update-index -q --ignore-submodules --refresh
.Returns: None Raises: GitWrapperError
if thegit 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 thegit 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 thegit 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 thegit 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, otherwiseNone
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 byHEAD
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
.
-
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¶
2.8. repobuddy.manifest_parser
- Manifest Parser¶
-
exception
repobuddy.manifest_parser.
ManifestParserError
(error_str)[source]¶ Bases:
repobuddy.utils.RepoBuddyBaseException
Exception raised by
ManifestParser
.
-
class
repobuddy.manifest_parser.
Repo
(url=None, branch=None, dest=None)[source]¶ Bases:
repobuddy.utils.EqualityBase
Represents the Repository in the manifest.
-
class
repobuddy.manifest_parser.
ClientSpec
(name=None, repo_list=None)[source]¶ Bases:
repobuddy.utils.EqualityBase
Represents the Client Spec in the manifest.
-
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.
-
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.
-
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
.
-
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.
-
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. Iftimeout
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 raisesFileLockError
withis_time_out
set toTrue
.Returns: None Raises: FileLockError
on errors.is_time_out
is set toTrue
only if the designatedtimeout
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
.
-
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: Returns: A stream object representing the resource file.
Raises: ResourceHelperError
if unable to locate the resourcefile_name
inpackage_name
.
-
classmethod
-
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
.
-
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.