forked from MarkusHackspacher/gpodder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
222 lines (175 loc) · 7.36 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
216
217
218
219
220
221
222
#!/usr/bin/env python3
#
# gPodder - A media aggregator and podcast client
# Copyright (c) 2005-2018 The gPodder Team
#
# gPodder is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# gPodder is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
import re
import sys
from setuptools import setup
installing = ('install' in sys.argv and '--help' not in sys.argv)
# setuptools depends on setup.py being executed from the same dir.
# Most of our custom commands work either way, but this makes
# it work in all cases.
os.chdir(os.path.dirname(os.path.realpath(__file__)))
# Read the metadata from gPodder's __init__ module (doesn't need importing)
main_module = open('src/gpodder/__init__.py', 'r', encoding='utf-8').read()
metadata = dict(re.findall("__([a-z_]+)__\\s*=\\s*'([^']+)'", main_module))
author, email = re.match(r'^(.*) <(.*)>$', metadata['author']).groups()
class MissingFile(BaseException):
pass
def info(message, item=None):
print('=>', message, item if item is not None else '')
def find_data_files(uis, scripts):
# Support for installing only a subset of translations
linguas = os.environ.get('LINGUAS', None)
if linguas is not None:
linguas = linguas.split()
info('Selected languages (from $LINGUAS):', linguas)
for dirpath, dirnames, filenames in os.walk('share'):
if not filenames:
continue
# Skip data folders if we don't want the corresponding UI
share_gpodder_ui = os.path.join('share', 'gpodder', 'ui')
if uis is not None and dirpath.startswith(share_gpodder_ui):
dirparts = dirpath.split(os.sep)
if not any(part in uis for part in dirparts):
info('Skipping folder:', dirpath)
continue
# Skip translations if $LINGUAS is set
share_locale = os.path.join('share', 'locale')
if linguas is not None and dirpath.startswith(share_locale):
_, _, language, _ = dirpath.split(os.sep, 3)
if language not in linguas:
info('Skipping translation:', language)
continue
# Skip desktop stuff if we don't have any UIs requiring it
skip_folder = False
uis_requiring_freedesktop = ('gtk',)
freedesktop_folders = ('applications', 'dbus-1', 'icons', 'metainfo')
for folder in freedesktop_folders:
share_folder = os.path.join('share', folder)
if dirpath.startswith(share_folder) and uis is not None:
if not any(ui in uis_requiring_freedesktop for ui in uis):
info('Skipping freedesktop.org folder:', dirpath)
skip_folder = True
break
if skip_folder:
continue
# Skip manpages if their scripts are not going to be installed
share_man = os.path.join('share', 'man')
if dirpath.startswith(share_man):
def have_script(filename):
if not filename.endswith('.1'):
return True
basename, _ = os.path.splitext(filename)
result = any(os.path.basename(s) == basename for s in scripts)
if not result:
info('Skipping manpage without script:', filename)
return result
filenames = list(filter(have_script, filenames))
def convert_filename(filename):
filename = os.path.join(dirpath, filename)
# Skip header files generated by "make messages"
if filename.endswith('.h'):
return None
# Skip .in files, but check if their target exist
if filename.endswith('.in'):
filename = filename[:-3]
if installing and not os.path.exists(filename):
raise MissingFile(filename)
return None
return filename
filenames = [_f for _f in map(convert_filename, filenames) if _f]
if filenames:
# Some distros/ports install manpages into $PREFIX/man instead
# of $PREFIX/share/man (e.g. FreeBSD). To allow this, we strip
# the "share/" part if the variable GPODDER_MANPATH_NO_SHARE is
# set to any value in the environment.
if dirpath.startswith(share_man):
if 'GPODDER_MANPATH_NO_SHARE' in os.environ:
dirpath = dirpath.replace(share_man, 'man')
yield (dirpath, filenames)
def find_packages(uis):
src_gpodder = os.path.join('src', 'gpodder')
for dirpath, dirnames, filenames in os.walk(src_gpodder):
if '__init__.py' not in filenames:
continue
skip = False
dirparts = dirpath.split(os.sep)
dirparts.pop(0)
package = '.'.join(dirparts)
# Extract all parts of the package name ending in "ui"
ui_parts = [p for p in dirparts if p.endswith('ui')]
if uis is not None and ui_parts:
# Strip the trailing "ui", e.g. "gtkui" -> "gtk"
folder_uis = [p[:-2] for p in ui_parts]
for folder_ui in folder_uis:
if folder_ui not in uis:
info('Skipping package:', package)
skip = True
break
if not skip:
yield package
def find_scripts(uis):
# Functions for scripts to check if they should be installed
file_checks = {
'gpo': lambda uis: 'cli' in uis,
'gpodder': lambda uis: any(ui in uis for ui in ('gtk',)),
}
for dirpath, dirnames, filenames in os.walk('bin'):
for filename in filenames:
# If we have a set of uis, check if we can skip this file
if uis is not None and filename in file_checks:
if not file_checks[filename](uis):
info('Skipping script:', filename)
continue
yield os.path.join(dirpath, filename)
# Recognized UIs: cli, gtk (default: install all UIs)
uis = os.environ.get('GPODDER_INSTALL_UIS', None)
if uis is not None:
uis = uis.split()
info('Selected UIs (from $GPODDER_INSTALL_UIS):', uis)
try:
packages = sorted(find_packages(uis))
scripts = sorted(find_scripts(uis))
data_files = sorted(find_data_files(uis, scripts))
except MissingFile as mf:
print("""
Missing file: %s
If you want to install, use "make install" instead of using
setup.py directly. See the README file for more information.
""" % mf, file=sys.stderr)
sys.exit(1)
setup(
name='gpodder',
version=metadata['version'],
description=metadata['tagline'],
license=metadata['license'],
url=metadata['url'],
author=author,
author_email=email,
package_dir={'': 'src'},
packages=packages,
scripts=scripts,
data_files=data_files,
install_requires=[
"podcastparser>=0.6.0",
"mygpoclient>=1.7",
"dbus-python;platform_system=='Linux'",
"PyGObject",
]
)