コード例 #1
0
ファイル: __init__.py プロジェクト: 000fan000/code
 def add_mirror_project(project):
     name = "mirror/%s" % (project.name)
     _project = CodeDoubanProject.add(
         name=name, owner_id='mirror', summary=project.summary,
         product=project.product, intern_banned=project.intern_banned,
         mirror=project.mirror_url)
     if _project:
         CodeDoubanMirror.add(url=project.mirror_url,
                              state=MIRROR_STATE_CLONING,
                              project_id=_project.id,
                              with_proxy=project.mirror_proxy)
     return _project
コード例 #2
0
ファイル: update_mirrors.py プロジェクト: 000fan000/code
def main():
    try:
        mirror_projects = CodeDoubanProject.get_projects(owner='mirror', sortby='created')
        for project in mirror_projects:
            mirror = CodeDoubanMirror.get_by_project_id(project.id)
            if not mirror:
                print "New: ", project.id, project.name, project.url
                mirror_url = project.git.call('ls-remote --get-url origin')
                CodeDoubanMirror.add(mirror_url, MIRROR_STATE_CLONED, project.id)
            else:
                print "Added: ", project.id, project.name, project.url
    except Exception, e:
        print_exc()
        sys.exit(1)
コード例 #3
0
 def add_mirror_project(project):
     name = "mirror/%s" % (project.name)
     _project = CodeDoubanProject.add(
         name=name,
         owner_id='mirror',
         summary=project.summary,
         product=project.product,
         intern_banned=project.intern_banned,
         mirror=project.mirror_url)
     if _project:
         CodeDoubanMirror.add(url=project.mirror_url,
                              state=MIRROR_STATE_CLONING,
                              project_id=_project.id,
                              with_proxy=project.mirror_proxy)
     return _project
コード例 #4
0
ファイル: update_mirrors.py プロジェクト: jackfrued/code-1
def main():
    try:
        mirror_projects = CodeDoubanProject.get_projects(owner='mirror',
                                                         sortby='created')
        for project in mirror_projects:
            mirror = CodeDoubanMirror.get_by_project_id(project.id)
            if not mirror:
                print "New: ", project.id, project.name, project.url
                mirror_url = project.git.call('ls-remote --get-url origin')
                CodeDoubanMirror.add(mirror_url, MIRROR_STATE_CLONED,
                                     project.id)
            else:
                print "Added: ", project.id, project.name, project.url
    except Exception, e:
        print_exc()
        sys.exit(1)
コード例 #5
0
ファイル: __init__.py プロジェクト: 000fan000/code
 def validate_project(project_type, project):
     error = ''
     if project_type in (PEOPLE_PROJECT, ORGANIZATION_PROJECT):
         error = project.validate()
     elif project_type == MIRROR_PROJECT:
         error = project.validate()
         if not error:
             error = CodeDoubanMirror.validate(project.mirror_url)
     else:
         error = project.validate()
     return error
コード例 #6
0
 def validate_project(project_type, project):
     error = ''
     if project_type in (PEOPLE_PROJECT, ORGANIZATION_PROJECT):
         error = project.validate()
     elif project_type == MIRROR_PROJECT:
         error = project.validate()
         if not error:
             error = CodeDoubanMirror.validate(project.mirror_url)
     else:
         error = project.validate()
     return error
コード例 #7
0
ファイル: source.py プロジェクト: leeccong/code
def _get_tmpl_tree(tmpl_target, ref, path, project_name, request):
    project = CodeDoubanProject.get_by_name(project_name)
    if not project:
        raise TraversalError("Wrong path for tree %s" % path)
    if project.is_mirror_project:
        mirror = CodeDoubanMirror.get_by_project_id(project.id)
        if not mirror.is_clone_completed:
            return st("/projects/mirror_cloning.html", **locals())
    if not project.repo:
        raise TraversalError("Wrong path for tree %s" % path)
    if not ref:
        ref = project.default_branch

    tree_path = path.decode("utf-8")
    last_commit = project.repo.get_last_commit(ref, path=path) if ref else ""
    tdt = _tmpl_common_data(ref, path, project_name, request)
    user = tdt["user"]
    if user is not None:
        username = user.username
        cur_user_project = project.get_forked_project(username)
        if cur_user_project is not None:
            latest_branch = _latest_update_branch(cur_user_project, ref, user)
            if latest_branch:
                cur_user_latest_branch_name = "{0}:{1}".format(username, latest_branch)
                tdt["latest_update_branch"].append((cur_user_project, cur_user_latest_branch_name, latest_branch))
    tdt.update({"lastcommit": last_commit})

    tree = []
    is_empty = True
    if last_commit:
        tree = project.repo.get_tree(ref, path)
        is_empty = False if tree else True

    if is_empty and not project.repo.is_empty:
        raise TraversalError("Wrong path for tree %s" % path)

    if isinstance(tree, basestring):
        raise TraversalError("Got a blob instead of a tree")

    # Add README code to tree if any
    for item in tree:
        if item["type"] == "blob" and (item["name"] == "README" or item["name"].startswith("README.")):
            readme_content = project.repo.get_file_by_ref("%s:%s" % (ref, item["path"]))
            tdt.update({"readme_content": format_md_or_rst(item["path"], readme_content, project.name)})
            break

    tdt.update({"tree": tree, "tree_path": tree_path, "is_empty": is_empty})
    return st(tmpl_target, **tdt)
コード例 #8
0
ファイル: source.py プロジェクト: jackfrued/code-1
def _get_tmpl_tree(tmpl_target, ref, path, project_name, request):
    project = CodeDoubanProject.get_by_name(project_name)
    if not project:
        raise TraversalError("Wrong path for tree %s" % path)
    if project.is_mirror_project:
        mirror = CodeDoubanMirror.get_by_project_id(project.id)
        if not mirror.is_clone_completed:
            return st('/projects/mirror_cloning.html', **locals())
    if not project.repo:
        raise TraversalError("Wrong path for tree %s" % path)
    if not ref:
        ref = project.default_branch

    tree_path = path.decode('utf-8')
    last_commit = project.repo.get_last_commit(ref, path=path) if ref else ''
    tdt = _tmpl_common_data(ref, path, project_name, request)
    user = tdt['user']
    if user is not None:
        username = user.username
        cur_user_project = project.get_forked_project(username)
        if cur_user_project is not None:
            latest_branch = _latest_update_branch(
                cur_user_project, ref, user)
            if latest_branch:
                cur_user_latest_branch_name = '{0}:{1}'.format(
                    username, latest_branch)
                tdt['latest_update_branch'].append(
                    (cur_user_project, cur_user_latest_branch_name,
                     latest_branch))
    tdt.update({
        'lastcommit': last_commit,
    })

    tree = []
    is_empty = True
    if last_commit:
        tree = project.repo.get_tree(ref, path)
        is_empty = False if tree else True

    if is_empty and not project.repo.is_empty:
        raise TraversalError("Wrong path for tree %s" % path)

    if isinstance(tree, basestring):
        raise TraversalError("Got a blob instead of a tree")

    # Add README code to tree if any
    for item in tree:
        if (item['type'] == 'blob'
            and (item['name'] == 'README'
                 or item['name'].startswith('README.'))):
            readme_content = project.repo.get_file_by_ref(
                "%s:%s" % (ref, item['path'])
            )
            tdt.update({
                'readme_content': format_md_or_rst(item['path'],
                                                   readme_content,
                                                   project.name),
            })
            break

    tdt.update({
        'tree': tree,
        'tree_path': tree_path,
        'is_empty': is_empty,
    })
    return st(tmpl_target, **tdt)
コード例 #9
0
ファイル: project.py プロジェクト: 000fan000/code
 def mirror(self):
     from vilya.models.mirror import CodeDoubanMirror
     mirror = CodeDoubanMirror.get_by_project_id(self.id)
     return mirror if mirror else None
コード例 #10
0
ファイル: project.py プロジェクト: 000fan000/code
 def is_mirror_project(self):
     from vilya.models.mirror import CodeDoubanMirror
     return CodeDoubanMirror.get_by_project_id(self.id) is not None
コード例 #11
0
 def mirror(self):
     from vilya.models.mirror import CodeDoubanMirror
     mirror = CodeDoubanMirror.get_by_project_id(self.id)
     return mirror if mirror else None
コード例 #12
0
 def is_mirror_project(self):
     from vilya.models.mirror import CodeDoubanMirror
     return CodeDoubanMirror.get_by_project_id(self.id) is not None