12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ # Instructions:
16
+ #
17
+ # Find the artman config file the describes the API you want to generate a client for.
18
+ #
19
+ # $ python utilities/generate_api.py PATH_TO_ARTMAN_CONFIG_FILE
20
+
15
21
import argparse
16
22
import io
17
23
import os
21
27
from distutils import dir_util
22
28
from ruamel import yaml
23
29
24
- def run (config_path ):
25
- api_dir_index = config_path .find ('/google/' )
26
- if api_dir_index == - 1 :
27
- raise ValueError ('Didn\' t find /google/ in config file path; need absolute path to the artman config file.' )
28
- root_dir = config_path [0 :api_dir_index ]
29
- api_dir = config_path [api_dir_index + 1 :]
30
30
31
- subprocess .check_call (['artman' , '--config' , api_dir , '--local' , '-v' , '--root-dir' , root_dir , 'generate' , 'java_gapic' ])
31
+ dir_overrides = {
32
+ 'bigtable-admin' : 'google-cloud-bigtable' ,
33
+ 'error-reporting' : 'google-cloud-errorreporting' ,
34
+ 'spanner-admin-instance' : 'google-cloud-spanner' ,
35
+ 'spanner-admin-database' : 'google-cloud-spanner'
36
+ }
37
+
38
+
39
+ def run_generate_api (config_path , noisy = False ):
40
+ googleapis_index = config_path .rfind ('/google/' )
41
+ if googleapis_index == - 1 :
42
+ raise ValueError ('Didn\' t find /googleapis/ in config file path; need absolute path to the artman config file.' )
43
+ root_dir = config_path [0 :googleapis_index ]
44
+ api_dir = config_path [googleapis_index + 1 :]
45
+
46
+ extra_options = []
47
+ if noisy :
48
+ extra_options = ['-v' ]
49
+
50
+ subprocess .check_call (['artman' , '--config' , api_dir , '--local' , '--root-dir' , root_dir ] + extra_options + ['generate' , 'java_gapic' ])
32
51
33
52
with io .open (config_path , encoding = 'UTF-8' ) as config_file :
34
53
artman_config_data = yaml .load (config_file , Loader = yaml .Loader )
@@ -44,9 +63,6 @@ def run(config_path):
44
63
proto_dir = os .path .join ('artman-genfiles' , 'java' , proto_dirname )
45
64
grpc_dir = os .path .join ('artman-genfiles' , 'java' , grpc_dirname )
46
65
gapic_dir = os .path .join ('artman-genfiles' , 'java' , gapic_dirname )
47
- print (proto_dir )
48
- print (grpc_dir )
49
- print (gapic_dir )
50
66
if not os .path .exists (proto_dir ):
51
67
raise ValueError ('generated proto dir doesn\' t exist: {}' .format (proto_dir ))
52
68
if not os .path .exists (grpc_dir ):
@@ -78,24 +94,30 @@ def run(config_path):
78
94
subprocess .call (['git' , 'checkout' , os .path .join (target_grpc_dir , 'pom.xml' )])
79
95
80
96
api_unversioned_name = '{}-{}' .format (org_name , api_name )
97
+ if api_name in dir_overrides :
98
+ api_unversioned_name = dir_overrides [api_name ]
99
+
81
100
target_gapic_dir = os .path .join ('google-cloud-clients' , api_unversioned_name )
82
101
dir_util .copy_tree (os .path .join (gapic_dir , 'src' ), os .path .join (target_gapic_dir , 'src' ))
83
102
84
- print ('**** REMAINING MANUAL WORK: *****' )
85
- print ('This script doesn\' t set up new clients. If this is a new client, you need to:' )
86
- print ('1. Add the new proto and grpc modules into google-api-grpc/pom.xml' )
87
- print ('3. Copy an existing client pom.xml to the new client directory, update its text' )
88
- print ('4. Copy an existing client README.md to the new client directory, update its text' )
89
- print ('5. Add the new proto, grpc, and client modules into versions.txt' )
90
- print ('6. Add the new proto, grpc, and client modules into google-cloud-bom/pom.xml' )
91
- print ('7. Run `utilities/replace_versions.py` to update the module versions' )
103
+ if noisy :
104
+ print ('**** REMAINING MANUAL WORK: *****' )
105
+ print ('This script doesn\' t set up new clients. If this is a new client, you need to:' )
106
+ print ('1. Add the new proto and grpc modules into google-api-grpc/pom.xml' )
107
+ print ('3. Copy an existing client pom.xml to the new client directory, update its text' )
108
+ print ('4. Copy an existing client README.md to the new client directory, update its text' )
109
+ print ('5. Add the new proto, grpc, and client modules into versions.txt' )
110
+ print ('6. Add the new proto, grpc, and client modules into google-cloud-bom/pom.xml' )
111
+ print ('7. Run `utilities/replace_versions.py` to update the module versions' )
92
112
93
113
def main ():
94
114
parser = argparse .ArgumentParser (description = 'Regenerate a single API.' )
95
115
parser .add_argument ('config_file' , help = 'The artman config file for the API' )
116
+ parser .add_argument ('--quiet' , action = "store_true" , default = False ,
117
+ help = 'Don\' t print informational instructions' )
96
118
args = parser .parse_args ()
97
119
98
- run (args .config_file )
120
+ run_generate_api (args .config_file , not args . quiet )
99
121
100
122
if __name__ == '__main__' :
101
123
main ()
0 commit comments