~artfwo/indicator-cpufreq/trunk

« back to all changes in this revision

Viewing changes to indicator_cpufreq/cpufreq.py

  • Committer: Artem Popov
  • Date: 2013-01-25 14:15:03 UTC
  • Revision ID: artfwo@ubuntu.com-20130125141503-wg4wb2x0yowu1gs5
* Finally a working Python3 port.
* Drop remaining stuff from Quickly, use vanilla distutils-extra.
* Bugfixes:
    - LP: #1008438.
    - LP: #1079864.
* Transliterate copyright info.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
2
### BEGIN LICENSE
3
 
# Copyright (C) 2010 Артём Попов <artfwo@gmail.com>
 
3
# Copyright (C) 2010 Artem Popov <artfwo@gmail.com>
4
4
# This program is free software: you can redistribute it and/or modify it 
5
5
# under the terms of the GNU General Public License version 3, as published 
6
6
# by the Free Software Foundation.
136
136
    return (min.value, max.value)
137
137
 
138
138
def get_driver(cpu):
139
 
    return _libcpufreq.cpufreq_get_driver(cpu)
 
139
    return _libcpufreq.cpufreq_get_driver(cpu).decode()
140
140
 
141
141
def get_policy(cpu):
142
142
    p = _libcpufreq.cpufreq_get_policy(cpu)
143
 
    policy = (p.contents.min, p.contents.max, p.contents.governor)
 
143
    policy = (p.contents.min, p.contents.max, p.contents.governor.decode())
144
144
    _libcpufreq.cpufreq_put_policy(p)
145
145
    return policy
146
146
 
147
 
def _marshall_structs(first, field):
 
147
def _marshall_structs(first, field, decode=False):
148
148
    values = []
149
149
    p = first
150
150
    while p:
151
 
        values.append(getattr(p.contents, field))
 
151
        if decode:
 
152
            values.append(getattr(p.contents, field).decode())
 
153
        else:
 
154
            values.append(getattr(p.contents, field))
152
155
        p = p.contents.next
153
156
    return values
154
157
 
155
158
def get_available_governors(cpu):
156
159
    structs = _libcpufreq.cpufreq_get_available_governors(cpu)
157
 
    values = _marshall_structs(structs, 'governor')
 
160
    values = _marshall_structs(structs, 'governor', decode=True)
158
161
    _libcpufreq.cpufreq_put_available_governors(structs)
159
162
    return values
160
163
 
199
202
    return _libcpufreq.cpufreq_modify_policy_max(cpu, max_freq)
200
203
 
201
204
def modify_policy_governor(cpu, governor):
202
 
    return _libcpufreq.cpufreq_modify_policy_governor(cpu, governor)
 
205
    return _libcpufreq.cpufreq_modify_policy_governor(cpu, governor.encode())
203
206
 
204
207
def set_frequency(cpu, target_frequency):
205
208
    return _libcpufreq.cpufreq_set_frequency(cpu, target_frequency)