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
|
|
4 |
# This file is in the public domain
|
|
5 |
### END LICENSE
|
|
6 |
||
7 |
###################### DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ######################
|
|
8 |
||
9 |
import os |
|
10 |
import sys |
|
11 |
||
12 |
try: |
|
13 |
import DistUtilsExtra.auto |
|
14 |
except ImportError: |
|
15 |
print >> sys.stderr, 'To build indicator-cpufreq you need https://launchpad.net/python-distutils-extra' |
|
16 |
sys.exit(1) |
|
17 |
assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18' |
|
18 |
||
19 |
def update_data_path(prefix, oldvalue=None): |
|
20 |
||
21 |
try: |
|
22 |
fin = file('indicator_cpufreq/indicator_cpufreqconfig.py', 'r') |
|
23 |
fout = file(fin.name + '.new', 'w') |
|
24 |
||
25 |
for line in fin: |
|
26 |
fields = line.split(' = ') # Separate variable from value |
|
27 |
if fields[0] == '__indicator_cpufreq_data_directory__': |
|
28 |
# update to prefix, store oldvalue
|
|
29 |
if not oldvalue: |
|
30 |
oldvalue = fields[1] |
|
31 |
line = "%s = '%s'\n" % (fields[0], prefix) |
|
32 |
else: # restore oldvalue |
|
33 |
line = "%s = %s" % (fields[0], oldvalue) |
|
34 |
fout.write(line) |
|
35 |
||
36 |
fout.flush() |
|
37 |
fout.close() |
|
38 |
fin.close() |
|
39 |
os.rename(fout.name, fin.name) |
|
40 |
except (OSError, IOError), e: |
|
41 |
print ("ERROR: Can't find indicator_cpufreq/indicator_cpufreqconfig.py") |
|
42 |
sys.exit(1) |
|
43 |
return oldvalue |
|
44 |
||
45 |
||
46 |
class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto): |
|
47 |
def run(self): |
|
48 |
previous_value = update_data_path(self.prefix + '/share/indicator-cpufreq/') |
|
49 |
DistUtilsExtra.auto.install_auto.run(self) |
|
50 |
update_data_path(self.prefix, previous_value) |
|
51 |
||
52 |
||
53 |
||
54 |
##################################################################################
|
|
55 |
###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ######################
|
|
56 |
##################################################################################
|
|
57 |
||
58 |
DistUtilsExtra.auto.setup( |
|
59 |
name='indicator-cpufreq', |
|
60 |
version='0.1', |
|
61 |
#license='GPL-3',
|
|
62 |
#author='Your Name',
|
|
63 |
#author_email='email@ubuntu.com',
|
|
64 |
#description='UI for managing …',
|
|
65 |
#long_description='Here a longer description',
|
|
66 |
#url='https://launchpad.net/indicator-cpufreq',
|
|
67 |
cmdclass={'install': InstallAndUpdateDataDirectory} |
|
68 |
)
|
|
69 |