home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 May / maximum-cd-2010-05.iso / DiscContents / boxee-0.9.20.10711.exe / system / python / Lib / distutils / core.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-07-20  |  7.6 KB  |  203 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. """distutils.core
  5.  
  6. The only module that needs to be imported to use the Distutils; provides
  7. the 'setup' function (which is to be called from the setup script).  Also
  8. indirectly provides the Distribution and Command classes, although they are
  9. really defined in distutils.dist and distutils.cmd.
  10. """
  11. __revision__ = '$Id: core.py 37828 2004-11-10 22:23:15Z loewis $'
  12. import sys
  13. import os
  14. from types import *
  15. from distutils.debug import DEBUG
  16. from distutils.errors import *
  17. from distutils.util import grok_environment_error
  18. from distutils.dist import Distribution
  19. from distutils.cmd import Command
  20. from distutils.extension import Extension
  21. USAGE = 'usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]\n   or: %(script)s --help [cmd1 cmd2 ...]\n   or: %(script)s --help-commands\n   or: %(script)s cmd --help\n'
  22.  
  23. def gen_usage(script_name):
  24.     script = os.path.basename(script_name)
  25.     return USAGE % vars()
  26.  
  27. _setup_stop_after = None
  28. _setup_distribution = None
  29. setup_keywords = ('distclass', 'script_name', 'script_args', 'options', 'name', 'version', 'author', 'author_email', 'maintainer', 'maintainer_email', 'url', 'license', 'description', 'long_description', 'keywords', 'platforms', 'classifiers', 'download_url')
  30. extension_keywords = ('name', 'sources', 'include_dirs', 'define_macros', 'undef_macros', 'library_dirs', 'libraries', 'runtime_library_dirs', 'extra_objects', 'extra_compile_args', 'extra_link_args', 'swig_opts', 'export_symbols', 'depends', 'language')
  31.  
  32. def setup(**attrs):
  33.     """The gateway to the Distutils: do everything your setup script needs
  34.     to do, in a highly flexible and user-driven way.  Briefly: create a
  35.     Distribution instance; find and parse config files; parse the command
  36.     line; run each Distutils command found there, customized by the options
  37.     supplied to 'setup()' (as keyword arguments), in config files, and on
  38.     the command line.
  39.  
  40.     The Distribution instance might be an instance of a class supplied via
  41.     the 'distclass' keyword argument to 'setup'; if no such class is
  42.     supplied, then the Distribution class (in dist.py) is instantiated.
  43.     All other arguments to 'setup' (except for 'cmdclass') are used to set
  44.     attributes of the Distribution instance.
  45.  
  46.     The 'cmdclass' argument, if supplied, is a dictionary mapping command
  47.     names to command classes.  Each command encountered on the command line
  48.     will be turned into a command class, which is in turn instantiated; any
  49.     class found in 'cmdclass' is used in place of the default, which is
  50.     (for command 'foo_bar') class 'foo_bar' in module
  51.     'distutils.command.foo_bar'.  The command class must provide a
  52.     'user_options' attribute which is a list of option specifiers for
  53.     'distutils.fancy_getopt'.  Any command-line options between the current
  54.     and the next command are used to set attributes of the current command
  55.     object.
  56.  
  57.     When the entire command-line has been successfully parsed, calls the
  58.     'run()' method on each command object in turn.  This method will be
  59.     driven entirely by the Distribution object (which each command object
  60.     has a reference to, thanks to its constructor), and the
  61.     command-specific options that became attributes of each command
  62.     object.
  63.     """
  64.     global _setup_distribution
  65.     klass = attrs.get('distclass')
  66.     if klass:
  67.         del attrs['distclass']
  68.     else:
  69.         klass = Distribution
  70.     if not attrs.has_key('script_name'):
  71.         attrs['script_name'] = os.path.basename(sys.argv[0])
  72.     
  73.     if not attrs.has_key('script_args'):
  74.         attrs['script_args'] = sys.argv[1:]
  75.     
  76.     
  77.     try:
  78.         _setup_distribution = dist = klass(attrs)
  79.     except DistutilsSetupError:
  80.         msg = None
  81.         if attrs.has_key('name'):
  82.             raise SystemExit, 'error in %s setup command: %s' % (attrs['name'], msg)
  83.         else:
  84.             raise SystemExit, 'error in setup command: %s' % msg
  85.     except:
  86.         attrs.has_key('name')
  87.  
  88.     if _setup_stop_after == 'init':
  89.         return dist
  90.     
  91.     dist.parse_config_files()
  92.     if DEBUG:
  93.         print 'options (after parsing config files):'
  94.         dist.dump_option_dicts()
  95.     
  96.     if _setup_stop_after == 'config':
  97.         return dist
  98.     
  99.     
  100.     try:
  101.         ok = dist.parse_command_line()
  102.     except DistutilsArgError:
  103.         msg = None
  104.         raise SystemExit, gen_usage(dist.script_name) + '\nerror: %s' % msg
  105.  
  106.     if DEBUG:
  107.         print 'options (after parsing command line):'
  108.         dist.dump_option_dicts()
  109.     
  110.     if _setup_stop_after == 'commandline':
  111.         return dist
  112.     
  113.     if ok:
  114.         
  115.         try:
  116.             dist.run_commands()
  117.         except KeyboardInterrupt:
  118.             raise SystemExit, 'interrupted'
  119.         except (IOError, os.error):
  120.             exc = None
  121.             error = grok_environment_error(exc)
  122.             if DEBUG:
  123.                 sys.stderr.write(error + '\n')
  124.                 raise 
  125.             else:
  126.                 raise SystemExit, error
  127.         except (DistutilsError, CCompilerError):
  128.             msg = None
  129.             if DEBUG:
  130.                 raise 
  131.             else:
  132.                 raise SystemExit, 'error: ' + str(msg)
  133.         except:
  134.             DEBUG
  135.         
  136.  
  137.     None<EXCEPTION MATCH>KeyboardInterrupt
  138.     return dist
  139.  
  140.  
  141. def run_setup(script_name, script_args = None, stop_after = 'run'):
  142.     """Run a setup script in a somewhat controlled environment, and
  143.     return the Distribution instance that drives things.  This is useful
  144.     if you need to find out the distribution meta-data (passed as
  145.     keyword args from 'script' to 'setup()', or the contents of the
  146.     config files or command-line.
  147.  
  148.     'script_name' is a file that will be run with 'execfile()';
  149.     'sys.argv[0]' will be replaced with 'script' for the duration of the
  150.     call.  'script_args' is a list of strings; if supplied,
  151.     'sys.argv[1:]' will be replaced by 'script_args' for the duration of
  152.     the call.
  153.  
  154.     'stop_after' tells 'setup()' when to stop processing; possible
  155.     values:
  156.       init
  157.         stop after the Distribution instance has been created and
  158.         populated with the keyword arguments to 'setup()'
  159.       config
  160.         stop after config files have been parsed (and their data
  161.         stored in the Distribution instance)
  162.       commandline
  163.         stop after the command-line ('sys.argv[1:]' or 'script_args')
  164.         have been parsed (and the data stored in the Distribution)
  165.       run [default]
  166.         stop after all commands have been run (the same as if 'setup()'
  167.         had been called in the usual way
  168.  
  169.     Returns the Distribution instance, which provides all information
  170.     used to drive the Distutils.
  171.     """
  172.     global _setup_stop_after, _setup_stop_after
  173.     if stop_after not in ('init', 'config', 'commandline', 'run'):
  174.         raise ValueError, "invalid value for 'stop_after': %r" % (stop_after,)
  175.     
  176.     _setup_stop_after = stop_after
  177.     save_argv = sys.argv
  178.     g = { }
  179.     l = { }
  180.     
  181.     try:
  182.         
  183.         try:
  184.             sys.argv[0] = script_name
  185.             if script_args is not None:
  186.                 sys.argv[1:] = script_args
  187.             
  188.             execfile(script_name, g, l)
  189.         finally:
  190.             sys.argv = save_argv
  191.             _setup_stop_after = None
  192.  
  193.     except SystemExit:
  194.         pass
  195.     except:
  196.         raise 
  197.  
  198.     if _setup_distribution is None:
  199.         raise RuntimeError, "'distutils.core.setup()' was never called -- perhaps '%s' is not a Distutils setup script?" % script_name
  200.     
  201.     return _setup_distribution
  202.  
  203.