Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: tools/traffic_annotation/auditor/prepare_protobuf.py

Issue 2448133006: Tool added to extract network traffic annotations. (Closed)
Patch Set: Comments addressed. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/traffic_annotation/auditor/prepare_protobuf.py
diff --git a/tools/traffic_annotation/auditor/prepare_protobuf.py b/tools/traffic_annotation/auditor/prepare_protobuf.py
new file mode 100644
index 0000000000000000000000000000000000000000..6d986aa6c6d14296e5d813dcbf4cdecf2724f038
--- /dev/null
+++ b/tools/traffic_annotation/auditor/prepare_protobuf.py
@@ -0,0 +1,36 @@
+# Copyright (c) 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+""" This code is imported with modifications from
+'//infra/recipes-py/recipe_engine/env.py' to import protobuf from third_party
+directory instead of the one installed with current python libraries."""
+
+import contextlib
+import pkg_resources
+import os
+import sys
+
+
+def PrepareProtobuf():
+ CHROME_SRC = os.path.abspath(
+ os.path.join(os.path.dirname(os.path.realpath(__file__)),
+ "..", "..", ".."))
+ THIRD_PARTY = os.path.join(CHROME_SRC, 'third_party')
+ sys.path.insert(0, os.path.join(THIRD_PARTY, 'protobuf', 'python'))
+ sys.path.insert(
+ 1, os.path.join(THIRD_PARTY, 'protobuf', 'third_party', 'six'))
+
+ @contextlib.contextmanager
+ def temp_sys_path():
+ orig_path = sys.path[:]
+ try:
+ yield
+ finally:
+ sys.path = orig_path
+
+ with temp_sys_path():
+ sys.path = [THIRD_PARTY]
+ sys.modules.pop('google', None)
+ pkg_resources.declare_namespace('google')
+ pkg_resources.fixup_namespace_packages(THIRD_PARTY)
« no previous file with comments | « tools/traffic_annotation/auditor/README.md ('k') | tools/traffic_annotation/auditor/traffic_annotation_auditor.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698