本文整理匯總了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()