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

Side by Side Diff: client/bin/base_utils.py

Issue 6551020: Merge remote branch 'autotest-upstream/master' into try-box1 (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/autotest.git@master
Patch Set: patch Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « client/bin/base_sysinfo.py ('k') | client/bin/local_host.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 """ 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 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 """ 741 """
742 'pgrep name' misses all python processes and also long process names. 742 'pgrep name' misses all python processes and also long process names.
743 'pgrep -f name' gets all shell commands with name in args. 743 'pgrep -f name' gets all shell commands with name in args.
744 So look only for command whose initial pathname ends with name. 744 So look only for command whose initial pathname ends with name.
745 Name itself is an egrep pattern, so it can use | etc for variations. 745 Name itself is an egrep pattern, so it can use | etc for variations.
746 """ 746 """
747 return utils.system("pgrep -f '^([^ /]*/)*(%s)([ ]|$)'" % name_pattern, 747 return utils.system("pgrep -f '^([^ /]*/)*(%s)([ ]|$)'" % name_pattern,
748 ignore_status=True) == 0 748 ignore_status=True) == 0
749 749
750 750
751 def get_hwclock_seconds(utc=True):
752 """
753 Return the hardware clock in seconds as a floating point value.
754 Use Coordinated Universal Time if utc is True, local time otherwise.
755 Raise a ValueError if unable to read the hardware clock.
756 """
757 cmd = '/sbin/hwclock --debug'
758 if utc:
759 cmd += ' --utc'
760 hwclock_output = utils.system_output(cmd, ignore_status=True)
761 match = re.search(r'= ([0-9]+) seconds since .+ (-?[0-9.]+) seconds$',
762 hwclock_output, re.DOTALL)
763 if match:
764 seconds = int(match.group(1)) + float(match.group(2))
765 logging.debug('hwclock seconds = %f' % seconds)
766 return seconds
767
768 raise ValueError('Unable to read the hardware clock -- ' +
769 hwclock_output)
770
771
772 def set_wake_alarm(alarm_time):
773 """
774 Set the hardware RTC-based wake alarm to 'alarm_time'.
775 """
776 utils.write_one_line('/sys/class/rtc/rtc0/wakealarm', str(alarm_time))
777
778
779 def set_power_state(state):
780 """
781 Set the system power state to 'state'.
782 """
783 utils.write_one_line('/sys/power/state', state)
784
785
786 def standby():
787 """
788 Power-on suspend (S1)
789 """
790 set_power_state('standby')
791
792
793 def suspend_to_ram():
794 """
795 Suspend the system to RAM (S3)
796 """
797 set_power_state('mem')
798
799
800 def suspend_to_disk():
801 """
802 Suspend the system to disk (S4)
803 """
804 set_power_state('disk')
OLDNEW
« no previous file with comments | « client/bin/base_sysinfo.py ('k') | client/bin/local_host.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698