[IMP] Added description display for the new fields
[cds-indico.git] / setup.py
blob29f2e99a50d65355db21dcf78bebaf243d7668cb
1 # -*- coding: utf-8 -*-
2 ##
3 ##
4 ## This file is part of CDS Indico.
5 ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
6 ##
7 ## CDS Indico is free software; you can redistribute it and/or
8 ## modify it under the terms of the GNU General Public License as
9 ## published by the Free Software Foundation; either version 2 of the
10 ## License, or (at your option) any later version.
12 ## CDS Indico is distributed in the hope that it will be useful, but
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ## General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
18 ## along with CDS Indico; if not, write to the Free Software Foundation, Inc.,
19 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21 # Autoinstalls setuptools if the user doesn't have them already
22 import ez_setup
23 ez_setup.use_setuptools()
25 import commands
26 import getopt
27 import os
28 import re
29 import shutil
30 import string
31 import sys
32 from distutils.sysconfig import get_python_lib
33 from distutils.cmd import Command
34 from distutils.command import bdist
36 import pkg_resources
37 from setuptools.command import develop, install, sdist, bdist_egg, easy_install
38 from setuptools import setup, find_packages, findall
39 from subprocess import Popen, PIPE
41 EXTRA_RESOURCES_URL = "http://cdswaredev.cern.ch/indico/wiki/Admin/Installation/IndicoExtras"
43 if sys.platform == 'linux2':
44 import pwd
45 import grp
47 import tests
49 class vars(object):
50 '''Variable holder.'''
51 packageDir = None
52 versionVal = 'None'
53 accessuser = None
54 accessgroup = None
55 dbInstalledBySetupPy = False
56 binDir = None
57 documentationDir = None
58 configurationDir = None
59 htdocsDir = None
61 ### Methods required by setup() ##############################################
63 def _generateDataPaths(x):
65 dataFilesDict = {}
67 for (baseDstDir, files, remove_first_x_chars) in x:
68 for f in files:
69 dst_dir = os.path.join(baseDstDir, os.path.dirname(f)[remove_first_x_chars:])
70 if dst_dir not in dataFilesDict:
71 dataFilesDict[dst_dir] = []
72 dataFilesDict[dst_dir].append(f)
74 dataFiles = []
75 for k, v in dataFilesDict.items():
76 dataFiles.append((k, v))
78 return dataFiles
80 def _getDataFiles(x):
81 """
82 Returns a fully populated data_files ready to be fed to setup()
84 WARNING: when creating a bdist_egg we need to include files inside bin,
85 doc, config & htdocs into the egg therefore we cannot fetch indico.conf
86 values directly because they will not refer to the proper place. We
87 include those files in the egg's root folder.
88 """
90 # setup expects a list like this (('foo/bar/baz', 'wiki.py'),
91 # ('a/b/c', 'd.jpg'))
93 # What we do below is transform a list like this:
94 # (('foo', 'bar/baz/wiki.py'),
95 # ('a', 'b/c/d.jpg'))
97 # first into a dict and then into a pallatable form for setuptools.
99 # This re will be used to filter out etc/*.conf files and therefore not overwritting them
100 isAConfRe = re.compile('etc\/[^/]+\.conf$')
102 dataFiles = _generateDataPaths((('bin', findall('bin'), 4),
103 ('doc', findall('doc'), 4),
104 ('etc', [xx for xx in findall('etc') if not isAConfRe.search(xx)], 4),
105 ('htdocs', findall('indico/htdocs'), 14)))
106 return dataFiles
112 def _getInstallRequires():
113 '''Returns external packages required by Indico
115 These are the ones needed for runtime.'''
117 base = ['pytz', 'zope.index', 'zope.interface', 'simplejson', 'suds', 'cds-indico-extras']
118 if sys.version_info[1] < 5: #for Python older than 2.5
119 base.append('hashlib') # hashlib isn't a part of Python older than 2.5
120 base.append('ZODB3>=3.8,<3.9.0a')
121 else: #for Python 2.5+
122 base.append('ZODB3>=3.8')
124 return base
127 def _versionInit():
128 '''Retrieves the version number from indico/MaKaC/__init__.py and returns it'''
130 import datetime
131 from indico.MaKaC import __version__
132 v = __version__
134 print('Version being packaged: %s' % v)
136 return v
138 ### Commands ###########################################################
139 class sdist_indico(sdist.sdist):
140 user_options = sdist.sdist.user_options + \
141 [('version=', None, 'version to distribute')]
142 version = 'dev'
144 def run(self):
145 global x
146 sdist.sdist.run(self)
149 class jsdist_indico:
150 def jsCompress(self):
151 from MaKaC.consoleScripts.installBase import jsCompress
152 jsCompress()
153 self.dataFiles += _generateDataPaths([('htdocs/js/presentation/pack', findall('indico/htdocs/js/presentation/pack'), 35),
154 ('htdocs/js/indico/pack', findall('indico/htdocs/js/indico/pack'), 29)])
157 def _bdist_indico(dataFiles):
158 class bdist_indico(bdist.bdist, jsdist_indico):
159 def run(self):
160 self.jsCompress()
161 compileAllLanguages()
162 bdist.bdist.run(self)
164 bdist_indico.dataFiles = dataFiles
165 return bdist_indico
167 def _bdist_egg_indico(dataFiles):
168 class bdist_egg_indico(bdist_egg.bdist_egg, jsdist_indico):
169 def run(self):
170 self.jsCompress()
171 compileAllLanguages()
172 bdist_egg.bdist_egg.run(self)
174 bdist_egg_indico.dataFiles = dataFiles
175 return bdist_egg_indico
177 class jsbuild(Command):
178 description = "minifies and packs javascript files"
179 user_options = []
180 boolean_options = []
182 def initialize_options(self):
183 pass
185 def finalize_options(self):
186 pass
188 def run(self):
189 from MaKaC.consoleScripts.installBase import jsCompress
190 jsCompress()
192 class fetchdeps:
193 def run(self):
194 print "Checking if dependencies need to be installed..."
196 wset = pkg_resources.working_set
198 wset.resolve(map(pkg_resources.Requirement.parse, _getInstallRequires()),
199 installer = self._installMissing)
201 print "Done!"
204 def _installMissing(self, dist):
205 env = pkg_resources.Environment()
206 print dist, EXTRA_RESOURCES_URL
207 easy_install.main(["-f", EXTRA_RESOURCES_URL, "-U", str(dist)])
208 env.scan()
209 return env[str(dist)][0]
212 class fetchdeps_indico(fetchdeps, Command):
213 description = "fetch all the dependencies needed to run Indico"
214 user_options = []
215 boolean_options = []
217 def initialize_options(self):
218 pass
220 def finalize_options(self):
221 pass
224 class develop_indico(Command):
225 description = "prepares the current directory for Indico development"
226 user_options = []
227 boolean_options = []
229 def initialize_options(self):
230 pass
232 def finalize_options(self):
233 pass
235 def run(self):
237 fetchdeps().run()
239 local = 'etc/indico.conf'
240 if os.path.exists(local):
241 print 'Upgrading existing etc/indico.conf..'
242 upgrade_indico_conf(local, 'etc/indico.conf.sample')
243 else:
244 print 'Creating new etc/indico.conf..'
245 shutil.copy('etc/indico.conf.sample', local)
247 for f in [x for x in ('etc/zdctl.conf', 'etc/zodb.conf', 'etc/logging.conf') if not os.path.exists(x)]:
248 shutil.copy('%s.sample' % f, f)
250 print """\nIndico needs to store some information in the filesystem (database, cache, temporary files, logs...)
251 Please specify the directory where you'd like it to be placed.
252 (Note that putting it outside of your sourcecode tree is recommended)"""
253 prefixDir = raw_input('[%s]: ' % os.getcwd()).strip()
255 if prefixDir == '':
256 prefixDir = os.getcwd()
258 directories = dict((d, os.path.join(prefixDir, d)) for d in
259 ['db', 'log', 'tmp', 'cache', 'archive'])
261 print 'Creating directories...',
262 for d in directories.values():
263 if not os.path.exists(d):
264 os.makedirs(d)
265 print 'Done!'
267 directories['htdocs'] = os.path.join(os.getcwd(), 'indico', 'htdocs')
268 directories['bin'] = os.path.join(os.getcwd(), 'bin')
269 directories['etc'] = os.path.join(os.getcwd(), 'etc')
270 directories['doc'] = os.path.join(os.getcwd(), 'doc')
272 self._update_conf_dir_paths(local, directories)
274 directories.pop('htdocs') #avoid modifying the htdocs folder permissions (it brings problems with git)
276 from MaKaC.consoleScripts.installBase import _databaseText, _findApacheUserGroup, _checkDirPermissions, _updateDbConfigFiles, _updateMaKaCEggCache
278 user = ''
280 sourcePath = os.getcwd()
282 if sys.platform == "linux2":
283 # find the apache user/group
284 user, group = _findApacheUserGroup(None, None)
285 _checkDirPermissions(directories, dbInstalledBySetupPy = directories['db'], accessuser = user, accessgroup = group)
287 _updateDbConfigFiles(directories['db'], directories['log'], os.path.join(sourcePath, 'etc'), directories['tmp'], user)
289 _updateMaKaCEggCache(os.path.join(os.path.dirname(__file__), 'indico', 'MaKaC', '__init__.py'), directories['tmp'])
291 updateIndicoConfPathInsideMaKaCConfig(os.path.join(os.path.dirname(__file__), ''), 'indico/MaKaC/common/MaKaCConfig.py')
292 compileAllLanguages()
293 print '''
295 ''' % _databaseText('etc')
297 def _update_conf_dir_paths(self, filePath, dirs):
298 fdata = open(filePath).read()
299 for dir in dirs.items():
300 d = dir[1].replace("\\","/") # For Windows users
301 fdata = re.sub('\/opt\/indico\/%s'%dir[0], d, fdata)
302 open(filePath, 'w').write(fdata)
304 class tests_indico(Command):
305 description = "run the test suite"
306 user_options = []
307 boolean_options = []
309 def initialize_options(self): pass
311 def finalize_options(self): pass
313 def run(self):
314 p = Popen("%s tests/__init__.py" % sys.executable, shell=True, stdout=PIPE, stderr=PIPE)
315 out = string.join(p.stdout.readlines() )
316 outerr = string.join(p.stderr.readlines() )
317 print out, outerr
320 if __name__ == '__main__':
321 sys.path = [os.path.abspath('indico')] + sys.path # Always load source from the current folder
323 #PWD_INDICO_CONF = 'etc/indico.conf'
324 #if not os.path.exists(PWD_INDICO_CONF):
325 # shutil.copy('etc/indico.conf.sample', PWD_INDICO_CONF)
327 from MaKaC.consoleScripts.installBase import *
328 setIndicoInstallMode(True)
330 x = vars()
331 x.packageDir = os.path.join(get_python_lib(), 'MaKaC')
334 x.binDir = 'bin'
335 x.documentationDir = 'doc'
336 x.configurationDir = 'etc'
337 x.htdocsDir = 'htdocs'
339 dataFiles = _getDataFiles(x)
341 setup(name = "cds-indico",
342 cmdclass = {'sdist': sdist_indico,
343 'bdist': _bdist_indico(dataFiles),
344 'bdist_egg': _bdist_egg_indico(dataFiles),
345 'jsbuild': jsbuild,
346 'tests': tests_indico,
347 'fetchdeps': fetchdeps_indico,
348 'develop_config': develop_indico,
351 version = _versionInit(),
352 description = "Indico is a full-featured conference lifecycle management and meeting/lecture scheduling tool",
353 author = "Indico Team",
354 author_email = "indico-team@cern.ch",
355 url = "http://cdswaredev.cern.ch/indico",
356 download_url = "http://cdswaredev.cern.ch/indico/wiki/Releases/Indico0.97.0",
357 platforms = ["any"],
358 long_description = "Indico allows you to schedule conferences, from single talks to complex meetings with sessions and contributions. It also includes an advanced user delegation mechanism, allows paper reviewing, archival of conference information and electronic proceedings",
359 license = "http://www.gnu.org/licenses/gpl-2.0.txt",
360 package_dir = { '': 'indico' },
361 entry_points = {
362 'console_scripts': [ 'taskDaemon = MaKaC.consoleScripts.taskDaemon:main',
363 'indico_initial_setup = MaKaC.consoleScripts.indicoInitialSetup:main',
364 'indico_ctl = MaKaC.consoleScripts.indicoCtl:main',
367 zip_safe = False,
368 packages = find_packages(where = 'indico', exclude = ('htdocs',)),
369 install_requires = _getInstallRequires(),
370 data_files = dataFiles,
371 package_data = {'indico': ['*.*'] },
372 include_package_data = True,
373 dependency_links = [
374 EXTRA_RESOURCES_URL