#coding utf8 #!/usr/bin/python import os import sys import time import threading import subprocess g_is_terminated = False def is_terminated(): return g_is_terminated def printp_stdout(p): try: while not is_terminated(): line = p.stdout.readline() if len(line) > 0: print(line, end = '') except Exception as e: print('build_pb stdout error:' + str(e)) def printp_stderr(p): try: while is_terminated(): line = p.stderr.readline() if len(line) > 0: print(line, end = '') except Exception as e: print('build_pb stderr error:' + str(e)) def need_rebuild(): for proto_name in ('ss_proto', 'ss_msgid'): if not os.path.isfile(proto_name + '.pb.cc'): return True s1 = os.stat(proto_name + '.pb.cc') s2 = os.stat('../tools/protobuild/' + proto_name + '.proto') if s1.st_mtime < s2.st_mtime: return True return False def rebuild(): global g_is_terminated try: p = subprocess.Popen( 'protoc --proto_path=../tools/protobuild --cpp_out=../dbproxy ../tools/protobuild/ss_proto.proto && ' + 'protoc --proto_path=../tools/protobuild --cpp_out=../dbproxy ../tools/protobuild/ss_msgid.proto ', stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = None, shell = True) t1 = threading.Thread(target = printp_stdout, args=(p, )) t2 = threading.Thread(target = printp_stderr, args=(p, )) t1.start() t2.start() p.wait() g_is_terminated = True t1.join() t2.join() sys.exit(p.returncode) except Exception as e: print('build_protocol rebuild error:' + str(e)) def repair_githooks(): os.system('/bin/bash ../tools/scripts/githooks/install.sh') repair_githooks() if need_rebuild(): rebuild() else: print('pb files already is the latest')