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/>.
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'):
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
)
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
)
70 # Skip desktop stuff if we don't have any UIs requiring it
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
)
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'):
92 basename
, _
= os
.path
.splitext(filename
)
93 result
= any(os
.path
.basename(s
) == basename
for s
in scripts
)
95 info('Skipping manpage without script:', filename
)
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'):
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
)
115 filenames
= filter(None, map(convert_filename
, 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
:
135 dirparts
= dirpath
.split(os
.sep
)
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
)
154 def find_scripts(uis
):
155 # Functions for scripts to check if they should be installed
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
)
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)
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')
182 info('Selected UIs (from $GPODDER_INSTALL_UIS):', uis
)
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
, """
193 If you want to install, use "make install" instead of using
194 setup.py directly. See the README file for more information.
201 version
= metadata
['version'],
202 description
= metadata
['tagline'],
203 license
= metadata
['license'],
204 url
= metadata
['url'],
207 author_email
= email
,
209 package_dir
= {'': 'src'},
212 data_files
= data_files
,