code: #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  
  # Copyright (C) 2008-2009 Adriano Monteiro Marques.
  #
  # Author: Bartosz SKOWRON <getxsick at gmail dot com>
  #
  # This library is free software; you can redistribute it and/or modify 
  # it under the terms of the GNU Lesser General Public License as published 
  # by the Free Software Foundation; either version 2.1 of the License, or 
  # (at your option) any later version.
  #
  # This library is distributed in the hope that it will be useful, but 
  # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
  # License for more details.
  #
  # You should have received a copy of the GNU Lesser General Public License 
  # along with this library; if not, write to the Free Software Foundation, 
  # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
  
  import glob
  import os
  import os.path
  from stat import ST_MODE
  from distutils.core import setup
  from distutils.command.install import install
  
  UMPA_VERSION = '0.2'
  SHARE_DIR = os.path.join('share', 'umpa')
  DOCS_DIR = os.path.join('share', 'doc', 'umpa')
  
  TESTS_DIR = [
      os.path.join('tests'),
      os.path.join('tests', 'system'),
      os.path.join('tests', 'system', 'test_snd'),
      os.path.join('tests', 'system', 'test_sndrcv'),
      os.path.join('tests', 'a_unit'),
      os.path.join('tests', 'a_unit', 'test_extensions'),
      os.path.join('tests', 'a_unit', 'test_protocols'),
      os.path.join('tests', 'a_unit', 'test_utils'),
      os.path.join('tests', 'a_unit', 'test_sniffing'),
      os.path.join('tests', 'a_unit', 'test_sniffing', 'test_libpcap'),
  ]
  
  class umpa_install(install):
      def run(self):
          install.run(self)
          self.create_uninstaller()
  
      def create_uninstaller(self):
          uninstaller_filename = os.path.join(
                  self.install_data, SHARE_DIR, 'uninstall_umpa')
          uninstaller = []
          uninstaller.append(
                  "#!/usr/bin/env python\n"
                  "import os, sys, shutil\n"
                  "\n"
                  "print\n"
                  "print '%(line)s Uninstall UMPA %(version)s %(line)s'\n"
                  "print\n"
                  "\n"
                  "answer = raw_input('Are you sure that you want to '\n"
                  "        'completly uninstall UMPA %(version)s? (yes/no) ')\n"
                  "\n"
                  "if answer.lower() not in ['yes', 'y']:\n"
                  "    sys.exit(0)\n"
                  "\n"
                  "print\n"
                  "print '%(line)s Uninstalling UMPA %(version)s... %(line)s'\n"
                  "print\n" % {'version': UMPA_VERSION, 'line': '-' * 10})
  
          for output in self.get_outputs():
              uninstaller.append(
                      'print "Removing %(output)s..."\n'
                      'if os.path.exists("%(output)s"):\n'
                      '    os.remove("%(output)s")\n' % {'output': output})
  
          uninstaller.append(
                  "print 'Removing uninstaller itself...'\n"
                  "os.remove('%s')\n" % uninstaller_filename)
  
          uninstaller.append('print "Removing empty directories..."\n')
          for dir in (
                  os.path.join(self.install_data, SHARE_DIR),
                  os.path.join(self.install_data, DOCS_DIR),
                  os.path.join(self.install_lib, 'umpa'),
              ):
              uninstaller.append(
                      'if os.path.exists("%(dir)s"):\n'
                      '    shutil.rmtree("%(dir)s")\n' % {'dir' : dir})
  
          uninstaller_file = open(uninstaller_filename, 'w')
          uninstaller_file.writelines(uninstaller)
          uninstaller_file.close()
  
          # Set exec bit for uninstaller
          mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777
          os.chmod(uninstaller_filename, mode)
  
  cmdclasses = {
          'install' : umpa_install,
          }
  
  test_files = []
  for dir in TESTS_DIR:
      test_files = test_files + [ (os.path.join(SHARE_DIR, dir),
                                  glob.glob(os.path.join(dir,'*.py')))]
  
  data_files = [  (os.path.join(SHARE_DIR,'examples'),
                              glob.glob(os.path.join('examples','*'))),
                  (os.path.join(DOCS_DIR,'API'),
                      glob.glob(os.path.join('docs','API','*'))),
                  (os.path.join(DOCS_DIR,'tutorials','_sources'),
                  glob.glob(os.path.join('docs','tutorials','_sources','*'))),
                  (os.path.join(DOCS_DIR,'tutorials','_static'),
                      glob.glob(os.path.join('docs','tutorials','_static','*'))),
                  (os.path.join(DOCS_DIR,'tutorials'),
                      glob.glob(os.path.join('docs','tutorials','*.*'))),
                  (SHARE_DIR, ('run_tests.sh', 'run_tests.bat')),
                  (DOCS_DIR,
                      ('README', 'COPYING', 'AUTHORS', 'TODO', 'CHANGES',
                      'INSTALL')),
                  (os.path.join(SHARE_DIR, 'tests'),
                      (os.path.join('tests','README'),
                      os.path.join('tests','IMPORTANT'))),
              ] + test_files
  
  setup(  name            = "UMPA",
          version         = UMPA_VERSION,
          description     = "Umit's Manipulations of Packets Art",
          author          = "Bartosz SKOWRON",
          author_email    = dummy@email.com",
          url             = "http://www.umpa.umitproject.org",
          license         = "GNU LGPLv2",
          platforms       = ["Platform Independent"],
          packages        = [ "umit",
                              "umit.umpa",
                              "umit.umpa.protocols",
                              "umit.umpa.sniffing",
                              "umit.umpa.sniffing.libpcap",
                              "umit.umpa.extensions",
                              "umit.umpa.utils",
                              ],
          data_files = data_files,
          cmdclass = cmdclasses,
  )
  
entities: [['EMAIL_ADDRESS', 'dummy@email.com'], ['URL', 'http://www.umpa.umitproject.org'], ['DATE_TIME', '2008-2009'], ['PERSON', 'Adriano Monteiro Marques'], ['PERSON', 'Bartosz SKOWRON'], ['LOCATION', 'Boston'], ['LOCATION', 'USA'], ['PERSON', 'UMPA'], ['LOCATION', 'version)s'], ['PERSON', 'UMPA'], ['LOCATION', 'version)s'], ['PERSON', 'answer.lower'], ['LOCATION', 'version)s'], ['PERSON', 'TODO'], ['PERSON', 'Umit'], ['PERSON', 'Bartosz SKOWRON'], ['URL', 'os.pa'], ['URL', 'distutils.co'], ['URL', 'distutils.command.in'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'install.ru'], ['URL', 'self.cr'], ['URL', 'os.path.jo'], ['URL', 'self.in'], ['URL', 'self.ge'], ['URL', 'os.pa'], ['URL', 'os.re'], ['URL', 'os.re'], ['URL', 'os.path.jo'], ['URL', 'self.in'], ['URL', 'os.path.jo'], ['URL', 'self.in'], ['URL', 'os.path.jo'], ['URL', 'self.in'], ['URL', 'os.pa'], ['URL', 'file.cl'], ['URL', 'os.st'], ['URL', 'os.ch'], ['URL', 'os.path.jo'], ['URL', 'glob.gl'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'glob.gl'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'glob.gl'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'glob.gl'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'glob.gl'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'glob.gl'], ['URL', 'os.path.jo'], ['URL', 'tests.sh'], ['URL', 'tests.ba'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'os.path.jo'], ['URL', 'email.com'], ['URL', 'umit.umpa.pro'], ['URL', 'umit.umpa.sn'], ['URL', 'umit.umpa.sniffing.li']]