[Answer]-Django wsgi + Popen + svn checkout

1👍

ok, after struggled for another 3 hours today. I have finally solved the problem.

Here is what’s going on, the wsgi & popen are actually fine, the real problem is some source code files for check out actually has special characters and that break the svn check out process (with the following error)

svn: Can’t convert string from ‘UTF-8’ to native encoding

The wsgi and console have different value for LC_LANG, and that explains the different behaviours between runserver and wsgi.

finally, I solved the problem by modifying the file of ‘/etc/apache2/envars’ and uncommented the following line:

. /etc/default/locale

Note that you have to restart the server by ‘apache2ctl stop’ and ‘apache2ctl start’, instead of ‘apache2ctl restart’, in order to have the setting to be effective.

I actually used pexpect to find out the problem, but reverted back to Popen later because obvious latency problem.

Here is my final code for the run_cmd, and hopefully it could help someone else in the future:

def run_cmd(argument_list, output_file = None):
    print "arguments", argument_list


    #command = " ".join(argument_list)
    #content = pexpect.run(command)
    #if output_file:
        #fout = file(output_file, "w")
        #fout.write(content)
        #fout.close
    #return content

    p = subprocess.Popen(argument_list, bufsize=50, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) #showed error message as well

    content = ""
    while True:
        line = p.stdout.read(50)

        if not line:
            break

        content += line

    #raise Exception(content)   #for debug

    if output_file:
        fout = file(output_file, "w")
        fout.write(content)
        fout.close()

    return content

Leave a comment