| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 '''A module to provide interface to ChromeOS services.''' | 6 '''A module to provide interface to ChromeOS services.''' |
| 7 | 7 |
| 8 import datetime | 8 import datetime |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 if not os.path.exists(self.state_dir): | 52 if not os.path.exists(self.state_dir): |
| 53 try: | 53 try: |
| 54 os.mkdir(self.state_dir) | 54 os.mkdir(self.state_dir) |
| 55 except OSError, err: | 55 except OSError, err: |
| 56 raise ChromeOSInterfaceError(err) | 56 raise ChromeOSInterfaceError(err) |
| 57 if log_file: | 57 if log_file: |
| 58 self.log_file = os.path.join(state_dir, log_file) | 58 self.log_file = os.path.join(state_dir, log_file) |
| 59 | 59 |
| 60 def target_hosted(self): | 60 def target_hosted(self): |
| 61 '''Return True if running on a ChromeOS target.''' | 61 '''Return True if running on a ChromeOS target.''' |
| 62 return 'chromeos' in open('/proc/version_signature', 'r').read() | 62 signature = open('/proc/version_signature', 'r').read() |
| 63 return re.search(r'chrom(ium|e)os', signature, re.IGNORECASE) != None |
| 63 | 64 |
| 64 def state_dir_file(self, file_name): | 65 def state_dir_file(self, file_name): |
| 65 '''Get a full path of a file in the state directory.''' | 66 '''Get a full path of a file in the state directory.''' |
| 66 return os.path.join(self.state_dir, file_name) | 67 return os.path.join(self.state_dir, file_name) |
| 67 | 68 |
| 68 def acpi_file(self, file_name): | 69 def acpi_file(self, file_name): |
| 69 '''Get a full path of a file in the ACPI directory.''' | 70 '''Get a full path of a file in the ACPI directory.''' |
| 70 return os.path.join(self.acpi_dir, file_name) | 71 return os.path.join(self.acpi_dir, file_name) |
| 71 | 72 |
| 72 def init_environment(self): | 73 def init_environment(self): |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 def read_partition(self, partition, size): | 277 def read_partition(self, partition, size): |
| 277 '''Read the requested partition, up to size bytes.''' | 278 '''Read the requested partition, up to size bytes.''' |
| 278 tmp_file = self.state_dir_file('part.tmp') | 279 tmp_file = self.state_dir_file('part.tmp') |
| 279 self.run_shell_command('dd if=%s of=%s bs=1 count=%d' % ( | 280 self.run_shell_command('dd if=%s of=%s bs=1 count=%d' % ( |
| 280 partition, tmp_file, size)) | 281 partition, tmp_file, size)) |
| 281 fileh = open(tmp_file, 'r') | 282 fileh = open(tmp_file, 'r') |
| 282 data = fileh.read() | 283 data = fileh.read() |
| 283 fileh.close() | 284 fileh.close() |
| 284 os.remove(tmp_file) | 285 os.remove(tmp_file) |
| 285 return data | 286 return data |
| OLD | NEW |