def initializer(gitrepo): """ Initializes a Git repo for use with jig. This will create a directory in the root of the Git repo that will contain files (plugins) and configuration. """ # If it's already initialized, refuse to run if repo_jiginitialized(gitrepo): raise AlreadyInitialized('The repository is already initialized.') # Create the container for all things jig jig_dir = join(gitrepo, JIG_DIR_NAME) mkdir(jig_dir) mkdir(join(jig_dir, JIG_PLUGIN_DIR)) set_jigconfig(gitrepo) # Initialize the date plugins were last checked to right now config = set_jigconfig( gitrepo, set_checked_for_updates(gitrepo)) return config
def get_jigconfig(gitrepo): """ Gets the config for a jig initialized Git repo. """ jig_dir = join(gitrepo, JIG_DIR_NAME) if not repo_jiginitialized(gitrepo): raise GitRepoNotInitialized( 'This repository has not been initialized.') with open(join(jig_dir, JIG_PLUGIN_CONFIG_FILENAME), 'r') as fh: plugins = SafeConfigParser() plugins.readfp(fh) return plugins
def set_jigconfig(gitrepo, config=None): """ Saves the config for jig in the Git repo. The ``config`` argument must be an instance of :py:class:`ConfigParser`. """ # If it's already initialized, refuse to run if not repo_jiginitialized(gitrepo): raise GitRepoNotInitialized('The repository has not been initialized.') # Create the container for all things jig jig_dir = join(gitrepo, JIG_DIR_NAME) # Create an empty config parser if we were not passed one plugins = config if config else SafeConfigParser() # Create a plugin list file with open(join(jig_dir, JIG_PLUGIN_CONFIG_FILENAME), 'w') as fh: plugins.write(fh) return plugins
def initializer(gitrepo): """ Initializes a Git repo for use with jig. This will create a directory in the root of the Git repo that will contain files (plugins) and configuration. """ # If it's already initialized, refuse to run if repo_jiginitialized(gitrepo): raise AlreadyInitialized('The repository is already initialized.') # Create the container for all things jig jig_dir = join(gitrepo, JIG_DIR_NAME) mkdir(jig_dir) mkdir(join(jig_dir, JIG_PLUGIN_DIR)) set_jigconfig(gitrepo) # Initialize the date plugins were last checked to right now config = set_jigconfig(gitrepo, set_checked_for_updates(gitrepo)) return config
def results(self, gitrepo, plugin=None, rev_range=None): """ Run jig in the repository and return results. Results will be a dictionary where the keys will be individual plugins and the value the result of calling their ``pre_commit()`` methods. :param unicode gitrepo: path to the Git repository :param unicode plugin: the name of the plugin to run, if None then run all plugins :param unicode rev_range: the revision range to use instead of the Git index """ self.gitrepo = gitrepo # Is this repository initialized to use jig on? with self.view.out() as out: if not repo_jiginitialized(self.gitrepo): raise GitRepoNotInitialized( 'This repository has not been initialized.') pm = PluginManager(get_jigconfig(self.gitrepo)) # Check to make sure we have some plugins to run with self.view.out() as out: if len(pm.plugins) == 0: out.append('There are no plugins installed, ' 'use jig install to add some.') return self.repo = Repo(gitrepo) diff = _diff_for(self.repo, rev_range) if diff is None: # No diff on head, no commits have been written yet out.append('This repository is empty, jig needs at ' 'least 1 commit to continue.') # Let execution continue so they *can* commit that first # changeset. This is a special mode that should not cause Jig # to exit with non-zero. return if len(diff) == 0: # There is nothing changed in this repository, no need for # jig to run so we exit with 0. out.append( 'No staged changes in the repository, skipping jig.') return # Our git diff index is an object that makes working with the diff much # easier in the context of our plugins. gdi = GitDiffIndex(self.gitrepo, diff) # Go through the plugins and gather up the results results = OrderedDict() for installed in pm.plugins: if plugin and installed.name != plugin: # This plugin doesn't match the requested continue retcode, stdout, stderr = installed.pre_commit(gdi) try: # Is it JSON data? data = json.loads(stdout) except ValueError: # Not JSON data = stdout results[installed] = (retcode, data, stderr) return results
def results(self, gitrepo, plugin=None, rev_range=None): """ Run jig in the repository and return results. Results will be a dictionary where the keys will be individual plugins and the value the result of calling their ``pre_commit()`` methods. :param unicode gitrepo: path to the Git repository :param unicode plugin: the name of the plugin to run, if None then run all plugins :param unicode rev_range: the revision range to use instead of the Git index """ self.gitrepo = gitrepo # Is this repository initialized to use jig on? with self.view.out() as out: if not repo_jiginitialized(self.gitrepo): raise GitRepoNotInitialized( 'This repository has not been initialized.') pm = PluginManager(get_jigconfig(self.gitrepo)) # Check to make sure we have some plugins to run with self.view.out() as out: if len(pm.plugins) == 0: out.append( 'There are no plugins installed, ' 'use jig install to add some.') return self.repo = Repo(gitrepo) diff = _diff_for(self.repo, rev_range) if diff is None: # No diff on head, no commits have been written yet out.append( 'This repository is empty, jig needs at ' 'least 1 commit to continue.') # Let execution continue so they *can* commit that first # changeset. This is a special mode that should not cause Jig # to exit with non-zero. return if len(diff) == 0: # There is nothing changed in this repository, no need for # jig to run so we exit with 0. out.append( 'No staged changes in the repository, skipping jig.') return # Our git diff index is an object that makes working with the diff much # easier in the context of our plugins. gdi = GitDiffIndex(self.gitrepo, diff) # Go through the plugins and gather up the results results = OrderedDict() for installed in pm.plugins: if plugin and installed.name != plugin: # This plugin doesn't match the requested continue retcode, stdout, stderr = installed.pre_commit(gdi) try: # Is it JSON data? data = json.loads(stdout) except ValueError: # Not JSON data = stdout results[installed] = (retcode, data, stderr) return results