1
by Jono Bacon
Initial project creation with Quickly! |
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
### BEGIN LICENSE
|
|
2
by Jono Bacon
First code for the repo. |
4 |
# Copyright (C) 2009 Jono Bacon <jono@ubuntu.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 Jono Bacon
Initial project creation with Quickly! |
16 |
### END LICENSE
|
17 |
||
18 |
###################### DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ######################
|
|
19 |
||
20 |
try: |
|
21 |
import DistUtilsExtra.auto |
|
22 |
except ImportError: |
|
23 |
import sys |
|
24 |
print >> sys.stderr, 'To build acire you need https://launchpad.net/python-distutils-extra' |
|
25 |
sys.exit(1) |
|
26 |
||
27 |
assert DistUtilsExtra.auto.__version__ >= '2.10', 'needs DistUtilsExtra.auto >= 2.10' |
|
28 |
import os |
|
29 |
||
30 |
||
31 |
def update_data_path(prefix, oldvalue=None): |
|
32 |
||
33 |
try: |
|
34 |
fin = file('acire/acireconfig.py', 'r') |
|
35 |
fout = file(fin.name + '.new', 'w') |
|
36 |
||
37 |
for line in fin: |
|
38 |
fields = line.split(' = ') # Separate variable from value |
|
39 |
if fields[0] == '__acire_data_directory__': |
|
40 |
# update to prefix, store oldvalue
|
|
41 |
if not oldvalue: |
|
42 |
oldvalue = fields[1] |
|
43 |
line = "%s = '%s'\n" % (fields[0], prefix) |
|
44 |
else: # restore oldvalue |
|
45 |
line = "%s = %s" % (fields[0], oldvalue) |
|
46 |
fout.write(line) |
|
47 |
||
48 |
fout.flush() |
|
49 |
fout.close() |
|
50 |
fin.close() |
|
51 |
os.rename(fout.name, fin.name) |
|
52 |
except (OSError, IOError), e: |
|
53 |
print ("ERROR: Can't find acire/acireconfig.py") |
|
54 |
sys.exit(1) |
|
55 |
return oldvalue |
|
56 |
||
57 |
||
58 |
def update_desktop_file(datadir): |
|
59 |
||
60 |
try: |
|
61 |
fin = file('acire.desktop.in', 'r') |
|
62 |
fout = file(fin.name + '.new', 'w') |
|
63 |
||
64 |
for line in fin: |
|
65 |
if 'Icon=' in line: |
|
66 |
line = "Icon=%s\n" % (datadir + 'media/icon.png') |
|
67 |
fout.write(line) |
|
68 |
fout.flush() |
|
69 |
fout.close() |
|
70 |
fin.close() |
|
71 |
os.rename(fout.name, fin.name) |
|
72 |
except (OSError, IOError), e: |
|
73 |
print ("ERROR: Can't find acire.desktop.in") |
|
74 |
sys.exit(1) |
|
75 |
||
76 |
||
77 |
class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto): |
|
78 |
def run(self): |
|
79 |
if self.root or self.home: |
|
80 |
print "WARNING: You don't use a standard --prefix installation, take care that you eventually " \ |
|
81 |
"need to update quickly/quicklyconfig.py file to adjust __quickly_data_directory__. You can " \
|
|
82 |
"ignore this warning if you are packaging and uses --prefix."
|
|
83 |
previous_value = update_data_path(self.prefix + '/share/acire/') |
|
84 |
update_desktop_file(self.prefix + '/share/acire/') |
|
85 |
DistUtilsExtra.auto.install_auto.run(self) |
|
86 |
update_data_path(self.prefix, previous_value) |
|
87 |
||
88 |
||
89 |
||
90 |
##################################################################################
|
|
91 |
###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ######################
|
|
92 |
##################################################################################
|
|
93 |
||
94 |
DistUtilsExtra.auto.setup( |
|
95 |
name='acire', |
|
96 |
version='0.1', |
|
2
by Jono Bacon
First code for the repo. |
97 |
license='GPL-3', |
98 |
author='Jono Bacon', |
|
99 |
author_email='jono@ubuntu.com', |
|
100 |
description='Browse, run and play with Python code snippets quickly and easily.', |
|
101 |
long_description='Browse, run and play with Python code snippets quickly and easily.', |
|
102 |
url='https://launchpad.net/acire', |
|
1
by Jono Bacon
Initial project creation with Quickly! |
103 |
cmdclass={'install': InstallAndUpdateDataDirectory} |
104 |
)
|
|
105 |