#! /usr/bin/env python import os import subprocess from distutils.core import setup from distutils import cmd from distutils.command.install_data import install_data as _install_data from distutils.command.build import build as _build from distutils.command.sdist import sdist local_cfg = None if os.path.exists('wcs/wcs_cfg.py'): local_cfg = file('wcs/wcs_cfg.py').read() os.unlink('wcs/wcs_cfg.py') class build_trans(cmd.Command): description = 'Compile .po files into .mo files' def initialize_options(self): pass def finalize_options(self): pass def run(self): po_dir = os.path.join(os.path.dirname(os.curdir), 'po') for path, names, filenames in os.walk(po_dir): for f in filenames: if f.endswith('.po'): lang = f[:-3] src = os.path.join(path, f) dest_path = os.path.join('build', 'locale', lang, 'LC_MESSAGES') dest = os.path.join(dest_path, 'wcs.mo') if not os.path.exists(dest_path): os.makedirs(dest_path) if not os.path.exists(dest): print 'Compiling %s' % src subprocess.call(['msgfmt', src, '--output-file', dest]) else: src_mtime = os.stat(src)[8] dest_mtime = os.stat(dest)[8] if src_mtime > dest_mtime: print 'Compiling %s' % src subprocess.call(['msgfmt', src, '--output-file', dest]) class build(_build): sub_commands = _build.sub_commands + [('build_trans', None)] def run(self): _build.run(self) class eo_sdist(sdist): def run(self): print "creating VERSION file" if os.path.exists('VERSION'): os.remove('VERSION') version = get_version() version_file = open('VERSION', 'w') version_file.write(version) version_file.close() sdist.run(self) print "removing VERSION file" if os.path.exists('VERSION'): os.remove('VERSION') class install_data(_install_data): def run(self): for lang in os.listdir('build/locale/'): lang_dir = os.path.join('share', 'locale', lang, 'LC_MESSAGES') lang_file = os.path.join('build', 'locale', lang, 'LC_MESSAGES', 'wcs.mo') self.data_files.append( (lang_dir, [lang_file]) ) _install_data.run(self) def data_tree(destdir, sourcedir): extensions = ['.css', '.png', '.jpeg', '.jpg', '.gif', '.xml', '.html', '.js', '.ezt', '.dat'] r = [] for root, dirs, files in os.walk(sourcedir): l = [os.path.join(root, x) for x in files if os.path.splitext(x)[1] in extensions] r.append( (root.replace(sourcedir, destdir, 1), l) ) for vcs_dirname in ('CVS', '.svn', '.bzr', '.git'): if vcs_dirname in dirs: dirs.remove(vcs_dirname) return r def get_version(): if os.path.exists('VERSION'): version_file = open('VERSION', 'r') version = version_file.read() version_file.close() return version if os.path.exists('.git'): p = subprocess.Popen(['git','describe','--match=v*'], stdout=subprocess.PIPE) result = p.communicate()[0] version = result.split()[0][1:] version = version.replace('-', '.') return version from wcs import __version__ as version return version cmdclass = { 'build': build, 'build_trans': build_trans, 'install_data': install_data, 'sdist': eo_sdist } setup( name = 'wcs', version = get_version(), maintainer = "Frederic Peters", maintainer_email = "fpeters@entrouvert.com", url = "http://wcs.labs.libre-entreprise.org", package_dir = { 'wcs': 'wcs' }, packages = ['wcs', 'wcs.admin', 'wcs.backoffice', 'wcs.ctl', 'wcs.ctl.Bouncers', 'wcs.forms', 'wcs.wf', 'wcs.qommon', 'wcs.qommon.admin', 'wcs.qommon.backoffice', 'wcs.qommon.ident', 'wcs.qommon.vendor'], cmdclass = cmdclass, scripts = ['wcsctl.py'], data_files = data_tree('share/wcs/web/', 'data/web/') + \ data_tree('share/wcs/themes/', 'data/themes/') + \ data_tree('share/wcs/vendor/', 'data/vendor/') + \ data_tree('share/wcs/qommon/', 'wcs/qommon/static/') ) if local_cfg: file('wcs/wcs_cfg.py', 'w').write(local_cfg)