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