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

Side by Side Diff: tools/cr/cr/commands/shell.py

Issue 142933004: [cr tool] Make context implicit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 9 months 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
« no previous file with comments | « tools/cr/cr/commands/select.py ('k') | tools/cr/cr/commands/sync.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """A module for the shell command.""" 5 """A module for the shell command."""
6 6
7 import os 7 import os
8 import tempfile 8 import tempfile
9 9
10 import cr 10 import cr
(...skipping 17 matching lines...) Expand all
28 in that shell. 28 in that shell.
29 This allows you to run commands that are not yet available natively 29 This allows you to run commands that are not yet available natively
30 in cr. 30 in cr.
31 """) 31 """)
32 32
33 def AddArguments(self, subparsers): 33 def AddArguments(self, subparsers):
34 parser = super(ShellCommand, self).AddArguments(subparsers) 34 parser = super(ShellCommand, self).AddArguments(subparsers)
35 self.ConsumeArgs(parser, 'the shell') 35 self.ConsumeArgs(parser, 'the shell')
36 return parser 36 return parser
37 37
38 def Run(self, context): 38 def Run(self):
39 if context.remains: 39 if cr.context.remains:
40 cr.Host.Shell(context, *context.remains) 40 cr.Host.Shell(*cr.context.remains)
41 return 41 return
42 # If we get here, we are trying to launch an interactive shell 42 # If we get here, we are trying to launch an interactive shell
43 shell = os.environ.get('SHELL', None) 43 shell = os.environ.get('SHELL', None)
44 if shell is None: 44 if shell is None:
45 print 'Don\'t know how to run a shell on this system' 45 print 'Don\'t know how to run a shell on this system'
46 elif shell.endswith('bash'): 46 elif shell.endswith('bash'):
47 ps1 = '[CR] ' + os.environ.get('PS1', '') 47 ps1 = '[CR] ' + os.environ.get('PS1', '')
48 with tempfile.NamedTemporaryFile() as rcfile: 48 with tempfile.NamedTemporaryFile() as rcfile:
49 rcfile.write('source ~/.bashrc\nPS1="'+ps1+'"') 49 rcfile.write('source ~/.bashrc\nPS1="'+ps1+'"')
50 rcfile.flush() 50 rcfile.flush()
51 cr.Host.Execute(context, shell, '--rcfile', rcfile.name) 51 cr.Host.Execute(shell, '--rcfile', rcfile.name)
52 else: 52 else:
53 cr.Host.Execute(context, shell) 53 cr.Host.Execute(shell)
OLDNEW
« no previous file with comments | « tools/cr/cr/commands/select.py ('k') | tools/cr/cr/commands/sync.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698