1#!/usr/bin/env python3 2 3import sys 4import os 5import os.path 6from nanopb_generator import invoke_protoc 7 8if __name__ == '__main__': 9 # Add argument so that protoc-gen-nanopb gets found 10 if getattr(sys, 'frozen', False): 11 mypath = os.path.dirname(sys.executable) # For pyInstaller 12 else: 13 mypath = os.path.dirname(__file__) 14 15 if os.path.isfile(os.path.join(mypath, "protoc-gen-nanopb.exe")): 16 protoc_gen_nanopb = os.path.join(mypath, "protoc-gen-nanopb.exe") 17 elif os.name == 'nt': 18 protoc_gen_nanopb = os.path.join(mypath, "protoc-gen-nanopb.bat") 19 else: 20 protoc_gen_nanopb = os.path.join(mypath, "protoc-gen-nanopb") 21 22 args = sys.argv[1:] 23 24 if os.path.isfile(protoc_gen_nanopb): 25 args = ['--plugin=protoc-gen-nanopb=%s' % protoc_gen_nanopb] + args 26 27 status = invoke_protoc(['protoc'] + args) 28 sys.exit(status) 29