|
|
Chromium Code Reviews|
Created:
7 years, 10 months ago by blois Modified:
7 years, 9 months ago CC:
reviews_dartlang.org Visibility:
Public. |
DescriptionAdding helper script to make it easy to run common DOM tasks.
I'm not much of a python person, so there's probably cleaner ways of doing some of this. It's primarily a script that I've been using locally for quite a while, but seems like it'd be useful for others as well.
It's not intended to cover every single scenario, just make the common ones easy. It prints out the commands it executes so if there is a problem, hopefully you can easily debug it.
BUG=
Committed: https://code.google.com/p/dart/source/detail?r=19648
Patch Set 1 : #
Total comments: 19
Patch Set 2 : #
Total comments: 1
Messages
Total messages: 10 (0 generated)
lgtm
Cool! Mostly nits. https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py File tools/dom/dom.py (right): https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode3 tools/dom/dom.py:3: # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2013 :-) https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode13 tools/dom/dom.py:13: import glob nit: alphabetize imports https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode15 tools/dom/dom.py:15: dart_out_dir = 'out/ReleaseIA32/' 'out' is 'xcodebuild' on the Mac. I think most of the dom scripts have worked on the mac. Also, os.path.join instead of '/'? https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode21 tools/dom/dom.py:21: def process(self, argv): You might consider the optparse python module for args. I think most of our python scripts (dom or otherwise) use it.
various DBCs https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py File tools/dom/dom.py (right): https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode19 tools/dom/dom.py:19: argv = [] this is not necessary and does slightly different thing than you might expect. overall, why do you need a class in the first place? https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode31 tools/dom/dom.py:31: if not hasattr(self, command): I'd rather have an explicit map 'command name' : function and used a patter like: COMMANDS.get(commandName, help)() which returns help function is there is no mapping for commandName https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode40 tools/dom/dom.py:40: if not attr in privates and not attr.startswith('__'): map will help here too
https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py File tools/dom/dom.py (right): https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode15 tools/dom/dom.py:15: dart_out_dir = 'out/ReleaseIA32/' On 2013/02/05 20:29:24, vsm wrote: > 'out' is 'xcodebuild' on the Mac. I think most of the dom scripts have worked > on the mac. Also, os.path.join instead of '/'? and 'out' is called 'build' on Windows. the file in tools/utils.py has a function called GetBuildDir that can be used for just this purpose. https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode16 tools/dom/dom.py:16: dart_bin = os.path.join(dart_out_dir, 'dart') same here ... on Windows it's dart.exe see the function DartBinary in tools/utils.py https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode21 tools/dom/dom.py:21: def process(self, argv): On 2013/02/05 20:29:24, vsm wrote: > You might consider the optparse python module for args. I think most of our > python scripts (dom or otherwise) use it. +1 Then you won't need to to add the logic for help() -- argparse/optparse will do that for you.
Thanks for the feedback all! Updated with a bunch of cleanup, should now support other platforms as well. This was just a script that I cobbled together with random commands over time to help automate common tasks, so it's not intended to replace anything, but hopefully folks find it useful. https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py File tools/dom/dom.py (right): https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode3 tools/dom/dom.py:3: # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file On 2013/02/05 20:29:24, vsm wrote: > 2013 :-) Done. https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode13 tools/dom/dom.py:13: import glob On 2013/02/05 20:29:24, vsm wrote: > nit: alphabetize imports Done. https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode15 tools/dom/dom.py:15: dart_out_dir = 'out/ReleaseIA32/' On 2013/02/06 18:36:14, Emily Fortuna wrote: > On 2013/02/05 20:29:24, vsm wrote: > > 'out' is 'xcodebuild' on the Mac. I think most of the dom scripts have worked > > on the mac. Also, os.path.join instead of '/'? > > and 'out' is called 'build' on Windows. the file in tools/utils.py has a > function called GetBuildDir that can be used for just this purpose. Done. https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode16 tools/dom/dom.py:16: dart_bin = os.path.join(dart_out_dir, 'dart') On 2013/02/06 18:36:14, Emily Fortuna wrote: > same here ... on Windows it's dart.exe see the function DartBinary in > tools/utils.py Done. https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode19 tools/dom/dom.py:19: argv = [] On 2013/02/06 11:52:28, Anton Muhin wrote: > this is not necessary and does slightly different thing than you might expect. > overall, why do you need a class in the first place? Done. https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode21 tools/dom/dom.py:21: def process(self, argv): On 2013/02/06 18:36:14, Emily Fortuna wrote: > On 2013/02/05 20:29:24, vsm wrote: > > You might consider the optparse python module for args. I think most of our > > python scripts (dom or otherwise) use it. > > +1 Then you won't need to to add the logic for help() -- argparse/optparse will > do that for you. From what I can tell, opt parse primarily handles flags, where the primary case here is passing a series of commands. for instance, I commonly run: dom.py gen test_drt html/element_test or: dom.py analyze test_drt html From what I can tell, optparse doesn't really help for non-flags, but I really wanted to eliminate all flags and just have chaining of common commands. https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode31 tools/dom/dom.py:31: if not hasattr(self, command): On 2013/02/06 11:52:28, Anton Muhin wrote: > I'd rather have an explicit map 'command name' : function and used a patter > like: > > COMMANDS.get(commandName, help)() > > which returns help function is there is no mapping for commandName Done. https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode40 tools/dom/dom.py:40: if not attr in privates and not attr.startswith('__'): On 2013/02/06 11:52:28, Anton Muhin wrote: > map will help here too Done.
https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py File tools/dom/dom.py (right): https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode21 tools/dom/dom.py:21: def process(self, argv): On 2013/02/06 22:36:27, blois wrote: > On 2013/02/06 18:36:14, Emily Fortuna wrote: > > On 2013/02/05 20:29:24, vsm wrote: > > > You might consider the optparse python module for args. I think most of our > > > python scripts (dom or otherwise) use it. > > > > +1 Then you won't need to to add the logic for help() -- argparse/optparse > will > > do that for you. > > From what I can tell, opt parse primarily handles flags, where the primary case > here is passing a series of commands. > > for instance, I commonly run: > dom.py gen test_drt html/element_test > > or: > dom.py analyze test_drt html > > From what I can tell, optparse doesn't really help for non-flags, but I really > wanted to eliminate all flags and just have chaining of common commands. Gotcha. Argparse is just what you want then, but it only works for Python 2.7, and our bots are running 2.6. Sigh. https://codereview.chromium.org/12211019/diff/7001/tools/dom/dom.py File tools/dom/dom.py (right): https://codereview.chromium.org/12211019/diff/7001/tools/dom/dom.py#newcode7 tools/dom/dom.py:7: # A script which makes it easy to execute common DOM-related tasks Can you write a few brief usage examples here like you did in this comment https://codereview.chromium.org/12211019/diff/3/tools/dom/dom.py#newcode21 explaining some common use cases?
lgtm Ping?
On 2013/03/07 00:59:31, Andrei Mouravski wrote: > lgtm > > Ping? Adding http_server command to kick off the testing server for manual testing & committing. Will be happy to continue to tweak.
Message was sent while issue was closed.
Committed patchset #2 manually as r19648 (presubmit successful). |
