#!/usr/bin/env python import os import os.path import sys import string from glob import glob from distutils.core import setup from distutils.command.install import install from distutils.command.install_data import install_data from distutils.command.install_scripts import install_scripts from stat import ST_MODE, S_ISDIR import cmmlwiki PACKAGE = 'CMMLWiki' VERSION = str(cmmlwiki.__version__) URL = cmmlwiki.__url__ LICENSE = cmmlwiki.__license__ if sys.version_info<(2,1): print >>sys.stderr, "You need at least Python 2.1 for %s %s" % (PACKAGE, VERSION) sys.exit(3) def _p(unix_path): return os.path.normpath(unix_path) class my_install (install): def run (self): self.siteconfig() def siteconfig(self): htdocs_dir = os.path.join(self.prefix, 'share', 'cmmlwiki', 'htdocs') f = open(_p('cmmlwiki/siteconfig.py'),'w') f.write(""" # PLEASE DO NOT EDIT THIS FILE! # This file was autogenerated when installing %(cmmlwiki)s %(ver)s. # __default_htdocs_dir__ = %(htdocs)r """ % {'cmmlwiki':PACKAGE, 'ver':VERSION, 'htdocs':_p(htdocs_dir) }) f.close() # Run actual install install.run(self) print print "Thank you for choosing CMMLWiki %s. Enjoy your stay!" % VERSION print class my_install_scripts (install_scripts): def initialize_options (self): install_scripts.initialize_options(self) self.install_data = None def finalize_options (self): install_scripts.finalize_options(self) self.set_undefined_options('install', ('install_data', 'install_data')) def run (self): if not self.skip_build: self.run_command('build_scripts') self.outfiles = [] self.mkpath(os.path.normpath(self.install_dir)) ofile, copied = self.copy_file(os.path.join(self.build_dir, 'cmmlwiki-admin'), self.install_dir) if copied: self.outfiles.append(ofile) ofile, copied = self.copy_file(os.path.join(self.build_dir, 'cmmlwiki-import'), self.install_dir) if copied: self.outfiles.append(ofile) ofile, copied = self.copy_file(os.path.join(self.build_dir, 'cmmlwiki-batch-import'), self.install_dir) if copied: self.outfiles.append(ofile) cgi_dir = os.path.join(self.install_data, 'share', 'cmmlwiki', 'cgi-bin') if not os.path.exists(cgi_dir): os.makedirs(cgi_dir) ofile, copied = self.copy_file(os.path.join(self.build_dir, 'cmmlwiki.cgi'), cgi_dir) if copied: self.outfiles.append(ofile) if os.name == 'posix': # Set the executable bits (owner, group, and world) on # all the scripts we just installed. for file in self.get_outputs(): if not self.dry_run: mode = ((os.stat(file)[ST_MODE]) | 0555) & 07777 os.chmod(file, mode) class my_install_data (install_data): def run (self): install_data.run(self) if os.name == 'posix' and not self.dry_run: # Make the data files we just installed world-readable, # and the directories world-executable as well. for path in self.get_outputs(): mode = os.stat(path)[ST_MODE] if S_ISDIR(mode): mode |= 011 mode |= 044 os.chmod(path, mode) setup(name="cmmlwiki", description="Collaborative media annotations editing environment", long_description=\ """ CMMLWiki is a web-based system for organizing and editing media annotations. """, version=VERSION, author="CSIRO Australia", author_email="annodex-dev@annodex.net", license=LICENSE, url=URL, packages=['cmmlwiki'], data_files=[(_p('share/cmmlwiki/htdocs'), glob(_p('htdocs/*.*')) + [_p('htdocs/README')]), (_p('share/cmmlwiki/htdocs/images'), glob(_p('htdocs/images/*'))), (_p('share/cmmlwiki/htdocs/stylesheets'), glob(_p('htdocs/stylesheets/*'))), (_p('share/cmmlwiki/htdocs/plugins'), glob(_p('htdocs/plugins/*'))), (_p('share/cmmlwiki/htdocs/javascripts'), glob(_p('htdocs/javascripts/*')))], scripts=[_p('scripts/cmmlwiki-admin'), _p('scripts/cmmlwiki-import'), _p('scripts/cmmlwiki-batch-import'), _p('cgi-bin/cmmlwiki.cgi'),], cmdclass = {'install': my_install, 'install_scripts': my_install_scripts, 'install_data': my_install_data})