| OLD | NEW |
| 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 Loading... |
| 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) |
| OLD | NEW |