Get content_type from filename during zodb import
[cds-indico.git] / setup.py
blobbd31be259de5766fba323cf1d4ba9e4c747d145d
1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 # Autoinstalls setuptools if the user doesn't have them already
18 import ez_setup
19 ez_setup.use_setuptools()
21 import os
22 import getpass
23 import re
24 import shutil
25 import sys
26 from distutils.sysconfig import get_python_lib, get_python_version
27 from distutils.cmd import Command
28 from distutils.command import bdist
31 import pkg_resources
32 from setuptools.command import develop, sdist, bdist_egg, easy_install
33 from setuptools import setup, find_packages, findall
36 DEPENDENCY_URLS = ["http://indico-software.org/wiki/Admin/Installation/IndicoExtras"]
39 class vars(object):
40 '''Variable holder.'''
41 packageDir = None
42 versionVal = 'None'
43 accessuser = None
44 accessgroup = None
45 dbInstalledBySetupPy = False
46 binDir = None
47 documentationDir = None
48 configurationDir = None
49 htdocsDir = None
52 def compile_languages(cmd):
53 """
54 Compile all language files
55 Needed to generate binary distro
56 """
57 from babel.messages import frontend
59 compile_cmd = frontend.compile_catalog(cmd.distribution)
60 cmd.distribution._set_command_options(compile_cmd)
61 compile_cmd.finalize_options()
62 compile_cmd.run()
65 def read_requirements_file(fname):
66 with open(fname, 'r') as f:
67 return [dep.strip() for dep in f.readlines() if not (dep.startswith('-') or '://' in dep)]
70 def _generateDataPaths(x):
72 dataFilesDict = {}
74 for (baseDstDir, srcDir) in x:
75 for f in findall(srcDir):
76 dst_dir = os.path.join(baseDstDir,
77 os.path.relpath(os.path.dirname(f), srcDir))
78 if dst_dir not in dataFilesDict:
79 dataFilesDict[dst_dir] = []
80 dataFilesDict[dst_dir].append(f)
82 dataFiles = []
83 for k, v in dataFilesDict.items():
84 dataFiles.append((k, v))
86 return dataFiles
89 def _getInstallRequires():
90 """Returns external packages required by Indico
92 These are the ones needed for runtime."""
94 return read_requirements_file(os.path.join(os.path.dirname(__file__), 'requirements.txt'))
97 def _versionInit():
98 """Retrieves the version number from indico/MaKaC/__init__.py and returns it"""
100 from indico.MaKaC import __version__
101 v = __version__
103 print 'Indico %s' % v
105 return v
108 # Commands
109 class sdist_indico(sdist.sdist):
110 user_options = (sdist.sdist.user_options +
111 [('version=', None, 'version to distribute')])
112 version = 'dev'
114 def run(self):
115 sdist.sdist.run(self)
118 def _bdist_indico(dataFiles):
119 class bdist_indico(bdist.bdist):
120 def run(self):
121 compile_languages(self)
122 bdist.bdist.run(self)
124 bdist_indico.dataFiles = dataFiles
125 return bdist_indico
128 def _bdist_egg_indico(dataFiles):
129 class bdist_egg_indico(bdist_egg.bdist_egg):
130 def run(self):
131 compile_languages(self)
132 bdist_egg.bdist_egg.run(self)
134 bdist_egg_indico.dataFiles = dataFiles
135 return bdist_egg_indico
138 class develop_indico(develop.develop):
139 def run(self):
140 develop.develop.run(self)
142 # create symlink to legacy MaKaC dir
143 # this is so that the ".egg-link" created by the "develop" command works
144 if sys.platform in ["linux2", "darwin"] and not os.path.exists('MaKaC'):
145 os.symlink('indico/MaKaC', 'MaKaC')
147 # install dev dependencies
148 env = pkg_resources.Environment()
149 easy_install.main(read_requirements_file(os.path.join(os.path.dirname(__file__), 'requirements.dev.txt')))
150 env.scan()
153 class develop_config(develop_indico):
154 description = "prepares the current directory for Indico development"
155 user_options = (develop.develop.user_options +
156 [('www-uid=', None, "Set user for cache/log/db (typically apache user)"),
157 ('www-gid=', None, "Set group for cache/log/db (typically apache group)"),
158 ('http-port=', None, "Set port used by HTTP server"),
159 ('https-port=', None, "Set port used by HTTP server in HTTPS mode"),
160 ('zodb-port=', None, "Set port used by ZODB"),
161 ('smtp-port=', None, "Set port used for SMTP (e-mail sending)"),
162 ('use-apache', None, "Use apache (will chmod directories accordingly)")])
164 www_uid = None
165 www_gid = None
166 http_port = 8000
167 https_port = 8443
168 zodb_port = 9675
169 use_apache = False
170 smtp_port = 8025
172 def run(self):
173 # dependencies, links, etc...
174 develop_indico.run(self)
176 local = 'etc/indico.conf'
177 if os.path.exists(local):
178 print 'Upgrading existing etc/indico.conf...'
179 else:
180 print 'Creating new etc/indico.conf..'
181 shutil.copy('etc/indico.conf.sample', local)
183 upgrade_indico_conf(local, 'etc/indico.conf.sample', {
184 'BaseURL': 'http://localhost:{0}'.format(self.http_port),
185 'BaseSecureURL': 'https://localhost:{0}'.format(self.https_port),
186 'DBConnectionParams': ("localhost", int(self.zodb_port)),
187 'SmtpServer': ("localhost", int(self.smtp_port))
190 for f in [x for x in ('etc/zdctl.conf', 'etc/zodb.conf', 'etc/logging.conf') if not os.path.exists(x)]:
191 shutil.copy('%s.sample' % f, f)
193 print """\nIndico needs to store some information in the filesystem (database, cache, temporary files, logs...)
194 Please specify the directory where you'd like it to be placed.
195 (Note that putting it outside of your sourcecode tree is recommended)"""
196 prefixDirDefault = os.path.dirname(os.getcwd())
197 prefixDir = raw_input('Full path [%s]: ' % prefixDirDefault).strip()
199 if prefixDir == '':
200 prefixDir = prefixDirDefault
202 directories = dict((d, os.path.join(prefixDir, d)) for d in
203 ['db', 'log', 'tmp', 'cache', 'archive'])
205 print 'Creating directories...',
206 for d in directories.values():
207 if not os.path.exists(d):
208 os.makedirs(d)
209 print 'Done!'
211 # add existing dirs
212 directories.update(dict((d, os.path.join(os.getcwd(), 'indico', d)) for d in ['htdocs', 'bin', 'etc', 'doc']))
214 self._update_conf_dir_paths(local, directories)
216 # avoid modifying the htdocs folder permissions (it brings problems with git)
217 directories.pop('htdocs')
219 from MaKaC.consoleScripts.installBase import _databaseText, _findApacheUserGroup, _checkDirPermissions, \
220 _updateDbConfigFiles, _updateMaKaCEggCache
222 user = getpass.getuser()
223 sourcePath = os.getcwd()
225 if self.use_apache:
226 # find the apache user/group
227 user, group = _findApacheUserGroup(self.www_uid, self.www_gid)
228 _checkDirPermissions(directories, dbInstalledBySetupPy=directories['db'], accessuser=user, accessgroup=group)
230 _updateDbConfigFiles(os.path.join(sourcePath, 'etc'),
231 db=directories['db'],
232 log=directories['log'],
233 tmp=directories['tmp'],
234 port=self.zodb_port,
235 uid=user)
237 _updateMaKaCEggCache(os.path.join(os.path.dirname(__file__), 'indico', 'MaKaC', '__init__.py'),
238 directories['tmp'])
240 compile_languages(self)
241 print '''
243 ''' % _databaseText('etc')
245 def _update_conf_dir_paths(self, filePath, dirs):
246 fdata = open(filePath).read()
247 for dir in dirs.items():
248 d = dir[1].replace("\\", "/") # For Windows users
249 fdata = re.sub('\/opt\/indico\/%s' % dir[0], d, fdata)
250 open(filePath, 'w').write(fdata)
253 class egg_filename(Command):
254 description = "Get the file name of the generated egg"
255 user_options = []
256 boolean_options = []
258 def initialize_options(self):
259 pass
261 def finalize_options(self):
262 ei_cmd = self.ei_cmd = self.get_finalized_command("egg_info")
263 self.egg_info = ei_cmd.egg_info
265 basename = pkg_resources.Distribution(
266 None, None, ei_cmd.egg_name, ei_cmd.egg_version,
267 get_python_version(),
268 self.distribution.has_ext_modules() and pkg_utils.get_build_platform).egg_name()
270 print basename
272 def run(self):
273 pass
276 if __name__ == '__main__':
277 # Always load source from the current folder
278 sys.path = [os.path.abspath('indico')] + sys.path
280 #PWD_INDICO_CONF = 'etc/indico.conf'
281 #if not os.path.exists(PWD_INDICO_CONF):
282 # shutil.copy('etc/indico.conf.sample', PWD_INDICO_CONF)
284 from MaKaC.consoleScripts.installBase import setIndicoInstallMode, upgrade_indico_conf
286 setIndicoInstallMode(True)
288 x = vars()
289 x.packageDir = os.path.join(get_python_lib(), 'MaKaC')
291 x.binDir = 'bin'
292 x.documentationDir = 'doc'
293 x.configurationDir = 'etc'
294 x.htdocsDir = 'htdocs'
296 dataFiles = _generateDataPaths((('bin', 'bin'), ('doc', 'doc'), ('etc', 'etc'), ('migrations', 'migrations')))
298 foundPackages = list('MaKaC.{}'.format(pkg) for pkg in find_packages(where='indico/MaKaC'))
299 foundPackages.append('MaKaC')
300 foundPackages.append('htdocs')
302 # add our namespace package
303 foundPackages += ['indico.{}'.format(pkg) for pkg in find_packages(where='indico', exclude=['htdocs*', 'MaKaC*'])]
304 foundPackages.append('indico')
305 foundPackages += ['indico_zodbimport.{}'.format(pkg) for pkg in find_packages(where='indico_zodbimport')]
306 foundPackages.append('indico_zodbimport')
308 cmdclass = {'sdist': sdist_indico,
309 'bdist': _bdist_indico(dataFiles),
310 'bdist_egg': _bdist_egg_indico(dataFiles),
311 'develop_config': develop_config,
312 'develop': develop_indico,
313 'egg_filename': egg_filename}
315 setup(name="indico",
316 cmdclass=cmdclass,
317 version=_versionInit(),
318 description="Indico is a full-featured conference lifecycle management and meeting/lecture scheduling tool",
319 author="Indico Team",
320 author_email="indico-team@cern.ch",
321 url="http://indico-software.org",
322 download_url="http://indico-software.org/wiki/Releases/Indico1.2",
323 platforms=["any"],
324 long_description="Indico allows you to schedule conferences, from single talks to complex meetings with "
325 "sessions and contributions. It also includes an advanced user delegation mechanism, "
326 "allows paper reviewing, archival of conference information and electronic proceedings",
327 license="http://www.gnu.org/licenses/gpl-3.0.txt",
328 entry_points="""
329 [console_scripts]
330 indico_initial_setup = MaKaC.consoleScripts.indicoInitialSetup:main
331 indico_ctl = MaKaC.consoleScripts.indicoCtl:main
332 indico = indico.cli.manage:main
333 indico-zodbimport = indico_zodbimport.cli:main
335 [pytest11]
336 indico = indico.testing.pytest_plugin
338 [indico.zodb_importers]
339 roombooking = indico_zodbimport.modules.roombooking:RoomBookingImporter
340 payment = indico_zodbimport.modules.payment:PaymentImporter
341 api = indico_zodbimport.modules.api:APIImporter
342 users = indico_zodbimport.modules.users:UserImporter
343 groups = indico_zodbimport.modules.groups:GroupImporter
344 evaluation_alarms = indico_zodbimport.modules.evaluation_alarms:EvaluationAlarmImporter
345 static_sites = indico_zodbimport.modules.static_sites:StaticSitesImporter
346 event_alarms = indico_zodbimport.modules.event_alarms:EventAlarmImporter
347 legacy_events = indico_zodbimport.modules.legacy_events:LegacyEventImporter
348 legacy_categories = indico_zodbimport.modules.legacy_categories:LegacyCategoryImporter
349 event_logs = indico_zodbimport.modules.event_logs:EventLogImporter
350 event_notes = indico_zodbimport.modules.event_notes:EventNoteImporter
351 attachments = indico_zodbimport.modules.attachments:AttachmentImporter
352 """,
353 zip_safe=False,
354 packages=foundPackages,
355 package_dir={'indico': 'indico',
356 'htdocs': os.path.join('indico', 'htdocs'),
357 'MaKaC': os.path.join('indico', 'MaKaC')},
358 package_data={'indico': ['*.*']},
359 include_package_data=True,
360 namespace_packages=['indico'],
361 install_requires=_getInstallRequires(),
362 data_files=dataFiles,
363 dependency_links=DEPENDENCY_URLS)