1 # -*- coding: utf-8 -*-
4 ## This file is part of CDS Indico.
5 ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
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
23 ez_setup
.use_setuptools()
32 from distutils
.sysconfig
import get_python_lib
33 from distutils
.cmd
import Command
34 from distutils
.command
import bdist
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':
50 '''Variable holder.'''
55 dbInstalledBySetupPy
= False
57 documentationDir
= None
58 configurationDir
= None
61 ### Methods required by setup() ##############################################
63 def _generateDataPaths(x
):
67 for (baseDstDir
, files
, remove_first_x_chars
) in x
:
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
)
75 for k
, v
in dataFilesDict
.items():
76 dataFiles
.append((k
, v
))
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.
90 # setup expects a list like this (('foo/bar/baz', 'wiki.py'),
93 # What we do below is transform a list like this:
94 # (('foo', 'bar/baz/wiki.py'),
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)))
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')
128 '''Retrieves the version number from indico/MaKaC/__init__.py and returns it'''
131 from indico
.MaKaC
import __version__
134 print('Version being packaged: %s' % v
)
138 ### Commands ###########################################################
139 class sdist_indico(sdist
.sdist
):
140 user_options
= sdist
.sdist
.user_options
+ \
141 [('version=', None, 'version to distribute')]
146 sdist
.sdist
.run(self
)
150 def jsCompress(self
):
151 from MaKaC
.consoleScripts
.installBase
import 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
):
161 compileAllLanguages()
162 bdist
.bdist
.run(self
)
164 bdist_indico
.dataFiles
= dataFiles
167 def _bdist_egg_indico(dataFiles
):
168 class bdist_egg_indico(bdist_egg
.bdist_egg
, jsdist_indico
):
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"
182 def initialize_options(self
):
185 def finalize_options(self
):
189 from MaKaC
.consoleScripts
.installBase
import jsCompress
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
)
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
)])
209 return env
[str(dist
)][0]
212 class fetchdeps_indico(fetchdeps
, Command
):
213 description
= "fetch all the dependencies needed to run Indico"
217 def initialize_options(self
):
220 def finalize_options(self
):
224 class develop_indico(Command
):
225 description
= "prepares the current directory for Indico development"
229 def initialize_options(self
):
232 def finalize_options(self
):
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')
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()
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
):
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
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()
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"
309 def initialize_options(self
): pass
311 def finalize_options(self
): pass
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() )
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)
331 x
.packageDir
= os
.path
.join(get_python_lib(), 'MaKaC')
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
),
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",
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' },
362 'console_scripts': [ 'taskDaemon = MaKaC.consoleScripts.taskDaemon:main',
363 'indico_initial_setup = MaKaC.consoleScripts.indicoInitialSetup:main',
364 'indico_ctl = MaKaC.consoleScripts.indicoCtl:main',
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,