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

Side by Side Diff: tools/cr/main.py

Issue 71483003: [cr tool] Adding the main function and remaining pieces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cr_commands
Patch Set: Use os.path.join directly Created 7 years, 1 month 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 unified diff | Download patch
« tools/cr/cr/autocomplete.py ('K') | « tools/cr/cr/autocomplete.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 """Chromium cr tool main module.
2
3 Holds the main function and all it's support code.
4 """
5
6 import os
7 import sys
8 import cr
9 import cr.auto.user
10 import cr.autocomplete
11 import cr.loader
12
13 _CONTACT = "iancottrell@chromium.org"
14
15
16 def Main():
17 """Chromium cr tool main function.
18
19 This is the main entry point of the cr tool, it finds and loads all the
20 plugins, creates the context and then activates and runs the specified
21 command.
22 """
23
24 # Add the users plugin dir to the cr.auto.user package scan
25 user_path = os.path.expanduser(os.path.join("~", ".config", "cr"))
26 cr.auto.user.__path__.append(user_path)
27
28 cr.loader.Scan()
29
30 # Build the command context
31 context = cr.Context(
32 description="The chrome dev build tool.",
33 epilog="Contact " + _CONTACT + " if you have issues with this tool.",
34 )
35 # Install the sub-commands
36 for command in cr.Command.Plugins():
37 context.AddSubParser(command)
38
39 # test for the special autocomplete command
40 if context.autocompleting:
41 # After plugins are loaded so pylint: disable=g-import-not-at-top
42 cr.autocomplete.Complete(context)
43 return
44 # Speculative argument processing to add config specific args
45 context.ParseArgs(True)
46 cr.plugin.Activate(context)
47 # At this point we should know what command we are going to use
48 command = cr.Command.GetActivePlugin(context)
49 # Do some early processing, in case it changes the build dir
50 if command:
51 command.EarlyArgProcessing(context)
52 # Update the activated set again, in case the early processing changed it
53 cr.plugin.Activate(context)
54 # Load the build specific configuration
55 found_build_dir = cr.base.client.LoadConfig(context)
56 # Final processing or arguments
57 context.ParseArgs()
58 cr.plugin.Activate(context)
59 # If we did not get a command before, it might have been fixed.
60 if command is None:
61 command = cr.Command.GetActivePlugin(context)
62 # If the verbosity level is 3 or greater, then print the environment here
63 if context.verbose >= 3:
64 context.DumpValues(context.verbose > 3)
65 if command is None:
66 print context.Substitute("No command specified.")
67 exit(1)
68 if command.requires_build_dir:
69 if not found_build_dir:
70 if not context.Find("CR_OUT_FULL"):
71 print context.Substitute(
72 "No build directory specified. Please use cr init to make one.")
73 else:
74 print context.Substitute(
75 "Build {CR_BUILD_DIR} not a valid build directory")
76 exit(1)
77 if context.Find("CR_VERSION") != cr.base.client.VERSION:
78 print context.Substitute(
79 "Build {CR_BUILD_DIR} is for the wrong version of cr")
80 print "Please run cr init to reset it"
81 exit(1)
82 cr.Platform.Prepare(context)
83 if context.verbose >= 1:
84 print context.Substitute(
85 "Running cr " + command.name + " for {CR_BUILD_DIR}")
bulach 2013/11/14 16:40:16 nit: s/"/'/ everywhere..
ian_cottrell 2013/11/15 10:28:51 Thought I had caught all those with my crazy greps
86 # Invoke the given command
87 command.Run(context)
88
89 if __name__ == "__main__":
90 sys.exit(Main())
OLDNEW
« tools/cr/cr/autocomplete.py ('K') | « tools/cr/cr/autocomplete.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698