From 0b2af7bde8f56787c344e429b6a9afbcb68bb1c8 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Mon, 21 Dec 2015 22:36:03 -0800 Subject: [PATCH] Bringing auto-gen import re-writing up to date with files. There were some manual (via `sed` with the command line) edits made for certain gRPC related parts of `*_pb2.py` files that used dispatch tables to map service names onto request/response protobuf types. For example request_deserializers = { ('google.longrunning.Operations', 'CancelOperation'): google.longrunning.operations_pb2.CancelOperationRequest.FromString, ('google.longrunning.Operations', 'DeleteOperation'): google.longrunning.operations_pb2.DeleteOperationRequest.FromString, ('google.longrunning.Operations', 'GetOperation'): google.longrunning.operations_pb2.GetOperationRequest.FromString, ('google.longrunning.Operations', 'ListOperations'): google.longrunning.operations_pb2.ListOperationsRequest.FromString, } needed to be transformed into request_deserializers = { ('google.longrunning.Operations', 'CancelOperation'): gcloud.bigtable._generated.operations_pb2.CancelOperationRequest.FromString, ('google.longrunning.Operations', 'DeleteOperation'): gcloud.bigtable._generated.operations_pb2.DeleteOperationRequest.FromString, ('google.longrunning.Operations', 'GetOperation'): gcloud.bigtable._generated.operations_pb2.GetOperationRequest.FromString, ('google.longrunning.Operations', 'ListOperations'): gcloud.bigtable._generated.operations_pb2.ListOperationsRequest.FromString, } --- scripts/rewrite_imports.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/rewrite_imports.py b/scripts/rewrite_imports.py index 71f83d8b946a..0ed8a310d0ef 100644 --- a/scripts/rewrite_imports.py +++ b/scripts/rewrite_imports.py @@ -49,8 +49,10 @@ def transform_old_to_new(line, old_module, new_module, "from {old_module} import ..." then checks if the line contains "import {old_module} ..." - and finally checks if the line starts with (ignoring whitespace) + then checks if the line starts with (ignoring whitespace) "{old_module} ..." + and finally checks if the line contians + "'some-dict-key': {old_module} ..." In any of these cases, "{old_module}" is replaced with "{new_module}". If none match, nothing is returned. @@ -96,6 +98,11 @@ def transform_old_to_new(line, old_module, new_module, # Only replace the first instance of the old_module. return line.replace(old_module, new_module, 1) + # Finally check for usage in dictionaries. + if ': ' + old_module in line: + # Only replace the first instance of the old_module. + return line.replace(': ' + old_module, ': ' + new_module, 1) + def transform_line(line): """Transforms an import line in a PB2 module.