| OLD | NEW |
| 1 """ | 1 """ |
| 2 DO NOT import this file directly - import client/bin/utils.py, | 2 DO NOT import this file directly - import client/bin/utils.py, |
| 3 which will mix this in | 3 which will mix this in |
| 4 | 4 |
| 5 Convenience functions for use by tests or whomever. | 5 Convenience functions for use by tests or whomever. |
| 6 | 6 |
| 7 Note that this file is mixed in by utils.py - note very carefully the | 7 Note that this file is mixed in by utils.py - note very carefully the |
| 8 precedence order defined there | 8 precedence order defined there |
| 9 """ | 9 """ |
| 10 import os, shutil, sys, signal, commands, pickle, glob, statvfs | 10 import os, shutil, sys, signal, commands, pickle, glob, statvfs |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return run_cmd('%s %s | %s' % (cat, file, command), | 56 return run_cmd('%s %s | %s' % (cat, file, command), |
| 57 ignore_status=ignore_status) | 57 ignore_status=ignore_status) |
| 58 | 58 |
| 59 | 59 |
| 60 def extract_tarball_to_dir(tarball, dir): | 60 def extract_tarball_to_dir(tarball, dir): |
| 61 """ | 61 """ |
| 62 Extract a tarball to a specified directory name instead of whatever | 62 Extract a tarball to a specified directory name instead of whatever |
| 63 the top level of a tarball is - useful for versioned directory names, etc | 63 the top level of a tarball is - useful for versioned directory names, etc |
| 64 """ | 64 """ |
| 65 if os.path.exists(dir): | 65 if os.path.exists(dir): |
| 66 raise NameError, 'target %s already exists' % dir | 66 if os.path.isdir(dir): |
| 67 shutil.rmtree(dir) |
| 68 else: |
| 69 os.remove(dir) |
| 67 pwd = os.getcwd() | 70 pwd = os.getcwd() |
| 68 os.chdir(os.path.dirname(os.path.abspath(dir))) | 71 os.chdir(os.path.dirname(os.path.abspath(dir))) |
| 69 newdir = extract_tarball(tarball) | 72 newdir = extract_tarball(tarball) |
| 70 os.rename(newdir, dir) | 73 os.rename(newdir, dir) |
| 71 os.chdir(pwd) | 74 os.chdir(pwd) |
| 72 | 75 |
| 73 | 76 |
| 74 def extract_tarball(tarball): | 77 def extract_tarball(tarball): |
| 75 """Returns the directory extracted by the tarball.""" | 78 """Returns the directory extracted by the tarball.""" |
| 76 extracted = cat_file_to_cmd(tarball, 'tar xvf - 2>/dev/null', | 79 extracted = cat_file_to_cmd(tarball, 'tar xvf - 2>/dev/null', |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 Suspend the system to RAM (S3) | 773 Suspend the system to RAM (S3) |
| 771 """ | 774 """ |
| 772 set_power_state('mem') | 775 set_power_state('mem') |
| 773 | 776 |
| 774 | 777 |
| 775 def suspend_to_disk(): | 778 def suspend_to_disk(): |
| 776 """ | 779 """ |
| 777 Suspend the system to disk (S4) | 780 Suspend the system to disk (S4) |
| 778 """ | 781 """ |
| 779 set_power_state('disk') | 782 set_power_state('disk') |
| OLD | NEW |