aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/hdparm.py
blob: fa2d5ce9acb0d7f5a0afc224c0016e6fcc8b5571 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- python -*-
'''
xpybar – xmobar replacement written in python
Copyright © 2014, 2015, 2016  Mattias Andrée (maandree@member.fsf.org)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

import os

from util import *


class HDParm: # TODO add output parsers
    '''
    Set/get SATA/IDE device parameters
    '''
    
    
    READAHEAD_SECTOR_COUNT = 'a'
    HAVE_READAHEAD = 'A'
    ADVANCED_POWER_MANAGEMENT = 'B'
    IDE_32BIT_IO_SUPPORT = 'c'
    POWER_MODE_STATUS = 'C'
    GEOMETRY = 'g'
    HITACHI_TEMPERATURE = 'H'
    KERNEL_INFORMATION = 'i'
    DIRECT_INFORMATION = 'I'
    WESTERN_DIGITAL_IDLE3_TIMEOUT = 'J'
    MULTIPLE_SECTOR_IO_SECTOR_COUNT = 'm'
    AUTOMATIC_ACOUSTIC_MANAGEMENT = 'M'
    MAX_VISIBLE_SECTOR_COUNT = 'N'
    COMMAND_QUEUE_DEPTH = 'Q'
    IS_READONLY = 'r'
    HAVE_WRITE_READ_VERIFY = 'R'
    IDLE_MODE = 'S'
    HAVE_WRITE_CACHING = 'W'
    STANDBY_MODE = 'y'
    SLEEP_MODE = 'Y'
    DISABLE_SEAGATE_AUTOMATIC_POWER_SAVING = 'Z'
    
    
    def __init__(self, devices = None):
        '''
        Constructor
        
        @param  devices:list<str>?  The devices to use, `None` for all
        '''
        self.devices = HDParm.get_devices() if devices is None else self.devices
        spawn_read()
    
    
    def get(self, action):
        '''
        Read information about selected devices
        
        @param   action:str  The information to read
        @return  :str        The read information
        '''
        return spawn_read('restricted-hdparm', '-%s' % action)
    
    
    def set(self, action, value = None):
        '''
        Configure selected devices
        
        @param   action:str  The settings to reconfigure
        @param   value:int?  The value to apply, `None` if there is no value to apply
        @return  :str        The read information
        '''
        if value is None:
            spawn('restricted-hdparm', action)
        else:
            spawn('restricted-hdparm', '-%s%s' % (action, str(value)))
    
    
    @staticmethod
    def get_devices(self):
        '''
        List available devices
        
        @param  :list<str>  Available devices
        '''
        test = lambda dev : (len(dev) == 3) and (dev[:2] in ('sd', 'hd'))
        return filter(test, os.listdir('/dev'))