使用Python/Django更新GitHub

2024-04-16 21:24:55 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我在Django支持的基于web的代码编辑器中为更新GitHub repo而编写的中断代码,请参见https://github.com/DjangoCoder/DjangoGUI/blob/master/projects/views.py第763行。如何重写这段代码才能真正工作?你知道吗

def update_github(request, project_slug):
    print 'UPDATE GITHUB\n' * 100
    project = Project.objects.get(created_by=request.user, slug=project_slug)
    import pexpect
    child = pexpect.spawn('/bin/bash',)
    import sys
    child.logfile = sys.stdout 
    print 'a'
    child.sendline('cd %s' % (project.get_current_directory()))
    print 'b'
    child.sendline('git add *')
    child.sendline('git commit -m "commit"')
    print 'c'
    child.sendline('git push -u origin master')
    print 'd'
    child.sendline('ssgmssgm2')
    print 'e'

    return HttpResponse('')

Tags: 代码importgitgithubmasterprojectchildget