1# Copyright 2013 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""A module for the select command."""
6
7import cr
8
9# The set of variables SELECT writes into the client plugin to control the
10# active output directory.
11SELECT_OUT_VARS = ['CR_OUT_FULL']
12
13
14class SelectCommand(cr.Command):
15  """The implementation of the select command.
16
17  The select command is used to set the default output directory used by all
18  other commands. It does this by writing out a plugin into the client root
19  that sets the active output path.
20  """
21
22  def __init__(self):
23    super(SelectCommand, self).__init__()
24    self.help = 'Select an output directory'
25    self.description = ("""
26        This makes the specified output directory the default for all future
27        operations. It also invokes prepare on that directory.
28        """)
29
30  def AddArguments(self, subparsers):
31    parser = super(SelectCommand, self).AddArguments(subparsers)
32    self.AddPrepareArguments(parser)
33    return parser
34
35  @classmethod
36  def AddPrepareArguments(cls, parser):
37    parser.add_argument(
38        '--no-prepare', dest='_no_prepare',
39        action='store_true', default=False,
40        help='Don\'t prepare the output directory.'
41    )
42
43  def Run(self):
44    self.Select()
45
46  @classmethod
47  def Select(cls):
48    """Performs the select.
49
50    This is also called by the init command to auto select the new output
51    directory.
52    """
53    cr.base.client.WriteConfig(
54        cr.context.Get('CR_CLIENT_PATH'), dict(
55            CR_OUT_FULL=cr.context.Get('CR_OUT_FULL')))
56    cr.base.client.PrintInfo()
57    # Now we run the post select actions
58    if not getattr(cr.context.args, '_no_prepare', None):
59      cr.PrepareCommand.Prepare()
60