~artfwo/indicator-cpufreq/trunk

1 by Артём Попов
Initial project creation with Quickly!
1
#!/usr/bin/env python
2
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
### BEGIN LICENSE
2 by Артём Попов
Initial working version.
4
# Copyright (C) 2010 Артём Попов <artfwo@gmail.com>
5
# This program is free software: you can redistribute it and/or modify it 
6
# under the terms of the GNU General Public License version 3, as published 
7
# by the Free Software Foundation.
8
# 
9
# This program is distributed in the hope that it will be useful, but 
10
# WITHOUT ANY WARRANTY; without even the implied warranties of 
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
12
# PURPOSE.  See the GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License along 
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
1 by Артём Попов
Initial project creation with Quickly!
16
### END LICENSE
17
18
###################### DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ######################
19
20
import os
21
import sys
22
23
try:
24
    import DistUtilsExtra.auto
25
except ImportError:
26
    print >> sys.stderr, 'To build indicator-cpufreq you need https://launchpad.net/python-distutils-extra'
27
    sys.exit(1)
28
assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18'
29
30
def update_data_path(prefix, oldvalue=None):
31
32
    try:
33
        fin = file('indicator_cpufreq/indicator_cpufreqconfig.py', 'r')
34
        fout = file(fin.name + '.new', 'w')
35
36
        for line in fin:            
37
            fields = line.split(' = ') # Separate variable from value
38
            if fields[0] == '__indicator_cpufreq_data_directory__':
39
                # update to prefix, store oldvalue
40
                if not oldvalue:
41
                    oldvalue = fields[1]
42
                    line = "%s = '%s'\n" % (fields[0], prefix)
43
                else: # restore oldvalue
44
                    line = "%s = %s" % (fields[0], oldvalue)
45
            fout.write(line)
46
47
        fout.flush()
48
        fout.close()
49
        fin.close()
50
        os.rename(fout.name, fin.name)
51
    except (OSError, IOError), e:
52
        print ("ERROR: Can't find indicator_cpufreq/indicator_cpufreqconfig.py")
53
        sys.exit(1)
54
    return oldvalue
55
56
57
class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
58
    def run(self):
59
        previous_value = update_data_path(self.prefix + '/share/indicator-cpufreq/')
60
        DistUtilsExtra.auto.install_auto.run(self)
61
        update_data_path(self.prefix, previous_value)
62
63
64
        
65
##################################################################################
66
###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ######################
67
##################################################################################
68
6 by Артём Попов
Initial support for themeable icons.
69
import glob
70
1 by Артём Попов
Initial project creation with Quickly!
71
DistUtilsExtra.auto.setup(
72
    name='indicator-cpufreq',
8 by Артём Попов
Packaging update 2.
73
    version='0.1.1-public1',
2 by Артём Попов
Initial working version.
74
    license='GPL-3',
75
    author='Артём Попов',
76
    author_email='artfwo@gmail.com',
77
    description='CPU frequency scaling indicator',
7 by Артём Попов
Update packaging for 0.1.1.
78
    long_description='Indicator applet for displaying and changing CPU frequency on-the-fly.',
2 by Артём Попов
Initial working version.
79
    url='https://launchpad.net/indicator-cpufreq',
6 by Артём Попов
Initial support for themeable icons.
80
    cmdclass={'install': InstallAndUpdateDataDirectory},
81
    # FIXME: install icons as data_files until we resolve it with quickly
82
    data_files=[
83
        ('share/icons/ubuntu-mono-dark/status/22',
18 by Артём Попов
Added better SVG icons.
84
            glob.glob('icons/ubuntu-mono-dark/*')),
6 by Артём Попов
Initial support for themeable icons.
85
        ('share/icons/ubuntu-mono-light/status/22',
18 by Артём Попов
Added better SVG icons.
86
            glob.glob('icons/ubuntu-mono-light/*')),
6 by Артём Попов
Initial support for themeable icons.
87
    ]
88
)
1 by Артём Попов
Initial project creation with Quickly!
89