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.

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