home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / setup.py < prev    next >
Text File  |  2001-01-16  |  7KB  |  178 lines

  1. #!/usr/bin/env python2
  2.  
  3. #    Copyright (C) 2000,2001  Bastian Kleineidam
  4. #
  5. #    This program is free software; you can redistribute it and/or modify
  6. #    it under the terms of the GNU General Public License as published by
  7. #    the Free Software Foundation; either version 2 of the License, or
  8. #    (at your option) any later version.
  9. #
  10. #    This program is distributed in the hope that it will be useful,
  11. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #    GNU General Public License for more details.
  14. #
  15. #    You should have received a copy of the GNU General Public License
  16. #    along with this program; if not, write to the Free Software
  17. #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. import os, string, re
  20. from types import StringType, TupleType
  21. from distutils.core import setup, Extension, DEBUG
  22. from distutils.dist import Distribution
  23. from distutils.command.install import install
  24. from distutils.command.config import config
  25. from distutils.command.install_data import install_data
  26. from distutils.file_util import write_file
  27. from distutils import util
  28.  
  29. class MyInstall(install):
  30.     def run(self):
  31.         install.run(self)
  32.         # we have to write a configuration file because we need the
  33.         # <install_data> directory (and other stuff like author, url, ...)
  34.         data = []
  35.         for d in ['purelib', 'platlib', 'lib', 'headers', 'scripts', 'data']:
  36.             attr = 'install_'+d
  37.             if self.root:
  38.                 val = getattr(self, attr)[len(self.root):]
  39.             else:
  40.                 val = getattr(self, attr)
  41.             if attr=="install_data":
  42.                 data.append('config_dir = %s' % `os.path.join(val,
  43.                             'share/webcleaner')`)
  44.             data.append("%s = %s" % (attr, `val`))
  45.         from pprint import pformat
  46.         data.append('outputs = %s' % pformat(self.get_outputs()))
  47.         self.distribution.create_conf_file(self.install_lib, data)
  48.  
  49.     # sent a patch for this, but here it is for compatibility
  50.     def dump_dirs (self, msg):
  51.         if DEBUG:
  52.             from distutils.fancy_getopt import longopt_xlate
  53.             print msg + ":"
  54.             for opt in self.user_options:
  55.                 opt_name = opt[0]
  56.                 if opt_name[-1] == "=":
  57.                     opt_name = opt_name[0:-1]
  58.                 if self.negative_opt.has_key(opt_name):
  59.                     opt_name = string.translate(self.negative_opt[opt_name],
  60.                                                 longopt_xlate)
  61.                     val = not getattr(self, opt_name)
  62.                 else:
  63.                     opt_name = string.translate(opt_name, longopt_xlate)
  64.                     val = getattr(self, opt_name)
  65.                 print "  %s: %s" % (opt_name, val)
  66.  
  67. class MyInstallData(install_data):
  68.     """My own data installer to handle .man pages"""
  69.     def run (self):
  70.         self.mkpath(self.install_dir)
  71.         for f in self.data_files:
  72.             if type(f) == StringType:
  73.                 # it's a simple file, so copy it
  74.                 if self.warn_dir:
  75.                     self.warn("setup script did not provide a directory for "
  76.                               "'%s' -- installing right in '%s'" %
  77.                               (f, self.install_dir))
  78.                 self._install_file(f, self.install_dir)
  79.             else:
  80.                 # it's a tuple with path to install to and a list of files
  81.                 dir = f[0]
  82.                 if not os.path.isabs(dir):
  83.                     dir = os.path.join(self.install_dir, dir)
  84.                 elif self.root:
  85.                     dir = change_root(self.root, dir)
  86.                 self.mkpath(dir)
  87.                 for data in f[1]:
  88.                     self._install_file(data, dir)
  89.  
  90.     def _install_file(self, filename, dirname):
  91.         out = self.copy_file(filename, dirname)
  92.         if type(out) == TupleType:
  93.             out = out[0]
  94.         # match for man pages .[0-9]
  95.         if re.search(r'/man/.+\.\d$', out):
  96.             out = out+".gz"
  97.         self.outfiles.append(out)
  98.  
  99.  
  100.  
  101. class MyDistribution(Distribution):
  102.     def __init__(self, attrs=None):
  103.         Distribution.__init__(self, attrs=attrs)
  104.         self.config_file = self.get_name()+"Conf.py"
  105.  
  106.  
  107.     def run_commands(self):
  108.         cwd = os.getcwd()
  109.         data = []
  110.     data.append('config_dir = %s' % `os.path.join(cwd, "config")`)
  111.         data.append("install_data = %s" % `cwd`)
  112.         self.create_conf_file(".", data)
  113.         Distribution.run_commands(self)
  114.  
  115.  
  116.     def create_conf_file(self, directory, data=[]):
  117.         print data
  118.         data.insert(0, "# this file is automatically created by setup.py")
  119.         filename = os.path.join(directory, self.config_file)
  120.         # add metadata
  121.         metanames = dir(self.metadata) + \
  122.                     ['fullname', 'contact', 'contact_email']
  123.         for name in metanames:
  124.               method = "get_" + name
  125.               cmd = "%s = %s" % (name, `getattr(self.metadata, method)()`)
  126.               data.append(cmd)
  127.         util.execute(write_file, (filename, data),
  128.                      "creating %s" % filename, self.verbose>=1, self.dry_run)
  129.  
  130.  
  131. myname = "Bastian Kleineidam"
  132. myemail = "calvin@users.sourceforge.net"
  133.  
  134. setup (name = "WebCleaner",
  135.        version = "0.8",
  136.        description = "a filtering HTTP proxy",
  137.        author = myname,
  138.        author_email = myemail,
  139.        maintainer = myname,
  140.        maintainer_email = myemail,
  141.        url = "http://webcleaner.sourceforge.net/",
  142.        licence = "GPL (Python 2.0 usage granted)",
  143.        packages = ['', 'webfilter', 'webparser'],
  144.        ext_modules = [Extension('webparser.sgmlop',
  145.                                 ['webparser/sgmlop.c']),
  146.                      ],
  147.        scripts = ['webcleaner', 'webcleanerconf'],
  148.        long_description =
  149. """WebCleaner can
  150. o disable animated GIFs
  151. o compress documents on-the-fly (with gzip)
  152. o enhance your privacy (remove user-agent: header and obfuscate IP address)
  153. o remove all HTML crap (adverts, javascript, ...)
  154. o be completely customized to your needs
  155. """,
  156.        distclass = MyDistribution,
  157.        cmdclass = {'install': MyInstall, 'install_data': MyInstallData},
  158.        data_files = [('share/webcleaner/config',
  159.                       ['config/blocked.html',
  160.                        'config/blocked.gif',
  161.                        'config/webcleaner.conf',
  162.                        'config/webcleaner.dtd',
  163.                     'config/filter.dtd',
  164.                'config/adverts.zap',
  165.                'config/css.zap',
  166.                'config/erotic.zap',
  167.                'config/finance.zap',
  168.                'config/misc.zap',
  169.                'config/plugins.zap',
  170.                'config/redirects.zap',
  171.                'config/scripting.zap']),
  172.                      ('share/webcleaner/examples',
  173.                       ['webcleaner.bat', 'filtertest', 'filtertest.html']),
  174.                      ('man/man1',
  175.               ['webcleaner.1', 'webcleanerconf.1']),
  176.             ],
  177. )
  178.