Cover art: Add fallback artwork for QML UI
[gpodder.git] / setup.py
blobe22c028b53eb10036eb0a7ebed90c590eea26062
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)
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 yield (dirpath, filenames)
120 def find_packages(uis):
121 src_gpodder = os.path.join('src', 'gpodder')
122 for dirpath, dirnames, filenames in os.walk(src_gpodder):
123 if '__init__.py' not in filenames:
124 continue
126 skip = False
127 dirparts = dirpath.split(os.sep)
128 dirparts.pop(0)
129 package = '.'.join(dirparts)
131 # Extract all parts of the package name ending in "ui"
132 ui_parts = filter(lambda p: p.endswith('ui'), dirparts)
133 if uis is not None and ui_parts:
134 # Strip the trailing "ui", e.g. "gtkui" -> "gtk"
135 folder_uis = map(lambda p: p[:-2], ui_parts)
136 for folder_ui in folder_uis:
137 if folder_ui not in uis:
138 info('Skipping package:', package)
139 skip = True
140 break
142 if not skip:
143 yield package
146 def find_scripts(uis):
147 # Functions for scripts to check if they should be installed
148 file_checks = {
149 'gpo': lambda uis: 'cli' in uis,
150 'gpodder': lambda uis: any(ui in uis for ui in ('qml', 'gtk')),
153 for dirpath, dirnames, filenames in os.walk('bin'):
154 for filename in filenames:
155 # If we have a set of uis, check if we can skip this file
156 if uis is not None and filename in file_checks:
157 if not file_checks[filename](uis):
158 info('Skipping script:', filename)
159 continue
161 yield os.path.join(dirpath, filename)
164 # Recognized UIs: cli, gtk, qml, web (default: install all UIs)
165 uis = os.environ.get('GPODDER_INSTALL_UIS', None)
166 if uis is not None:
167 uis = uis.split()
169 # The CLI has a hard dependency on the Web UI
170 if 'cli' in uis and 'web' not in uis:
171 info('Adding Web UI as dependency of CLI')
172 uis.append('web')
174 info('Selected UIs (from $GPODDER_INSTALL_UIS):', uis)
177 try:
178 packages = list(sorted(find_packages(uis)))
179 scripts = list(sorted(find_scripts(uis)))
180 data_files = list(sorted(find_data_files(uis, scripts)))
181 except MissingFile, mf:
182 print >>sys.stderr, """
183 Missing file: %s
185 If you want to install, use "make install" instead of using
186 setup.py directly. See the README file for more information.
187 """ % mf.message
188 sys.exit(1)
191 setup(
192 name = 'gpodder',
193 version = metadata['version'],
194 description = metadata['tagline'],
195 license = metadata['license'],
196 url = metadata['url'],
198 author = author,
199 author_email = email,
201 package_dir = {'': 'src'},
202 packages = packages,
203 scripts = scripts,
204 data_files = data_files,