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

Unified Diff: tools/telemetry/refactor.py

Issue 1132103009: Example of refactoring using rope library. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « tools/telemetry/.ropeproject/config.py ('k') | tools/telemetry/telemetry/internal/story_runner.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/refactor.py
diff --git a/tools/telemetry/refactor.py b/tools/telemetry/refactor.py
new file mode 100644
index 0000000000000000000000000000000000000000..405dd384c3047ff1f1900b3f79f85e7566476737
--- /dev/null
+++ b/tools/telemetry/refactor.py
@@ -0,0 +1,27 @@
+import os
+
+from telemetry.core import util
+
+util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'rope')
+
+from rope.refactor import rename
+import rope.base.project
+
+
+telemetry_path = os.path.dirname(__file__)
+telemetry_project = rope.base.project.Project(telemetry_path)
+
+
+def Rename(resource, offset, new_name):
+ changes = rename.Rename(
+ telemetry_project, resource, offset).get_changes(new_name)
+ print changes.get_description()
+ telemetry_project.do(changes)
+
+user_story_file_path = os.path.join(
+ 'telemetry', 'internal', 'story_runner.py')
+
+user_story_code = telemetry_project.get_resource(user_story_file_path)
+Rename(user_story_code,
+ user_story_code.read().index('def StoriesGroupedByStateClass') + 4,
+ 'StoriesByStateClass')
« no previous file with comments | « tools/telemetry/.ropeproject/config.py ('k') | tools/telemetry/telemetry/internal/story_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698