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

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

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

Powered by Google App Engine
This is Rietveld 408576698