Ejemplo n.º 1
0
def checkin(url, files, message=None):
    """
    Check in files to a repository.

    :param url: URL of repo to check files into.
    :param message: Optional commit message.
    """
    from grit import Repo, Item
    r = Repo(url)

    if not files:
        raise GritError('No files')

    def _write(path):
        item = Item.from_path(repo=r, path=path)
        if r.isLocal():
            v.addItem(item=item)
        else:
            r.upload(filename=os.path.basename(path), filedata=open(path, 'r').read())

    if r.isLocal():
        v = r.addVersion()
    count = 1
    total = len(files) 
    while count <= total:
        print '[%s/%s] %0.2f%%' %(count, total, (float(count) / total) * 100), '*'*count, '\r',
        _write(os.path.abspath(files[count-1]))
        count += 1
        sys.stdout.flush()
    if message is None:
        message = 'Publishing %s' % ', '.join(files)
    if r.isLocal():
        v.save(message=message)
    print
Ejemplo n.º 2
0
def new(url):
    """
    Creates a new Repo class instance at url.

    :param url: URL of new repo

    :return: new Repo class instance.
    """
    from grit import Repo
    return Repo.new(url=url, bare=True)
Ejemplo n.º 3
0
def checkout(url, version=None):
    """
    Checks out latest version of item or repository.

    :param url: URL of repo or item to check out.
    :param version: Version number to check out.
    """
    from grit import Repo
    r = Repo(url)

    def _write(item):
        log.debug('writing: %s' % item.name)
        if item.type != 'blob':
            return
        if r.type in ['repo', 'proxy', 'local']:
            path = os.path.join(r.name, item.path)
            pdir = os.path.dirname(path)
            if not os.path.isdir(pdir):
                os.makedirs(pdir)
        else:
            path = item.name

        f = open(path, 'w')
        f.write(item.data())
        f.close()

    if r.type == 'blob':
        _write(r)
    else:
        items = r.items()
        count = 1
        total = len(items)
        while count <= total:
            print '[%s/%s] %0.2f%%' %(count, total, (float(count) / total) * 100), '*'*count, '\r',
            _write(items[count-1])
            count += 1
            sys.stdout.flush()
        print
Ejemplo n.º 4
0
 def setUp(self):
     # create a new repo instance
     n = int(time.time())
     self.tempdir = os.path.join(tempfile.gettempdir(), 'grit-unittest-%d' % n)
     self.repo = Repo.new(self.tempdir)
     time.sleep(1)