huangcm
2025-04-10 8644e82af5b4eb3e67a2ea2bb22ff60db6f7c2ce
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
#
# Copyright 2018 - The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
 
from distutils.spawn import find_executable
import os
import subprocess
import sys
 
import setuptools
 
ACLOUD_DIR = os.path.realpath(os.path.dirname(__file__))
 
try:
    with open("README.md", "r") as fh:
        LONG_DESCRIPTION = fh.read()
except IOError:
    LONG_DESCRIPTION = ""
 
# Find the Protocol Compiler. (Taken from protobuf/python/setup.py)
if "PROTOC" in os.environ and os.path.exists(os.environ["PROTOC"]):
    PROTOC = os.environ["PROTOC"]
else:
    PROTOC = find_executable("protoc")
 
 
def generate_proto(source):
    """Generate a _pb2.py from a .proto file.
 
    Invokes the Protocol Compiler to generate a _pb2.py from the given
    .proto file.  Does nothing if the output already exists and is newer than
    the input.
 
    Args:
      source: The source proto file that needs to be compiled.
    """
 
    output = source.replace(".proto", "_pb2.py")
 
    if (not os.path.exists(output) or (os.path.exists(source) and
                                       os.path.getmtime(source) > os.path.getmtime(output))):
        print "Generating %s..." % output
 
        if not os.path.exists(source):
            sys.stderr.write("Can't find required file: %s\n" % source)
            sys.exit(-1)
 
        if PROTOC is None:
            sys.stderr.write(
                "protoc is not found.  Please compile it "
                "or install the binary package.\n")
            sys.exit(-1)
 
        protoc_command = [PROTOC,  "-I%s" % ACLOUD_DIR, "--python_out=.", source]
        if subprocess.call(protoc_command) != 0:
            sys.exit(-1)
 
 
# Generate the protobuf files that we depend on.
generate_proto(os.path.join(ACLOUD_DIR, "internal/proto/user_config.proto"))
generate_proto(os.path.join(ACLOUD_DIR, "internal/proto/internal_config.proto"))
open(os.path.join(ACLOUD_DIR, "internal/proto/__init__.py"), "a").close()
 
setuptools.setup(
    python_requires=">=2",
    name="acloud",
    version="1.0",
    test_suite="nose.collector",
    tests_require=["coverage", "mock"],
    author="Kevin Cheng, Keun Soo Yim",
    author_email="kevcheng@google.com, yim@google.com",
    description="Acloud is a command line tool that assists users to "
                "create an Android Virtual Device (AVD).",
    long_description=LONG_DESCRIPTION,
    long_description_content_type="text/markdown",
    packages=[
        "acloud", "acloud.internal", "acloud.public", "acloud.delete",
        "acloud.create", "acloud.setup", "acloud.metrics",
        "acloud.internal.lib", "acloud.internal.proto", "acloud.public.data",
        "acloud.public.acloud_kernel", "acloud.public.actions", "acloud.reconnect",
        "acloud.list",
    ],
    package_dir={
        "acloud": ".",
        "acloud.internal": "internal",
        "acloud.public": "public",
        "acloud.delete": "delete",
        "acloud.create": "create",
        "acloud.setup": "setup",
        "acloud.metrics": "metrics",
        "acloud.internal.lib": "internal/lib",
        "acloud.internal.proto": "internal/proto",
        "acloud.public.data": "public/data",
        "acloud.public.acloud_kernel": "public/acloud_kernel",
        "acloud.public.actions": "public/actions",
        "acloud.reconnect": "reconnect",
        "acloud.list": "list"
    },
    package_data={"acloud.public.data": ["default.config"]},
    include_package_data=True,
    platforms="POSIX",
    entry_points={
        "console_scripts": ["acloud=acloud.public.acloud_main:main"],
    },
    install_requires=[
        "google-api-python-client", "oauth2client==3.0.0", "protobuf",
        "python-dateutil"
    ],
    license="Apache License, Version 2.0",
    classifiers=[
        "Programming Language :: Python :: 2",
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: Apache Software License",
        "Natural Language :: English",
        "Environment :: Console",
        "Intended Audience :: Developers",
        "Topic :: Utilities",
    ])