Merge pull request #12 from brot/bugfix
[gpodder.git] / setup.py
blobd19022d98925b5588ab465b041aeb921e5a2434d
1 #!/usr/bin/env python
4 # gPodder - A media aggregator and podcast client
5 # Copyright (c) 2005-2012 Thomas Perl and the gPodder Team
7 # gPodder is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # gPodder is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import glob
22 import os
23 import re
24 import sys
26 from distutils.core import setup
28 installing = ('install' in sys.argv and '--help' not in sys.argv)
30 # Read the metadata from gPodder's __init__ module (doesn't need importing)
31 main_module = open('src/gpodder/__init__.py').read()
32 metadata = dict(re.findall("__([a-z_]+)__\s*=\s*'([^']+)'", main_module))
34 author, email = re.match(r'^(.*) <(.*)>$', metadata['author']).groups()
37 class MissingFile(BaseException): pass
39 def info(message, item=None):
40 print '=>', message, item if item is not None else ''
43 def find_data_files(uis, scripts):
44 # Support for installing only a subset of translations
45 linguas = os.environ.get('LINGUAS', None)
46 if linguas is not None:
47 linguas = linguas.split()
48 info('Selected languages (from $LINGUAS):', linguas)
50 for dirpath, dirnames, filenames in os.walk('share'):
51 if not filenames:
52 continue
54 # Skip data folders if we don't want the corresponding UI
55 share_gpodder_ui = os.path.join('share', 'gpodder', 'ui')
56 if uis is not None and dirpath.startswith(share_gpodder_ui):
57 dirparts = dirpath.split(os.sep)
58 if not any(part in uis for part in dirparts):
59 info('Skipping folder:', dirpath)
60 continue
62 # Skip translations if $LINGUAS is set
63 share_locale = os.path.join('share', 'locale')
64 if linguas is not None and dirpath.startswith(share_locale):
65 _, _, language, _ = dirpath.split(os.sep, 3)
66 if language not in linguas:
67 info('Skipping translation:', language)
68 continue
70 # Skip desktop stuff if we don't have any UIs requiring it
71 skip_folder = False
72 uis_requiring_freedesktop = ('gtk', 'qml')
73 freedesktop_folders = ('icons', 'dbus-1', 'applications')
74 for folder in freedesktop_folders:
75 share_folder = os.path.join('share', folder)
76 if dirpath.startswith(share_folder) and uis is not None:
77 if not any(ui in uis_requiring_freedesktop for ui in uis):
78 info('Skipping freedesktop.org folder:', dirpath)
79 skip_folder = True
80 break
82 if skip_folder:
83 continue
85 # Skip manpages if their scripts are not going to be installed
86 share_man = os.path.join('share', 'man')
87 if dirpath.startswith(share_man):
88 def have_script(filename):
89 if not filename.endswith('.1'):
90 return True
92 basename, _ = os.path.splitext(filename)
93 result = any(os.path.basename(s) == basename for s in scripts)
94 if not result:
95 info('Skipping manpage without script:', filename)
96 return result
97 filenames = filter(have_script, filenames)
99 def convert_filename(filename):
100 filename = os.path.join(dirpath, filename)
102 # Skip header files generated by "make messages"
103 if filename.endswith('.h'):
104 return None
106 # Skip .in files, but check if their target exist
107 if filename.endswith('.in'):
108 filename = filename[:-3]
109 if installing and not os.path.exists(filename):
110 raise MissingFile(filename)
111 return None
113 return filename
115 filenames = filter(None, map(convert_filename, filenames))
116 if filenames:
117 # Some distros/ports install manpages into $PREFIX/man instead
118 # of $PREFIX/share/man (e.g. FreeBSD). To allow this, we strip
119 # the "share/" part if the variable GPODDER_MANPATH_NO_SHARE is
120 # set to any value in the environment.
121 if dirpath.startswith(share_man):
122 if 'GPODDER_MANPATH_NO_SHARE' in os.environ:
123 dirpath = dirpath.replace(share_man, 'man')
125 yield (dirpath, filenames)
128 def find_packages(uis):
129 src_gpodder = os.path.join('src', 'gpodder')
130 for dirpath, dirnames, filenames in os.walk(src_gpodder):
131 if '__init__.py' not in filenames:
132 continue
134 skip = False
135 dirparts = dirpath.split(os.sep)
136 dirparts.pop(0)
137 package = '.'.join(dirparts)
139 # Extract all parts of the package name ending in "ui"
140 ui_parts = filter(lambda p: p.endswith('ui'), dirparts)
141 if uis is not None and ui_parts:
142 # Strip the trailing "ui", e.g. "gtkui" -> "gtk"
143 folder_uis = map(lambda p: p[:-2], ui_parts)
144 for folder_ui in folder_uis:
145 if folder_ui not in uis:
146 info('Skipping package:', package)
147 skip = True
148 break
150 if not skip:
151 yield package
154 def find_scripts(uis):
155 # Functions for scripts to check if they should be installed
156 file_checks = {
157 'gpo': lambda uis: 'cli' in uis,
158 'gpodder': lambda uis: any(ui in uis for ui in ('qml', 'gtk')),
161 for dirpath, dirnames, filenames in os.walk('bin'):
162 for filename in filenames:
163 # If we have a set of uis, check if we can skip this file
164 if uis is not None and filename in file_checks:
165 if not file_checks[filename](uis):
166 info('Skipping script:', filename)
167 continue
169 yield os.path.join(dirpath, filename)
172 # Recognized UIs: cli, gtk, qml, web (default: install all UIs)
173 uis = os.environ.get('GPODDER_INSTALL_UIS', None)
174 if uis is not None:
175 uis = uis.split()
177 # The CLI has a hard dependency on the Web UI
178 if 'cli' in uis and 'web' not in uis:
179 info('Adding Web UI as dependency of CLI')
180 uis.append('web')
182 info('Selected UIs (from $GPODDER_INSTALL_UIS):', uis)
185 try:
186 packages = list(sorted(find_packages(uis)))
187 scripts = list(sorted(find_scripts(uis)))
188 data_files = list(sorted(find_data_files(uis, scripts)))
189 except MissingFile, mf:
190 print >>sys.stderr, """
191 Missing file: %s
193 If you want to install, use "make install" instead of using
194 setup.py directly. See the README file for more information.
195 """ % mf.message
196 sys.exit(1)
199 setup(
200 name = 'gpodder',
201 version = metadata['version'],
202 description = metadata['tagline'],
203 license = metadata['license'],
204 url = metadata['url'],
206 author = author,
207 author_email = email,
209 package_dir = {'': 'src'},
210 packages = packages,
211 scripts = scripts,
212 data_files = data_files,