当前位置: 首页>>代码示例>>Python>>正文


Python Repository.is_initialized方法代码示例

本文整理汇总了Python中repository.Repository.is_initialized方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.is_initialized方法的具体用法?Python Repository.is_initialized怎么用?Python Repository.is_initialized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在repository.Repository的用法示例。


在下文中一共展示了Repository.is_initialized方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload_handout

# 需要导入模块: from repository import Repository [as 别名]
# 或者: from repository.Repository import is_initialized [as 别名]
def upload_handout(class_name, local_handout_dir):

    local_handout_dir = os.path.expanduser(local_handout_dir)
    local_handout_dir = os.path.abspath(local_handout_dir)

    handout_name = os.path.basename(local_handout_dir.rstrip('/'))

    if handout_name.count(' ') != 0:
        sys.exit('NO spaces allowed in handout directory')

    if not os.path.isdir(local_handout_dir):
        sys.exit('{0} does not exist'.format(local_handout_dir))

    try:
        config = GraderConfiguration(single_class_name=class_name)
    except ConfigurationError as e:
        sys.exit(e)

    if class_name not in config.students_by_class:
        sys.exit('Class {0} does not exist'.format(class_name))

    remote_handout_repo_basename = handout_name + '.git'
    remote_handout_repo_dir = os.path.join('/home/git', class_name,
                                           remote_handout_repo_basename)

    if directory_exists(remote_handout_repo_dir, ssh=config.ssh):
        sys.exit('{0} already exists on the grader'
                 .format(remote_handout_repo_dir))

    local_handout_repo = Repository(local_handout_dir, handout_name)
    if not local_handout_repo.is_initialized():
        print('Initializing local git repository in {0}'
              .format(local_handout_dir))
        try:
            local_handout_repo.init()
            local_handout_repo.add_all_and_commit('Initial commit')
        except CommandError as e:
            sys.exit('Error initializing local repository:\n{0}'
                     .format(e))
    else:
        print('{0} is already a git repository, it will be pushed'
              .format(local_handout_dir))

    print('Creating a bare repository on the grader at this path:\n{0}'
          .format(remote_handout_repo_dir))

    remote_handout_repo = Repository(remote_handout_repo_dir, handout_name,
                                     is_local=False, is_bare=True,
                                     remote_user=config.username,
                                     remote_host=config.host,
                                     ssh=config.ssh)
    try:
        remote_handout_repo.init()
    except CommandError as e:
        sys.exit('Error initializing remote bare repository:\n{0}'.format(e))

    print('Setting the remote of the local repository')
    try:
        local_handout_repo.set_remote(remote_handout_repo)
    except CommandError as e:
        print('Error setting remote:\n{0}'.format(e))
        print('Set the remote manually if need be')

    print('Pushing local handout to the grader')
    try:
        local_handout_repo.push(remote_handout_repo)
    except CommandError as e:
        sys.exit('Error pushing handout:\n{0}'.format(e))

    email_queue = Queue()
    email_thread = Thread(target=process_email_queue, args=(email_queue,
                                                            class_name,
                                                            config))
    email_thread.start()

    for student in config.students_by_class[class_name]:
        assert isinstance(student, Student)
        clone_url = '{0}@{1}:{2}'.format(student.username, config.host,
                                         remote_handout_repo_dir)
        body = 'Clone URL:\n{0}'.format(clone_url)
        subject = 'New handout: {0}'.format(handout_name)

        email_queue.put(Email(student.email_address, subject, body))

    email_queue.put(None)
    email_thread.join()
开发者ID:sommern,项目名称:git-keeper,代码行数:88,代码来源:upload_handout.py


注:本文中的repository.Repository.is_initialized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。