File: protoc

package info (click to toggle)
nanopb 0.4.9.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,676 kB
  • sloc: ansic: 12,144; python: 2,795; cpp: 190; sh: 163; makefile: 85
file content (45 lines) | stat: -rwxr-xr-x 1,577 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
# This file acts as a drop-in replacement of binary protoc.exe.
# It will use either Python-based protoc from grpcio-tools package,
# or if it is not available, protoc.exe from path if found.

import sys
import os
import os.path

# Depending on how this script is run, we may or may not have PEP366 package name
# available for relative imports.
if not __package__:
    from proto._utils import invoke_protoc
else:
    from .proto._utils import invoke_protoc

if __name__ == '__main__':
    # Get path of the directory where this script is stored.
    if getattr(sys, 'frozen', False):
        mypath = os.path.dirname(sys.executable) # For pyInstaller
    else:
        mypath = os.path.dirname(__file__)

    # Avoid recursive calls to self
    env_paths = os.environ["PATH"].split(os.pathsep)
    if mypath in env_paths:
        env_paths.remove(mypath)
        os.environ["PATH"] = os.pathsep.join(env_paths)

    # Add argument for finding the nanopb generator when using --nanopb_out=
    # argument to protoc.
    if os.path.isfile(os.path.join(mypath, "protoc-gen-nanopb.exe")):
        protoc_gen_nanopb = os.path.join(mypath, "protoc-gen-nanopb.exe")
    elif os.name == 'nt':
        protoc_gen_nanopb = os.path.join(mypath, "protoc-gen-nanopb.bat")
    else:
        protoc_gen_nanopb = os.path.join(mypath, "protoc-gen-nanopb")

    args = sys.argv[1:]

    if os.path.isfile(protoc_gen_nanopb):
         args = ['--plugin=protoc-gen-nanopb=%s' % protoc_gen_nanopb] + args

    status = invoke_protoc(['protoc'] + args)
    sys.exit(status)