Exemplo n.º 1
0
 def iter(cls, owner=None, remote=False):
     """
     Yield the name of each blueprint.
     """
     if owner is None:
         owner = auth.login()
     gitname = cls.gitname(owner)
     with context_managers.breakout():
         if not os.path.isdir(gitname):
             return
         if remote:
             with context_managers.cd(gitname):
                 p = subprocess.Popen(
                     ['git', 'ls-remote', '--heads', 'origin'],
                     close_fds=True, stdout=subprocess.PIPE)
                 stdout, stderr = p.communicate()
                 if 0 != p.returncode:
                     return
                 for line in stdout.splitlines():
                     sha, refname = line.split()
                     if 'refs/heads' == os.path.dirname(refname):
                         yield os.path.basename(refname)
         else:
             repo = dulwich.repo.Repo(gitname)
             for refname in repo.refs.keys():
                 if 'refs/heads' == os.path.dirname(refname):
                     yield os.path.basename(refname)
Exemplo n.º 2
0
    def repo(self):
        """
        Return a Dulwich Repo object pointing to the repository that belongs
        to the owner of this blueprint.

        Users of this property are responsible for ensuring they're in the
        base sandbox by using the `context_managers.breakout` context manager.
        """
        if hasattr(self, '_repo'):
            return self._repo
        gitname = self.gitname(self.owner)
        if not os.path.isdir(gitname):
            os.mkdir(gitname)
        try:
            self._repo = dulwich.repo.Repo.init_bare(gitname)
            with context_managers.cd(gitname):
                os.system(
                    'git remote add origin https://{0}:{1}@{2}/{3}'.format(
                        urllib.quote(self.owner, ''),
                        urllib.quote(auth.token(), ''),
                        'git.devstructure.com',
                        urllib.quote(os.path.basename(gitname), '')))
        except OSError:
            self._repo = dulwich.repo.Repo(gitname)
        return self._repo
Exemplo n.º 3
0
 def push(cls, name, owner=None):
     """
     Push the named blueprint to the central Git repository.
     """
     if owner is None:
         owner = auth.login()
     gitname = cls.gitname(owner)
     with context_managers.breakout():
         with context_managers.cd(gitname):
             status = os.system('git push origin {0}'.format(name))
             if 0 != status:
                 raise KeyError(name)
Exemplo n.º 4
0
 def pull(cls, name, owner=None):
     """
     Pull the named blueprint from the central Git repository.
     """
     if owner is None:
         owner = auth.login()
     gitname = cls.gitname(owner)
     with context_managers.breakout():
         with context_managers.cd(gitname):
             status = os.system('git remote update origin')
             if 0 != status:
                 raise KeyError(name)
             if os.path.exists('refs/heads/{0}'.format(name)):
                 return
             status = os.system(
                 'git branch {0} remotes/origin/{0}'.format(name))
             if 0 != status:
                 raise KeyError(name)
Exemplo n.º 5
0
 def destroy(cls, name, owner=None, remote=False):
     """
     Destroy the named blueprint.
     """
     if owner is None:
         owner = auth.login()
     gitname = cls.gitname(owner)
     with context_managers.breakout():
         if remote:
             with context_managers.cd(gitname):
                 os.system('git push origin :{0}'.format(name))
         else:
             if not os.path.isdir(gitname):
                 raise KeyError(name)
             repo = dulwich.repo.Repo(gitname)
             refname = os.path.join('refs/heads', name)
             repo.refs[refname] # To induce KeyError.
             del repo.refs[refname]