2
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
4
# Copyright (C) 2014 Archisman Panigrahi <apandada1@gmail.com>
5
# Thanks to Adam Whitcroft <adamwhitcroft.com> for Climacons!
6
# This program is free software: you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License version 3, as published
8
# by the Free Software Foundation.
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranties of
12
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
# PURPOSE. See the GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License along
16
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
###################### DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ######################
25
import DistUtilsExtra.auto
27
print >> sys.stderr, 'To build typhoon you need https://launchpad.net/python-distutils-extra'
29
assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18'
31
def update_config(libdir, values = {}):
33
filename = os.path.join(libdir, 'typhoon_lib/typhoonconfig.py')
36
fin = file(filename, 'r')
37
fout = file(filename + '.new', 'w')
40
fields = line.split(' = ') # Separate variable from value
41
if fields[0] in values:
42
oldvalues[fields[0]] = fields[1].strip()
43
line = "%s = %s\n" % (fields[0], values[fields[0]])
49
os.rename(fout.name, fin.name)
50
except (OSError, IOError), e:
51
print ("ERROR: Can't find %s" % filename)
56
def move_desktop_file(root, target_data, prefix):
57
# The desktop file is rightly installed into install_data. But it should
58
# always really be installed into prefix, because while we can install
59
# normal data files anywhere we want, the desktop file needs to exist in
60
# the main system to be found. Only actually useful for /opt installs.
62
old_desktop_path = os.path.normpath(root + target_data +
63
'/share/applications')
64
old_desktop_file = old_desktop_path + '/typhoon.desktop'
65
desktop_path = os.path.normpath(root + prefix + '/share/applications')
66
desktop_file = desktop_path + '/typhoon.desktop'
68
if not os.path.exists(old_desktop_file):
69
print ("ERROR: Can't find", old_desktop_file)
71
elif target_data != prefix + '/':
72
# This is an /opt install, so rename desktop file to use extras-
73
desktop_file = desktop_path + '/extras-typhoon.desktop'
75
os.makedirs(desktop_path)
76
os.rename(old_desktop_file, desktop_file)
77
os.rmdir(old_desktop_path)
79
print ("ERROR: Can't rename", old_desktop_file, ":", e)
84
def update_desktop_file(filename, target_pkgdata, target_scripts):
87
fin = file(filename, 'r')
88
fout = file(filename + '.new', 'w')
92
line = "Icon=%s\n" % (target_pkgdata + 'media/typhoon.svg')
94
cmd = line.split("=")[1].split(None, 1)
95
line = "Exec=%s" % (target_scripts + 'typhoon')
97
line += " %s" % cmd[1].strip() # Add script arguments back
103
os.rename(fout.name, fin.name)
104
except (OSError, IOError), e:
105
print ("ERROR: Can't find %s" % filename)
108
def compile_schemas(root, target_data):
109
if target_data == '/usr/':
110
return # /usr paths don't need this, they will be handled by dpkg
111
schemadir = os.path.normpath(root + target_data + 'share/glib-2.0/schemas')
112
if (os.path.isdir(schemadir) and
113
os.path.isfile('/usr/bin/glib-compile-schemas')):
114
os.system('/usr/bin/glib-compile-schemas "%s"' % schemadir)
117
class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
119
DistUtilsExtra.auto.install_auto.run(self)
121
target_data = '/' + os.path.relpath(self.install_data, self.root) + '/'
122
target_pkgdata = target_data + 'share/typhoon/'
123
target_scripts = '/' + os.path.relpath(self.install_scripts, self.root) + '/'
125
values = {'__typhoon_data_directory__': "'%s'" % (target_pkgdata),
126
'__version__': "'%s'" % self.distribution.get_version()}
127
update_config(self.install_lib, values)
129
desktop_file = move_desktop_file(self.root, target_data, self.prefix)
130
update_desktop_file(desktop_file, target_pkgdata, target_scripts)
131
compile_schemas(self.root, target_data)
134
##################################################################################
135
###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ######################
136
##################################################################################
138
DistUtilsExtra.auto.setup(
142
author='Archisman Panigrahi',
143
author_email='apandada1@gmail.com',
144
description='Quickly check the weather with this beautiful application',
145
long_description='Typhoon is a free and open source weather application. It is continuation of discontinued Stormcloud 1.1 ,however with some changes. It is and always will be free. PPA: https://launchpad.net/~apandada1/+archive/typhoon/ Homepage: http://gettyphoon.tk/',
146
url='https://launchpad.net/typhoon',
147
cmdclass={'install': InstallAndUpdateDataDirectory}