Created
September 13, 2017 03:33
-
-
Save snower/71375e62937652dfb972d4bb4b831e21 to your computer and use it in GitHub Desktop.
build python to bin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# 15/10/29 | |
# create by: snower | |
import sys | |
import os | |
import shlex | |
import subprocess | |
def run_command(command): | |
print command | |
args = shlex.split(command) | |
p = subprocess.Popen(args) | |
p.wait() | |
def build_path(path): | |
for file in os.listdir(path): | |
if file[0] == ".": | |
continue | |
filename = path + os.sep + file | |
if os.path.isfile(filename): | |
if not file.endswith(".py") or file in ("__init__.py", "main.py", "build.py"): | |
continue | |
basefile = filename[:-3] | |
if os.path.isfile("%s.so" % basefile): | |
run_command("rm -rf %s.so" % basefile) | |
run_command("cython -o %s.c %s" % (basefile, filename)) | |
run_command("gcc -fPIC -I/opt/python/include/python2.7 -c -o %s.o %s.c" % (basefile, basefile)) | |
if os.path.isfile("%s.o" % basefile): | |
run_command("rm -rf %s.c" % basefile) | |
run_command("gcc -shared -o %s.so %s.o" % (basefile, basefile)) | |
if os.path.isfile("%s.so" % basefile): | |
run_command("rm -rf %s.o" % basefile) | |
run_command("rm -rf %s" % filename) | |
if os.path.isfile(filename + "c"): | |
run_command("rm -rf %sc" % filename) | |
elif os.path.isdir(filename): | |
if file in ("settings", "tornado"): | |
continue | |
build_path(os.path.abspath(filename)) | |
if __name__ == "__main__": | |
if len(sys.argv) > 1: | |
build_path(os.path.abspath(sys.argv[1])) | |
else: | |
build_path(os.path.abspath(".")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment