예제 #1
0
파일: home.py 프로젝트: westernx/vee
    def get_env_repo(self, name=None):

        name = name or self.default_repo_name

        if name:
            row = self.db.execute(
                'SELECT * FROM repositories WHERE name = ? LIMIT 1',
                [name]).fetchone()
            if not row:
                raise ValueError('%r repo does not exist' % name)

        else:
            # Grab the default repo if possible, otherwise make sure there is
            # only one.
            rows = self.db.execute(
                'SELECT * FROM repositories ORDER BY is_default DESC LIMIT 2'
            ).fetchall()
            if not rows:
                raise ValueError('no repositories exist')
            elif rows[0]['is_default']:
                row = rows[0]
            elif len(rows) == 1:
                row = rows[0]
            else:
                raise ValueError('multiple repositories with no default')

        env_repo = EnvironmentRepo(row, home=self)
        if not env_repo.exists:
            log.debug('Looking for env_repo: %s' % env_repo.work_tree)
            raise ValueError('%r repo does not exist' % env_repo.name)

        return env_repo
예제 #2
0
def list_(args):
    home = args.assert_home()
    rows = list(home.db.execute('SELECT * FROM repositories'))
    if not rows:
        print style_warning('No repositories.')
        return
    max_len = max(len(row['name']) for row in rows)
    for row in rows:
        env_repo = EnvironmentRepo(row, home=home)
        if env_repo.exists:
            print style_note(
                env_repo.name,
                '%s/%s' % (env_repo.remote_name, env_repo.branch_name),
                env_repo.remotes().get(env_repo.remote_name, '') + 
                ' --default' if row['is_default'] else '',
            )
예제 #3
0
파일: home.py 프로젝트: immersionroom/vee
    def create_repo(self,
                    path=None,
                    url=None,
                    name=None,
                    remote=None,
                    branch=None,
                    is_default=None):

        if path:
            path = os.path.abspath(path)
            if not os.path.exists(path):
                raise ValueError('no repo at %s' % path)

        if url or path:
            name = name or re.sub(r'\.git$', '', os.path.basename(url or path))
        else:
            name = name or self.default_repo_name or PRIMARY_REPO

        # Make sure it doesn't exist.
        try:
            repo = self.get_repo(name)
        except ValueError:
            pass
        else:
            raise ValueError('%r repo already exists' % name)

        branch = branch or get_default_branch()

        con = self.db.connect()
        cur = con.execute(
            'INSERT OR REPLACE INTO repositories (name, path, remote, branch, is_default) VALUES (?, ?, ?, ?, ?)',
            [name, path, remote or 'origin', branch,
             bool(is_default)])
        row = con.execute('SELECT * FROM repositories WHERE id = ?',
                          [cur.lastrowid]).fetchone()

        repo = EnvironmentRepo(row, home=self)
        if url:
            repo.clone_if_not_exists(url)
        elif not repo.exists:
            makedirs(repo.work_tree)
            repo.git('init')

        if branch != repo.get_current_branch():
            con.execute('UPDATE repositories SET branch = ? WHERE id = ?',
                        [repo.get_current_branch(), repo.id])

        return repo
예제 #4
0
파일: home.py 프로젝트: westernx/vee
 def iter_env_repos(self):
     for row in self.db.execute('SELECT * FROM repositories'):
         env_repo = EnvironmentRepo(row, home=self)
         if env_repo.exists:
             yield env_repo