4 # gPodder - A media aggregator and podcast client
5 # Copyright (c) 2005-2018 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/>.
25 from setuptools
import setup
27 installing
= ('install' in sys
.argv
and '--help' not in sys
.argv
)
29 # setuptools depends on setup.py being executed from the same dir.
30 # Most of our custom commands work either way, but this makes
31 # it work in all cases.
32 os
.chdir(os
.path
.dirname(os
.path
.realpath(__file__
)))
35 class MissingFile(BaseException
):
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',)
73 freedesktop_folders
= ('applications', 'dbus-1', 'icons', 'metainfo')
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
= list(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
= [_f
for _f
in map(convert_filename
, filenames
) if _f
]
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
= [p
for p
in dirparts
if p
.endswith('ui')]
141 if uis
is not None and ui_parts
:
142 # Strip the trailing "ui", e.g. "gtkui" -> "gtk"
143 folder_uis
= [p
[:-2] for p
in 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 ('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 (default: install all UIs)
173 uis
= os
.environ
.get('GPODDER_INSTALL_UIS', None)
177 info('Selected UIs (from $GPODDER_INSTALL_UIS):', uis
)
181 packages
= sorted(find_packages(uis
))
182 scripts
= sorted(find_scripts(uis
))
183 data_files
= sorted(find_data_files(uis
, scripts
))
184 except MissingFile
as mf
:
188 If you want to install, use "make install" instead of using
189 setup.py directly. See the README file for more information.
190 """ % mf
, file=sys
.stderr
)
195 package_dir
={'': 'src'},
198 data_files
=data_files
,