Пример #1
0
    def Installgit(self, entry):
        """Checkout contents from a git repository"""
        destname = entry.get('name')
        if os.path.lexists(destname):
            # remove incorrect contents
            try:
                if os.path.isdir(destname):
                    shutil.rmtree(destname)
                else:
                    os.remove(destname)
            except OSError:
                self.logger.info('Failed to remove %s' %
                                 destname)
                return False

        dulwich.file.ensure_dir_exists(destname)
        destr = dulwich.repo.Repo.init(destname)
        determine_wants = destr.object_store.determine_wants_all
        cl, host_path = dulwich.client.get_transport_and_path(
            entry.get('sourceurl'))
        remote_refs = cl.fetch(host_path,
                               destr,
                               determine_wants=determine_wants,
                               progress=sys.stdout.write)

        if entry.get('revision') in remote_refs:
            destr.refs['HEAD'] = remote_refs[entry.get('revision')]
        else:
            destr.refs['HEAD'] = entry.get('revision')

        dtree = destr['HEAD'].tree
        index = dulwich.index.Index(destr.index_path())
        for fname, mode, sha in destr.object_store.iter_tree_contents(dtree):
            full_path = os.path.join(destname, fname)
            dulwich.file.ensure_dir_exists(os.path.dirname(full_path))

            if stat.S_ISLNK(mode):
                src_path = destr[sha].as_raw_string()
                try:
                    os.symlink(src_path, full_path)
                except OSError:
                    e = sys.exc_info()[1]
                    if e.errno == errno.EEXIST:
                        os.unlink(full_path)
                        os.symlink(src_path, full_path)
                    else:
                        raise
            else:
                file = open(full_path, 'wb')
                file.write(destr[sha].as_raw_string())
                file.close()
                os.chmod(full_path, mode)

            st = os.lstat(full_path)
            index[fname] = index_entry_from_stat(st, sha, 0)

        index.write()
        return True
Пример #2
0
Файл: VCS.py Проект: rcuza/bcfg2
    def Installgit(self, entry):
        """Checkout contents from a git repository"""
        destname = entry.get('name')
        if os.path.lexists(destname):
            # remove incorrect contents
            try:
                if os.path.isdir(destname):
                    shutil.rmtree(destname)
                else:
                    os.remove(destname)
            except OSError:
                self.logger.info('Failed to remove %s' % destname)
                return False

        dulwich.file.ensure_dir_exists(destname)
        destr = dulwich.repo.Repo.init(destname)
        cl, host_path = dulwich.client.get_transport_and_path(
            entry.get('sourceurl'))
        remote_refs = cl.fetch(
            host_path,
            destr,
            determine_wants=destr.object_store.determine_wants_all,
            progress=sys.stdout.write)

        if entry.get('revision') in remote_refs:
            destr.refs['HEAD'] = remote_refs[entry.get('revision')]
        else:
            destr.refs['HEAD'] = entry.get('revision')

        dtree = destr['HEAD'].tree
        index = dulwich.index.Index(destr.index_path())
        for fname, mode, sha in destr.object_store.iter_tree_contents(dtree):
            full_path = os.path.join(destname, fname)
            dulwich.file.ensure_dir_exists(os.path.dirname(full_path))

            if stat.S_ISLNK(mode):
                src_path = destr[sha].as_raw_string()
                try:
                    os.symlink(src_path, full_path)
                except OSError:
                    e = sys.exc_info()[1]
                    if e.errno == errno.EEXIST:
                        os.unlink(full_path)
                        os.symlink(src_path, full_path)
                    else:
                        raise
            else:
                file = open(full_path, 'wb')
                file.write(destr[sha].as_raw_string())
                file.close()
                os.chmod(full_path, mode)

            st = os.lstat(full_path)
            index[fname] = index_entry_from_stat(st, sha, 0)

        index.write()
        return True
Пример #3
0
def rm(repo=".", paths=None):
    """Remove files from the staging area.

    :param repo: Repository for the files
    :param paths: Paths to remove
    """
    r = open_repo(repo)
    index = r.open_index()
    for p in paths:
        del index[p]
    index.write()
Пример #4
0
def rm(repo=".", paths=None):
    """Remove files from the staging area.

    :param repo: Repository for the files
    :param paths: Paths to remove
    """
    r = open_repo(repo)
    index = r.open_index()
    for p in paths:
        del index[p]
    index.write()
Пример #5
0
 def _checkout_entry(self,index,path,mode,sha):
     full_path = os.path.join(self.path, path)
     checked_out_entry = False
     if stat.S_ISREG(mode):
         if not os.path.exists(os.path.dirname(full_path)):
             os.makedirs(os.path.dirname(full_path))
         f = open(full_path, 'wb')
         try:
             f.write(self.object_store[sha].as_raw_string())
         finally:
             f.close()
         os.chmod(full_path, mode)
         checked_out_entry = True
     elif dulwich.objects.S_ISGITLINK(mode) and path in self.subrepo:
         self.subrepo[path][1].checkout(self.subrepo[path][0])
         checked_out_entry = True
     if checked_out_entry:
         st = os.lstat(full_path)
         index[path] = index_entry_from_stat(st, sha, 0, mode=mode)
         index.write()