| LEFT | RIGHT | 
|   1 #!/usr/bin/env python |   1 #!/usr/bin/env python | 
|   2 # coding: utf-8 |   2 # coding: utf-8 | 
|   3  |   3  | 
|   4 import os, sys, subprocess, tempfile; |   4 import os, sys, subprocess, tempfile; | 
|   5 baseDir = os.path.abspath(os.path.dirname(__file__)) |   5 baseDir = os.path.abspath(os.path.dirname(__file__)) | 
|   6  |   6  | 
|   7 def check_curl(): |   7 def check_curl(): | 
|   8   (fd, name) = tempfile.mkstemp(dir=os.path.join(baseDir, 'build'), suffix='.h') |   8   buildDir = os.path.join(baseDir, 'build') | 
 |   9   if not os.path.exists(buildDir): | 
 |  10     os.makedirs(buildDir); | 
 |  11   (fd, name) = tempfile.mkstemp(dir=buildDir, suffix='.h') | 
|   9   try: |  12   try: | 
|  10     handle = os.fdopen(fd, 'wb'); |  13     handle = os.fdopen(fd, 'wb'); | 
|  11     handle.write('#include <curl/curl.h>') |  14     handle.write('#include <curl/curl.h>') | 
|  12     handle.close(); |  15     handle.close(); | 
|  13  |  16  | 
|  14     # This command won't work for Windows or Android build environments but we |  17     # This command won't work for Windows or Android build environments but we | 
|  15     # don't want to use curl there anyway |  18     # don't want to use curl there anyway | 
|  16     command = ['/usr/bin/env', 'gcc', '-E', name]; |  19     command = ['/usr/bin/env', 'gcc', '-E', name]; | 
|  17     process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subproces
    s.PIPE) |  20     process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subproces
    s.PIPE) | 
|  18     process.communicate() |  21     process.communicate() | 
|  19  |  22  | 
|  20     if process.returncode: |  23     if process.returncode: | 
|  21       # call failed, curl not available |  24       # call failed, curl not available | 
|  22       sys.stdout.write('0') |  25       sys.stdout.write('0') | 
|  23     else: |  26     else: | 
|  24       # call succeeded, curl can be used |  27       # call succeeded, curl can be used | 
|  25       sys.stdout.write('1') |  28       sys.stdout.write('1') | 
|  26   finally: |  29   finally: | 
|  27     os.remove(name) |  30     os.remove(name) | 
|  28  |  31  | 
|  29 if __name__ == '__main__': |  32 if __name__ == '__main__': | 
|  30   check_curl() |  33   check_curl() | 
| LEFT | RIGHT |