diff --git a/modules/core/git.py b/modules/core/git.py index 468d174..7bff60b 100644 --- a/modules/core/git.py +++ b/modules/core/git.py @@ -9,38 +9,31 @@ Requires: """ import os -import string -import logging -try: - import pygit2 -except ImportError: - pass +import pygit2 -import bumblebee.input -import bumblebee.output -import bumblebee.engine -import bumblebee.util +import core.module +import core.widget -class Module(bumblebee.engine.Module): - def __init__(self, engine, config): - widgets = [] - super(Module, self).__init__(engine, config, widgets) - self._engine = engine - self._error = False - self.update(self.widgets()) +import util.cli + +class Module(core.module.Module): + def __init__(self, config): + super().__init__(config, []) + + self.__error = False def hidden(self): - return self._error + return self.__error - def update(self, widgets): + def update(self): state = {} new_widgets = [] try: - directory = bumblebee.util.execute("xcwd").strip() - directory = self._get_git_root(directory) + directory = util.cli.execute("xcwd").strip() + directory = self.__get_git_root(directory) repo = pygit2.Repository(directory) - new_widgets.append(bumblebee.output.Widget(name='git.main', full_text=repo.head.shorthand)) + new_widgets.append(core.widget.Widget(name='git.main', full_text=repo.head.shorthand)) for filepath, flags in repo.status().items(): if flags == pygit2.GIT_STATUS_WT_NEW or \ @@ -52,26 +45,24 @@ class Module(bumblebee.engine.Module): if flags == pygit2.GIT_STATUS_WT_MODIFIED or \ flags == pygit2.GIT_STATUS_INDEX_MODIFIED: state['modified'] = True - self._error = False + self.__error = False if 'new' in state: - new_widgets.append(bumblebee.output.Widget(name='git.new')) + new_widgets.append(core.widget.Widget(name='git.new')) if 'modified' in state: - new_widgets.append(bumblebee.output.Widget(name='git.modified')) + new_widgets.append(core.widget.Widget(name='git.modified')) if 'deleted' in state: - new_widgets.append(bumblebee.output.Widget(name='git.deleted')) + new_widgets.append(core.widget.Widget(name='git.deleted')) - while len(widgets) > 0: - del widgets[0] - for widget in new_widgets: - widgets.append(widget) + self.widgets().clear() + self.widget(new_widgets) except Exception as e: - self._error = True + self.__error = True def state(self, widget): return widget.name.split('.')[1] - def _get_git_root(self, directory): + def __get_git_root(self, directory): while len(directory) > 1: if os.path.exists(os.path.join(directory, ".git")): return directory