Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 2 | |
| 3 | # Copyright 2017-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Scott Baker | 96b995a | 2017-02-15 16:21:12 -0800 | [diff] [blame] | 17 | import os |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 18 | from setuptools.command.install import install |
| 19 | |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 20 | try: |
| 21 | from xosutil.autoversion_setup import setup_with_auto_version as setup |
| 22 | except ImportError: |
| 23 | # xosutil is not installed. Expect this to happen when we build an egg, in which case xosgenx.version will |
| 24 | # automatically have the right version. |
| 25 | from setuptools import setup |
| 26 | |
| 27 | from xosapi.version import __version__ |
Scott Baker | 96b995a | 2017-02-15 16:21:12 -0800 | [diff] [blame] | 28 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 29 | CHAMELEON_DIR = "xosapi/chameleon" |
Scott Baker | 96b995a | 2017-02-15 16:21:12 -0800 | [diff] [blame] | 30 | |
| 31 | if not os.path.exists(CHAMELEON_DIR): |
| 32 | raise Exception("%s does not exist!" % CHAMELEON_DIR) |
| 33 | |
| 34 | if not os.path.exists(os.path.join(CHAMELEON_DIR, "protos/schema_pb2.py")): |
| 35 | raise Exception("Please make the chameleon protos") |
| 36 | |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 37 | # Chameleon requires these files have executable permission set. |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 38 | |
| 39 | |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 40 | class InstallFixChameleonPermissions(install): |
| 41 | def run(self): |
| 42 | install.run(self) |
| 43 | for filepath in self.get_outputs(): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 44 | if filepath.endswith( |
| 45 | "chameleon/protoc_plugins/gw_gen.py" |
| 46 | ) or filepath.endswith("chameleon/protoc_plugins/swagger_gen.py"): |
| 47 | os.chmod(filepath, 0o777) |
Scott Baker | 96b995a | 2017-02-15 16:21:12 -0800 | [diff] [blame] | 48 | |
Scott Baker | 96b995a | 2017-02-15 16:21:12 -0800 | [diff] [blame] | 49 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 50 | setup_result = setup( |
| 51 | name="xosapi", |
| 52 | version=__version__, |
| 53 | cmdclass={"install": InstallFixChameleonPermissions}, |
| 54 | description="XOS api client", |
| 55 | package_dir={"xosapi.chameleon": CHAMELEON_DIR}, |
| 56 | packages=[ |
| 57 | "xosapi.chameleon.grpc_client", |
| 58 | "xosapi.chameleon.protos", |
| 59 | "xosapi.chameleon.utils", |
| 60 | "xosapi.chameleon.protoc_plugins", |
| 61 | "xosapi", |
| 62 | "xosapi.convenience", |
| 63 | ], |
| 64 | py_modules=["xosapi.chameleon.__init__"], |
| 65 | include_package_data=True, |
| 66 | package_data={ |
| 67 | "xosapi.chameleon.protos": ["*.proto"], |
| 68 | "xosapi.chameleon.protoc_plugins": ["*.desc"], |
| 69 | }, |
| 70 | scripts=["xossh"], |
| 71 | ) |