Exemple #1
0
class IProgram(object):
    def __init__(self, ishell):
        self.ishell = ishell

    def run(self, **kwargs):
        kwargs = self.filter_prog_args(self, kwargs)
        self._output = SimpleCache(self._run_prog, lazy=False, **kwargs)
        return self._output.fetch()

    @property
    def output(self):
        return self._output.fetch()

    def refresh(self):
        ''' Naive program-level refresh: re-run with same args, result may change depending on e.g. filesystem state. '''
        return self._output.fetch(force_refresh=True)

    @abstractmethod
    def _run_prog(self, **kwargs):
        pass

    @classmethod
    @abstractmethod
    def arg_parser(cls, parent):
        pass

    @classmethod
    def _add_command_parser(cls, p, name, /, *args, aliases, **kwargs):
        return add_sub_parser(p, {'command': name},
                              *args,
                              aliases=aliases,
                              **kwargs)
Exemple #2
0
class Repo(object):
    ''' A cloned (on-the-filesystem) git repo representation. '''
    def __init__(self, ishell, path):
        self.ishell = ishell
        self.user_path = path
        self.git_controller = RawGitCommands(self.ishell, self.user_path)
        self._base_dir = self.git_controller.path
        self._head = SimpleCache(self._do_get_head)
        self._remote = SimpleCache(self.git_controller.get_remote)
        self._cur_branch = SimpleCache(self.git_controller.get_current_branch)

    @property
    def base_dir(self):
        return self._base_dir.fetch()

    @property
    def head(self):
        return self._head.fetch()

    @property
    def remote(self):
        return self._remote.fetch()

    def _do_get_head(self):
        head_hash = self.git_controller.get_current_hash()
        return CommitKey(self, Hash(head_hash))

    def __eq__(self, other):
        return self.remote == other.remote

    def __str__(self):
        return self.remote
Exemple #3
0
 def __init__(self, ishell, path):
     self.ishell = ishell
     self.user_path = path
     self.git_controller = RawGitCommands(self.ishell, self.user_path)
     self._base_dir = self.git_controller.path
     self._head = SimpleCache(self._do_get_head)
     self._remote = SimpleCache(self.git_controller.get_remote)
     self._cur_branch = SimpleCache(self.git_controller.get_current_branch)
Exemple #4
0
class Commit(object):
    ''' A single commit object. '''
    def __init__(self, key: 'CommitKey'):
        self.key = key
        self.git_controller = self.key.repo.git_controller
        self._pointing_branches = SimpleCache(self._do_get_pointing_branches)
        self._containing_branches = SimpleCache(
            self._do_get_containing_branches)
        self._tags = SimpleCache(self._do_get_tags)
        self._names = SimpleCache(self._do_get_names)
        self._diff = SimpleCache(self._do_get_diff)

    def is_repo_head(self):
        return self.key

    @property
    def pointing_branches(self):
        return self._pointing_branches.fetch()

    @property
    def containing_branches(self):
        return self._containing_branches.fetch()

    @property
    def tags(self):
        return self._tags.fetch()

    @property
    def names(self):
        return self._names.fetch()
        ''' Get commit names with the followng order: Current-Branch > Branches > Tags > Hash '''

    @property
    def hash(self):
        return self.key.hash

    def _do_get_names(self):
        names = []

        names += self.pointing_branches
        # TODO also head containing branches as e.g. BRANCH~23
        names += self.tags
        names.append(self.hash)

        return names

    def _do_get_pointing_branches(self):
        return self.git_controller.get_pointing_branches(self.key.hash.full)

    def _do_get_containing_branches(self):
        return self.git_controller.get_containing_branches(self.key.hash.full)

    def _do_get_tags(self):
        return self.git_controller.get_containing_tags(self.key.hash.full)

    def _do_get_diff(self):
        return self.git_controller.get_commit_diff(self.key.hash.full)
Exemple #5
0
 def __init__(self, key: 'CommitKey'):
     self.key = key
     self.git_controller = self.key.repo.git_controller
     self._pointing_branches = SimpleCache(self._do_get_pointing_branches)
     self._containing_branches = SimpleCache(
         self._do_get_containing_branches)
     self._tags = SimpleCache(self._do_get_tags)
     self._names = SimpleCache(self._do_get_names)
     self._diff = SimpleCache(self._do_get_diff)
Exemple #6
0
 def run(self, **kwargs):
     self.kwargs = kwargs
     self._output = SimpleCache(self._run_virt_prog)
Exemple #7
0
 def run(self, **kwargs):
     kwargs = self.filter_prog_args(self, kwargs)
     self._output = SimpleCache(self._run_prog, lazy=False, **kwargs)
     return self._output.fetch()