forked from thesamet/webilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
215 lines (176 loc) · 6.76 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env python
from setuptools import setup
import os
import sys
import glob
from distutils.core import Command
from distutils.command.build import build as build_
from distutils.command.clean import clean as clean_
from setuptools.command.develop import develop as develop_
from setuptools.command.egg_info import egg_info as egg_info_
from setuptools.command.install import install as install_
from distutils.errors import DistutilsError
import gettext
LOCALE_DIR = os.path.join(os.path.dirname(sys.argv[0]), 'src/webilder/locale')
gettext.install('webilder', LOCALE_DIR)
if sys.argv[-1] == 'setup.py':
print _("To install, run '%s'") % 'python setup.py install'
print
def GetBonoboPath():
"""Extract the bonono path from the command line."""
for flag in sys.argv[1:]:
if flag.startswith('--bonobo_path'):
sys.argv.remove(flag)
return flag.split('=', 1)[1]
else:
return 'lib/bonobo/servers'
class file_build_command(Command):
def initialize_options(self):
self.build_lib = None
self.install_scripts = None
self.install_data = None
def finalize_options(self):
self.set_undefined_options('build',
('build_lib', 'build_lib'))
self.set_undefined_options('install',
('install_scripts', 'install_scripts'),
('install_data', 'install_data'),
)
inst_cmd = self.get_finalized_command('install')
if inst_cmd.root is not None:
self.install_scripts = inst_cmd._original_install_scripts
self.install_data = inst_cmd._original_install_data
def run(self):
dest_dir = self.get_dest_dir()
self.mkpath(dest_dir)
fc = file(os.path.join(self.dir, self.filename + '.in'), 'r').read()
fw = file(os.path.join(dest_dir, self.filename), 'w')
fw.write(fc % dict(
bin_dir = self.install_scripts,
data_dir = os.path.join(self.install_data, 'share', 'pixmaps'),
version = self.distribution.get_version()))
fw.close()
class build_server(file_build_command):
description = _('Builds the bonobo server file representing the applet.')
dir = 'servers'
filename = 'GNOME_WebilderApplet.server'
def get_dest_dir(self): return 'servers'
class egg_info(egg_info_):
def find_sources(self):
egg_info_.find_sources(self)
# Prune debian/ control directory.
self.filelist.exclude_pattern(None, prefix='debian')
class build(build_):
sub_commands = build_.sub_commands[:]
sub_commands.append(('build_server', None))
sub_commands.append(('build_i18n', None))
class CompileTranslationsMixin(object):
def compile_mo(self):
for po in glob.glob(os.path.join(LOCALE_DIR, '*/*/*.po')):
self.spawn([
'msgfmt', po,
'-o', po[:-3]+'.mo'])
class develop(develop_, CompileTranslationsMixin):
def install_for_development(self):
self.compile_mo()
return develop_.install_for_development(self)
sub_commands = develop_.sub_commands[:]
sub_commands.append(('build_i18n', None))
class build_i18n(Command, CompileTranslationsMixin):
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
self.compile_mo()
def check_modules(*modules):
for module in modules:
import imp
try:
imp.find_module(module)
except ImportError, e:
raise DistutilsError, _('Could not find module %s. Make sure all dependencies are installed.') % e
class install(install_):
user_options = install_.user_options[:]
sub_commands = install_.sub_commands[:]
def run(self):
check_modules('gtk', 'pygtk', 'gnome', 'appindicator')
install_.run(self)
print _("""
Installation completed successfully.
GNOME Users: Right-click on the GNOME panel, choose "Add to panel",
and select "Webilder Webshots Applet". If it
is not in the list - log off and log in again.
# If you prefer the command line, you can run webilder_desktop
# to configure Webilder and manage your photos. It is also
# possible to start photo downloading from the command line by
# starting webilder_downloader.
#
# Please report any problem to thesamet at gmail.com.
# """)
def change_roots(self, *names):
# in case we are going to perform a rooted install, store the original
# path names, so we can use them in file_build_command's.
for name in names:
attr = 'install_' + name
backup_attr = '_original_install_' + name
setattr(self, backup_attr, getattr(self, attr))
install_.change_roots(self, *names)
class clean(clean_):
def run(self):
if self.dry_run:
return
for mo in glob.glob(os.path.join(LOCALE_DIR, '*/*/*.mo')):
os.unlink(mo)
bonobo_server = os.path.join(
os.path.dirname(sys.argv[0]),
'servers/GNOME_WebilderApplet.server')
if os.path.exists(bonobo_server):
os.unlink(bonobo_server)
clean_.run(self)
setup(name='Webilder',
version='0.7.2',
description='Webilder Desktop',
author='Nadav Samet',
author_email='thesamet@gmail.com',
url='http://www.webilder.org',
packages = ['webilder', 'webilder.webshots', 'webilder.flickr'],
package_dir = {'': 'src'},
package_data = {
'': ['ui/*.glade', 'ui/*.png', 'ui/*.xpm', 'locale/*/*/*.mo'],
},
exclude_package_data = {
'': ['debian/*',],
},
data_files = [
(os.path.join('share', 'pixmaps'),
['src/webilder/ui/camera48.png']),
(os.path.join('share', 'applications'),
['desktop/webilder_desktop.desktop']),
(os.path.join('share', 'applications'),
['desktop/webilder_indicator.desktop']),
(os.path.join('share', 'gnome', 'autostart'),
['autostart/webilder_indicator.desktop']),
(GetBonoboPath(),
['servers/GNOME_WebilderApplet.server'])
],
cmdclass = {
'build': build,
'build_server': build_server,
'build_i18n': build_i18n,
'clean': clean,
'develop': develop,
'egg_info': egg_info,
'install': install},
entry_points = {
'console_scripts': [
'webilder_downloader = webilder.downloader:main',
'wbz_handler = webilder.wbz_handler:main',
'webilder_applet = webilder.webilder_gnome_applet:main',
'webilder_unity_indicator = webilder.webilder_unity_indicator:main',
],
'gui_scripts': [
'webilder_desktop = webilder.WebilderDesktop:main'
]
}
)