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

Issue 6250058: Split out the big chromite shell 'main.py' into lots of subfiles. (Closed)

Created:
9 years, 10 months ago by diandersAtChromium
Modified:
9 years, 6 months ago
Reviewers:
davidjames, sosa
CC:
anush, chromium-os-reviews_chromium.org
Visibility:
Public.

Description

Split out the big chromite shell 'main.py' into lots of subfiles. Main focus for review should be organization / naming. Make sure those are OK. Since this is hard to follow, a high-level description of things that happened here: 1. Almost everything moved out of 'main.py'. The 'utils.py' became a bit of a dumping ground (for now) for functions needed by multiple modules. 2. All subcommands went into the 'subcmds' folder. Mostly I have one command per file, except for the portage commands (which are all wrappers). 3. To make mox work better, we now import cros_build_lib directly (as cros_lib). Now, we can mox out cros_lib.Die. 4. Cleaned up how the "--resume-state" gets handled for EnterChroot. It's now abstracted into its own function (so that it can be in the same file as EnterChroot). 5. Moved 'WrappedChrootCmd' into subcmd.py. 6. (Minor) Hack sys.argv[0] as 'chromite' so that help commands look better. Change-Id: I19aad2a437864d364f4df70236ab84bfeba35376 BUG=chromium-os:10556 TEST=Ran unit tests; built mario; tried shell; tried workon command. Committed: http://chrome-svn/viewvc/chromeos?view=rev&revision=a9b1090

Patch Set 1 #

Total comments: 33

Patch Set 2 : Incorporated davidjames and sosa feedback. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1110 lines, -980 lines) Patch
M shell/main.py View 1 8 chunks +40 lines, -958 lines 0 comments Download
M shell/main_unittest.py View 1 14 chunks +24 lines, -22 lines 0 comments Download
M shell/subcmd.py View 1 2 chunks +99 lines, -1 line 0 comments Download
A shell/subcmds/__init__.py View 0 chunks +-1 lines, --1 lines 0 comments Download
A shell/subcmds/build_cmd.py View 1 1 chunk +200 lines, -0 lines 0 comments Download
A shell/subcmds/clean_cmd.py View 1 1 chunk +140 lines, -0 lines 0 comments Download
A shell/subcmds/portage_cmds.py View 1 1 chunk +56 lines, -0 lines 0 comments Download
A shell/subcmds/shell_cmd.py View 1 1 chunk +124 lines, -0 lines 0 comments Download
A shell/subcmds/workon_cmd.py View 1 1 chunk +42 lines, -0 lines 0 comments Download
A shell/utils.py View 1 1 chunk +386 lines, -0 lines 0 comments Download

Messages

Total messages: 4 (0 generated)
diandersAtChromium
PTAL. See CL comments above for details.
9 years, 10 months ago (2011-01-31 22:40:50 UTC) #1
davidjames
LGTM w/nits http://codereview.chromium.org/6250058/diff/1/shell/main.py File shell/main.py (right): http://codereview.chromium.org/6250058/diff/1/shell/main.py#newcode39 shell/main.py:39: for cls in _COMMAND_HANDLERS ] No need ...
9 years, 10 months ago (2011-02-02 01:15:18 UTC) #2
sosa
Mostly nits Your refactor got a lot of > 80 chars lines http://codereview.chromium.org/6250058/diff/1/shell/main.py File shell/main.py ...
9 years, 10 months ago (2011-02-02 01:16:19 UTC) #3
diandersAtChromium
9 years, 10 months ago (2011-02-02 01:49:10 UTC) #4
Got a verbal that sosa's review was 'LGTM w/ nits'.  I've fixed all nits and
will push.

http://codereview.chromium.org/6250058/diff/1/shell/main.py
File shell/main.py (right):

http://codereview.chromium.org/6250058/diff/1/shell/main.py#newcode16
shell/main.py:16: from chromite.lib import cros_build_lib as cros_lib
On 2011/02/02 01:16:19, sosa wrote:
> might be cleaner if you did:
> 
> import chromite.lib.cros_build_lib as cros_lib

Done.

http://codereview.chromium.org/6250058/diff/1/shell/main.py#newcode39
shell/main.py:39: for cls in _COMMAND_HANDLERS      ]
On 2011/02/02 01:15:18, davidjames wrote:
> No need for extra spaces at the end here.

Done.

http://codereview.chromium.org/6250058/diff/1/shell/main.py#newcode104
shell/main.py:104: sys.argv[0] = 'chromite'
On 2011/02/02 01:15:18, davidjames wrote:
> Can you add a TODO to remove this hack? We discussed a few solutions in person
> that might be cleaner, so feel free to add your favorite one to the comment.
> 

Done.

http://codereview.chromium.org/6250058/diff/1/shell/main.py#newcode177
shell/main.py:177: cmd_cls = _COMMAND_HANDLERS[_COMMAND_STRS.index(cmd_str)]
On 2011/02/02 01:15:18, davidjames wrote:
> Thank you! No eval please :)

Done.

http://codereview.chromium.org/6250058/diff/1/shell/subcmd.py
File shell/subcmd.py (right):

http://codereview.chromium.org/6250058/diff/1/shell/subcmd.py#newcode11
shell/subcmd.py:11: 
On 2011/02/02 01:16:19, sosa wrote:
> Don't need dbl lines here

Done.

http://codereview.chromium.org/6250058/diff/1/shell/subcmds/build_cmd.py
File shell/subcmds/build_cmd.py (right):

http://codereview.chromium.org/6250058/diff/1/shell/subcmds/build_cmd.py#newc...
shell/subcmds/build_cmd.py:1: #!/usr/bin/python
On 2011/02/02 01:16:19, sosa wrote:
> Only directly shell-callable python should have this up top (i.e main /
> unittests)

Done.

http://codereview.chromium.org/6250058/diff/1/shell/subcmds/clean_cmd.py
File shell/subcmds/clean_cmd.py (right):

http://codereview.chromium.org/6250058/diff/1/shell/subcmds/clean_cmd.py#newc...
shell/subcmds/clean_cmd.py:1: #!/usr/bin/python
On 2011/02/02 01:16:19, sosa wrote:
> Only directly shell-callable python should have this up top (i.e main /
> unittests)

Done.

http://codereview.chromium.org/6250058/diff/1/shell/subcmds/portage_cmds.py
File shell/subcmds/portage_cmds.py (right):

http://codereview.chromium.org/6250058/diff/1/shell/subcmds/portage_cmds.py#n...
shell/subcmds/portage_cmds.py:2: #
On 2011/02/02 01:16:19, sosa wrote:
> same

Done.

http://codereview.chromium.org/6250058/diff/1/shell/subcmds/shell_cmd.py
File shell/subcmds/shell_cmd.py (right):

http://codereview.chromium.org/6250058/diff/1/shell/subcmds/shell_cmd.py#newc...
shell/subcmds/shell_cmd.py:1: #!/usr/bin/python
On 2011/02/02 01:16:19, sosa wrote:
> same

Done.

http://codereview.chromium.org/6250058/diff/1/shell/subcmds/shell_cmd.py#newc...
shell/subcmds/shell_cmd.py:125: cros_lib.RunCommand(argv, cwd=cwd, env=env,
error_ok=True, ignore_sigint=True)
On 2011/02/02 01:16:19, sosa wrote:
> 80 char

Done.

http://codereview.chromium.org/6250058/diff/1/shell/subcmds/workon_cmd.py
File shell/subcmds/workon_cmd.py (right):

http://codereview.chromium.org/6250058/diff/1/shell/subcmds/workon_cmd.py#new...
shell/subcmds/workon_cmd.py:1: #!/usr/bin/python
On 2011/02/02 01:16:19, sosa wrote:
> same

Done.

http://codereview.chromium.org/6250058/diff/1/shell/utils.py
File shell/utils.py (right):

http://codereview.chromium.org/6250058/diff/1/shell/utils.py#newcode1
shell/utils.py:1: #!/usr/bin/python
On 2011/02/02 01:16:19, sosa wrote:
> same

Done.

http://codereview.chromium.org/6250058/diff/1/shell/utils.py#newcode194
shell/utils.py:194: cros_lib.Die("Couldn't find any matching %s specs for: %s" %
(spec_type, spec_name))
On 2011/02/02 01:16:19, sosa wrote:
> 80 chars

Done.

http://codereview.chromium.org/6250058/diff/1/shell/utils.py#newcode305
shell/utils.py:305: cros_lib.Die('Chroot dir does not exist; try the "build
host" command.\n  %s.' %
On 2011/02/02 01:16:19, sosa wrote:
> 80 chars

Done.

http://codereview.chromium.org/6250058/diff/1/shell/utils.py#newcode358
shell/utils.py:358: argv: The value of sys.argv
Wanted to be explicit that this works on sys.argv, so made caller pass it in.

On 2011/02/02 01:16:19, sosa wrote:
> um why not just take sys.argv then?

http://codereview.chromium.org/6250058/diff/1/shell/utils.py#newcode374
shell/utils.py:374: sys.exit(0)
OK, we now return True if we handled things.  It's up to main() to return then.

Powered by Google App Engine
This is Rietveld 408576698