home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / distutils / dist.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  26.8 KB  |  892 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. __revision__ = '$Id: dist.py 68035 2008-12-29 22:36:22Z tarek.ziade $'
  5. import sys
  6. import os
  7. import string
  8. import re
  9. from types import *
  10. from copy import copy
  11.  
  12. try:
  13.     import warnings
  14. except ImportError:
  15.     warnings = None
  16.  
  17. from distutils.errors import *
  18. from distutils.fancy_getopt import FancyGetopt, translate_longopt
  19. from distutils.util import check_environ, strtobool, rfc822_escape
  20. from distutils import log
  21. from distutils.debug import DEBUG
  22. PKG_INFO_ENCODING = 'utf-8'
  23. command_re = re.compile('^[a-zA-Z]([a-zA-Z0-9_]*)$')
  24.  
  25. class Distribution:
  26.     global_options = [
  27.         ('verbose', 'v', 'run verbosely (default)', 1),
  28.         ('quiet', 'q', 'run quietly (turns verbosity off)'),
  29.         ('dry-run', 'n', "don't actually do anything"),
  30.         ('help', 'h', 'show detailed help message')]
  31.     common_usage = "Common commands: (see '--help-commands' for more)\n\n  setup.py build      will build the package underneath 'build/'\n  setup.py install    will install the package\n"
  32.     display_options = [
  33.         ('help-commands', None, 'list all available commands'),
  34.         ('name', None, 'print package name'),
  35.         ('version', 'V', 'print package version'),
  36.         ('fullname', None, 'print <package name>-<version>'),
  37.         ('author', None, "print the author's name"),
  38.         ('author-email', None, "print the author's email address"),
  39.         ('maintainer', None, "print the maintainer's name"),
  40.         ('maintainer-email', None, "print the maintainer's email address"),
  41.         ('contact', None, "print the maintainer's name if known, else the author's"),
  42.         ('contact-email', None, "print the maintainer's email address if known, else the author's"),
  43.         ('url', None, 'print the URL for this package'),
  44.         ('license', None, 'print the license of the package'),
  45.         ('licence', None, 'alias for --license'),
  46.         ('description', None, 'print the package description'),
  47.         ('long-description', None, 'print the long package description'),
  48.         ('platforms', None, 'print the list of platforms'),
  49.         ('classifiers', None, 'print the list of classifiers'),
  50.         ('keywords', None, 'print the list of keywords'),
  51.         ('provides', None, 'print the list of packages/modules provided'),
  52.         ('requires', None, 'print the list of packages/modules required'),
  53.         ('obsoletes', None, 'print the list of packages/modules made obsolete')]
  54.     display_option_names = map((lambda x: translate_longopt(x[0])), display_options)
  55.     negative_opt = {
  56.         'quiet': 'verbose' }
  57.     
  58.     def __init__(self, attrs = None):
  59.         self.verbose = 1
  60.         self.dry_run = 0
  61.         self.help = 0
  62.         for attr in self.display_option_names:
  63.             setattr(self, attr, 0)
  64.         
  65.         self.metadata = DistributionMetadata()
  66.         for basename in self.metadata._METHOD_BASENAMES:
  67.             method_name = 'get_' + basename
  68.             setattr(self, method_name, getattr(self.metadata, method_name))
  69.         
  70.         self.cmdclass = { }
  71.         self.command_packages = None
  72.         self.script_name = None
  73.         self.script_args = None
  74.         self.command_options = { }
  75.         self.dist_files = []
  76.         self.packages = None
  77.         self.package_data = { }
  78.         self.package_dir = None
  79.         self.py_modules = None
  80.         self.libraries = None
  81.         self.headers = None
  82.         self.ext_modules = None
  83.         self.ext_package = None
  84.         self.include_dirs = None
  85.         self.extra_path = None
  86.         self.scripts = None
  87.         self.data_files = None
  88.         self.command_obj = { }
  89.         self.have_run = { }
  90.         if attrs:
  91.             options = attrs.get('options')
  92.             if options is not None:
  93.                 del attrs['options']
  94.                 for command, cmd_options in options.items():
  95.                     opt_dict = self.get_option_dict(command)
  96.                     for opt, val in cmd_options.items():
  97.                         opt_dict[opt] = ('setup script', val)
  98.                     
  99.                 
  100.             
  101.             if 'licence' in attrs:
  102.                 attrs['license'] = attrs['licence']
  103.                 del attrs['licence']
  104.                 msg = "'licence' distribution option is deprecated; use 'license'"
  105.                 if warnings is not None:
  106.                     warnings.warn(msg)
  107.                 else:
  108.                     sys.stderr.write(msg + '\n')
  109.             
  110.             for key, val in attrs.items():
  111.                 if hasattr(self.metadata, 'set_' + key):
  112.                     getattr(self.metadata, 'set_' + key)(val)
  113.                     continue
  114.                 if hasattr(self.metadata, key):
  115.                     setattr(self.metadata, key, val)
  116.                     continue
  117.                 if hasattr(self, key):
  118.                     setattr(self, key, val)
  119.                     continue
  120.                 msg = 'Unknown distribution option: %s' % repr(key)
  121.                 if warnings is not None:
  122.                     warnings.warn(msg)
  123.                     continue
  124.                 sys.stderr.write(msg + '\n')
  125.             
  126.         
  127.         self.finalize_options()
  128.  
  129.     
  130.     def get_option_dict(self, command):
  131.         dict = self.command_options.get(command)
  132.         if dict is None:
  133.             dict = self.command_options[command] = { }
  134.         
  135.         return dict
  136.  
  137.     
  138.     def dump_option_dicts(self, header = None, commands = None, indent = ''):
  139.         pformat = pformat
  140.         import pprint
  141.         if commands is None:
  142.             commands = self.command_options.keys()
  143.             commands.sort()
  144.         
  145.         if header is not None:
  146.             print indent + header
  147.             indent = indent + '  '
  148.         
  149.         if not commands:
  150.             print indent + 'no commands known yet'
  151.             return None
  152.         for cmd_name in commands:
  153.             opt_dict = self.command_options.get(cmd_name)
  154.             if opt_dict is None:
  155.                 print indent + "no option dict for '%s' command" % cmd_name
  156.                 continue
  157.             print indent + "option dict for '%s' command:" % cmd_name
  158.             out = pformat(opt_dict)
  159.             for line in string.split(out, '\n'):
  160.                 print indent + '  ' + line
  161.             
  162.         
  163.  
  164.     
  165.     def find_config_files(self):
  166.         files = []
  167.         check_environ()
  168.         sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
  169.         sys_file = os.path.join(sys_dir, 'distutils.cfg')
  170.         if os.path.isfile(sys_file):
  171.             files.append(sys_file)
  172.         
  173.         if os.name == 'posix':
  174.             user_filename = '.pydistutils.cfg'
  175.         else:
  176.             user_filename = 'pydistutils.cfg'
  177.         user_file = os.path.join(os.path.expanduser('~'), user_filename)
  178.         if os.path.isfile(user_file):
  179.             files.append(user_file)
  180.         
  181.         local_file = 'setup.cfg'
  182.         if os.path.isfile(local_file):
  183.             files.append(local_file)
  184.         
  185.         return files
  186.  
  187.     
  188.     def parse_config_files(self, filenames = None):
  189.         ConfigParser = ConfigParser
  190.         import ConfigParser
  191.         if filenames is None:
  192.             filenames = self.find_config_files()
  193.         
  194.         if DEBUG:
  195.             print 'Distribution.parse_config_files():'
  196.         
  197.         parser = ConfigParser()
  198.         for filename in filenames:
  199.             if DEBUG:
  200.                 print '  reading', filename
  201.             
  202.             parser.read(filename)
  203.             for section in parser.sections():
  204.                 options = parser.options(section)
  205.                 opt_dict = self.get_option_dict(section)
  206.                 for opt in options:
  207.                     if opt != '__name__':
  208.                         val = parser.get(section, opt)
  209.                         opt = string.replace(opt, '-', '_')
  210.                         opt_dict[opt] = (filename, val)
  211.                         continue
  212.                 
  213.             
  214.             parser.__init__()
  215.         
  216.  
  217.     
  218.     def parse_command_line(self):
  219.         toplevel_options = self._get_toplevel_options()
  220.         if sys.platform == 'mac':
  221.             import EasyDialogs
  222.             cmdlist = self.get_command_list()
  223.             self.script_args = EasyDialogs.GetArgv(toplevel_options + self.display_options, cmdlist)
  224.         
  225.         self.commands = []
  226.         parser = FancyGetopt(toplevel_options + self.display_options)
  227.         parser.set_negative_aliases(self.negative_opt)
  228.         parser.set_aliases({
  229.             'licence': 'license' })
  230.         args = parser.getopt(args = self.script_args, object = self)
  231.         option_order = parser.get_option_order()
  232.         log.set_verbosity(self.verbose)
  233.         if self.handle_display_options(option_order):
  234.             return None
  235.         while args:
  236.             args = self._parse_command_opts(parser, args)
  237.             if args is None:
  238.                 return None
  239.             continue
  240.             args is None
  241.         if self.help:
  242.             self._show_help(parser, display_options = len(self.commands) == 0, commands = self.commands)
  243.             return None
  244.         if not self.commands:
  245.             raise DistutilsArgError, 'no commands supplied'
  246.         self.commands
  247.         return 1
  248.  
  249.     
  250.     def _get_toplevel_options(self):
  251.         return self.global_options + [
  252.             ('command-packages=', None, 'list of packages that provide distutils commands')]
  253.  
  254.     
  255.     def _parse_command_opts(self, parser, args):
  256.         Command = Command
  257.         import distutils.cmd
  258.         command = args[0]
  259.         if not command_re.match(command):
  260.             raise SystemExit, "invalid command name '%s'" % command
  261.         command_re.match(command)
  262.         self.commands.append(command)
  263.         
  264.         try:
  265.             cmd_class = self.get_command_class(command)
  266.         except DistutilsModuleError:
  267.             msg = None
  268.             raise DistutilsArgError, msg
  269.  
  270.         if not issubclass(cmd_class, Command):
  271.             raise DistutilsClassError, 'command class %s must subclass Command' % cmd_class
  272.         issubclass(cmd_class, Command)
  273.         if not hasattr(cmd_class, 'user_options') and type(cmd_class.user_options) is ListType:
  274.             raise DistutilsClassError, ('command class %s must provide ' + "'user_options' attribute (a list of tuples)") % cmd_class
  275.         type(cmd_class.user_options) is ListType
  276.         negative_opt = self.negative_opt
  277.         if hasattr(cmd_class, 'negative_opt'):
  278.             negative_opt = copy(negative_opt)
  279.             negative_opt.update(cmd_class.negative_opt)
  280.         
  281.         if hasattr(cmd_class, 'help_options') and type(cmd_class.help_options) is ListType:
  282.             help_options = fix_help_options(cmd_class.help_options)
  283.         else:
  284.             help_options = []
  285.         parser.set_option_table(self.global_options + cmd_class.user_options + help_options)
  286.         parser.set_negative_aliases(negative_opt)
  287.         (args, opts) = parser.getopt(args[1:])
  288.         if hasattr(opts, 'help') and opts.help:
  289.             self._show_help(parser, display_options = 0, commands = [
  290.                 cmd_class])
  291.             return None
  292.         opt_dict = self.get_option_dict(command)
  293.         for name, value in vars(opts).items():
  294.             opt_dict[name] = ('command line', value)
  295.         
  296.         return args
  297.  
  298.     
  299.     def finalize_options(self):
  300.         keywords = self.metadata.keywords
  301.         if keywords is not None:
  302.             if type(keywords) is StringType:
  303.                 keywordlist = string.split(keywords, ',')
  304.                 self.metadata.keywords = map(string.strip, keywordlist)
  305.             
  306.         
  307.         platforms = self.metadata.platforms
  308.         if platforms is not None:
  309.             if type(platforms) is StringType:
  310.                 platformlist = string.split(platforms, ',')
  311.                 self.metadata.platforms = map(string.strip, platformlist)
  312.             
  313.         
  314.  
  315.     
  316.     def _show_help(self, parser, global_options = 1, display_options = 1, commands = []):
  317.         gen_usage = gen_usage
  318.         import distutils.core
  319.         Command = Command
  320.         import distutils.cmd
  321.         if global_options:
  322.             if display_options:
  323.                 options = self._get_toplevel_options()
  324.             else:
  325.                 options = self.global_options
  326.             parser.set_option_table(options)
  327.             parser.print_help(self.common_usage + '\nGlobal options:')
  328.             print 
  329.         
  330.         if display_options:
  331.             parser.set_option_table(self.display_options)
  332.             parser.print_help('Information display options (just display ' + 'information, ignore any commands)')
  333.             print 
  334.         
  335.         for command in self.commands:
  336.             if type(command) is ClassType and issubclass(command, Command):
  337.                 klass = command
  338.             else:
  339.                 klass = self.get_command_class(command)
  340.             if hasattr(klass, 'help_options') and type(klass.help_options) is ListType:
  341.                 parser.set_option_table(klass.user_options + fix_help_options(klass.help_options))
  342.             else:
  343.                 parser.set_option_table(klass.user_options)
  344.             parser.print_help("Options for '%s' command:" % klass.__name__)
  345.             print 
  346.         
  347.         print gen_usage(self.script_name)
  348.  
  349.     
  350.     def handle_display_options(self, option_order):
  351.         gen_usage = gen_usage
  352.         import distutils.core
  353.         if self.help_commands:
  354.             self.print_commands()
  355.             print 
  356.             print gen_usage(self.script_name)
  357.             return 1
  358.         any_display_options = 0
  359.         is_display_option = { }
  360.         for option in self.display_options:
  361.             is_display_option[option[0]] = 1
  362.         
  363.         for opt, val in option_order:
  364.             if val and is_display_option.get(opt):
  365.                 opt = translate_longopt(opt)
  366.                 value = getattr(self.metadata, 'get_' + opt)()
  367.                 if opt in ('keywords', 'platforms'):
  368.                     print string.join(value, ',')
  369.                 elif opt in ('classifiers', 'provides', 'requires', 'obsoletes'):
  370.                     print string.join(value, '\n')
  371.                 else:
  372.                     print value
  373.                 any_display_options = 1
  374.                 continue
  375.         
  376.         return any_display_options
  377.  
  378.     
  379.     def print_command_list(self, commands, header, max_length):
  380.         print header + ':'
  381.         for cmd in commands:
  382.             klass = self.cmdclass.get(cmd)
  383.             if not klass:
  384.                 klass = self.get_command_class(cmd)
  385.             
  386.             
  387.             try:
  388.                 description = klass.description
  389.             except AttributeError:
  390.                 description = '(no description available)'
  391.  
  392.             print '  %-*s  %s' % (max_length, cmd, description)
  393.         
  394.  
  395.     
  396.     def print_commands(self):
  397.         import distutils.command as distutils
  398.         std_commands = distutils.command.__all__
  399.         is_std = { }
  400.         for cmd in std_commands:
  401.             is_std[cmd] = 1
  402.         
  403.         extra_commands = []
  404.         for cmd in self.cmdclass.keys():
  405.             if not is_std.get(cmd):
  406.                 extra_commands.append(cmd)
  407.                 continue
  408.         
  409.         max_length = 0
  410.         for cmd in std_commands + extra_commands:
  411.             if len(cmd) > max_length:
  412.                 max_length = len(cmd)
  413.                 continue
  414.         
  415.         self.print_command_list(std_commands, 'Standard commands', max_length)
  416.         if extra_commands:
  417.             print 
  418.             self.print_command_list(extra_commands, 'Extra commands', max_length)
  419.         
  420.  
  421.     
  422.     def get_command_list(self):
  423.         import distutils.command as distutils
  424.         std_commands = distutils.command.__all__
  425.         is_std = { }
  426.         for cmd in std_commands:
  427.             is_std[cmd] = 1
  428.         
  429.         extra_commands = []
  430.         for cmd in self.cmdclass.keys():
  431.             if not is_std.get(cmd):
  432.                 extra_commands.append(cmd)
  433.                 continue
  434.         
  435.         rv = []
  436.         for cmd in std_commands + extra_commands:
  437.             klass = self.cmdclass.get(cmd)
  438.             if not klass:
  439.                 klass = self.get_command_class(cmd)
  440.             
  441.             
  442.             try:
  443.                 description = klass.description
  444.             except AttributeError:
  445.                 description = '(no description available)'
  446.  
  447.             rv.append((cmd, description))
  448.         
  449.         return rv
  450.  
  451.     
  452.     def get_command_packages(self):
  453.         pkgs = self.command_packages
  454.         if not isinstance(pkgs, type([])):
  455.             if not pkgs:
  456.                 pass
  457.             pkgs = string.split('', ',')
  458.             for i in range(len(pkgs)):
  459.                 pkgs[i] = string.strip(pkgs[i])
  460.             
  461.             pkgs = filter(None, pkgs)
  462.             if 'distutils.command' not in pkgs:
  463.                 pkgs.insert(0, 'distutils.command')
  464.             
  465.             self.command_packages = pkgs
  466.         
  467.         return pkgs
  468.  
  469.     
  470.     def get_command_class(self, command):
  471.         klass = self.cmdclass.get(command)
  472.         if klass:
  473.             return klass
  474.         for pkgname in self.get_command_packages():
  475.             module_name = '%s.%s' % (pkgname, command)
  476.             klass_name = command
  477.             
  478.             try:
  479.                 __import__(module_name)
  480.                 module = sys.modules[module_name]
  481.             except ImportError:
  482.                 klass
  483.                 klass
  484.                 continue
  485.             except:
  486.                 klass
  487.  
  488.             
  489.             try:
  490.                 klass = getattr(module, klass_name)
  491.             except AttributeError:
  492.                 klass
  493.                 klass
  494.                 raise DistutilsModuleError, "invalid command '%s' (no class '%s' in module '%s')" % (command, klass_name, module_name)
  495.             except:
  496.                 klass
  497.  
  498.             self.cmdclass[command] = klass
  499.             return klass
  500.         
  501.         raise DistutilsModuleError("invalid command '%s'" % command)
  502.  
  503.     
  504.     def get_command_obj(self, command, create = 1):
  505.         cmd_obj = self.command_obj.get(command)
  506.         if not cmd_obj and create:
  507.             if DEBUG:
  508.                 print "Distribution.get_command_obj(): creating '%s' command object" % command
  509.             
  510.             klass = self.get_command_class(command)
  511.             cmd_obj = self.command_obj[command] = klass(self)
  512.             self.have_run[command] = 0
  513.             options = self.command_options.get(command)
  514.             if options:
  515.                 self._set_command_options(cmd_obj, options)
  516.             
  517.         
  518.         return cmd_obj
  519.  
  520.     
  521.     def _set_command_options(self, command_obj, option_dict = None):
  522.         command_name = command_obj.get_command_name()
  523.         if option_dict is None:
  524.             option_dict = self.get_option_dict(command_name)
  525.         
  526.         if DEBUG:
  527.             print "  setting options for '%s' command:" % command_name
  528.         
  529.         for source, value in option_dict.items():
  530.             
  531.             try:
  532.                 bool_opts = map(translate_longopt, command_obj.boolean_options)
  533.             except AttributeError:
  534.                 None if DEBUG else None
  535.                 None if DEBUG else None
  536.                 bool_opts = []
  537.             except:
  538.                 None if DEBUG else None
  539.  
  540.             
  541.             try:
  542.                 neg_opt = command_obj.negative_opt
  543.             except AttributeError:
  544.                 None if DEBUG else None
  545.                 None if DEBUG else None
  546.                 neg_opt = { }
  547.             except:
  548.                 None if DEBUG else None
  549.  
  550.             
  551.             try:
  552.                 is_string = type(value) is StringType
  553.                 if option in neg_opt and is_string:
  554.                     setattr(command_obj, neg_opt[option], not strtobool(value))
  555.                 elif option in bool_opts and is_string:
  556.                     setattr(command_obj, option, strtobool(value))
  557.                 elif hasattr(command_obj, option):
  558.                     setattr(command_obj, option, value)
  559.                 else:
  560.                     raise DistutilsOptionError, "error in %s: command '%s' has no such option '%s'" % (source, command_name, option)
  561.                 continue
  562.                 except ValueError:
  563.                     is_string
  564.                     msg = is_string
  565.                     raise DistutilsOptionError, msg
  566.                     continue
  567.                 
  568.             return None
  569.  
  570.  
  571.     
  572.     def reinitialize_command(self, command, reinit_subcommands = 0):
  573.         Command = Command
  574.         import distutils.cmd
  575.         if not isinstance(command, Command):
  576.             command_name = command
  577.             command = self.get_command_obj(command_name)
  578.         else:
  579.             command_name = command.get_command_name()
  580.         if not command.finalized:
  581.             return command
  582.         command.initialize_options()
  583.         command.finalized = 0
  584.         self.have_run[command_name] = 0
  585.         self._set_command_options(command)
  586.         if reinit_subcommands:
  587.             for sub in command.get_sub_commands():
  588.                 self.reinitialize_command(sub, reinit_subcommands)
  589.             
  590.         
  591.         return command
  592.  
  593.     
  594.     def announce(self, msg, level = 1):
  595.         log.debug(msg)
  596.  
  597.     
  598.     def run_commands(self):
  599.         for cmd in self.commands:
  600.             self.run_command(cmd)
  601.         
  602.  
  603.     
  604.     def run_command(self, command):
  605.         if self.have_run.get(command):
  606.             return None
  607.         log.info('running %s', command)
  608.         cmd_obj = self.get_command_obj(command)
  609.         cmd_obj.ensure_finalized()
  610.         cmd_obj.run()
  611.         self.have_run[command] = 1
  612.  
  613.     
  614.     def has_pure_modules(self):
  615.         if not self.packages and self.py_modules:
  616.             pass
  617.         return len([]) > 0
  618.  
  619.     
  620.     def has_ext_modules(self):
  621.         if self.ext_modules:
  622.             pass
  623.         return len(self.ext_modules) > 0
  624.  
  625.     
  626.     def has_c_libraries(self):
  627.         if self.libraries:
  628.             pass
  629.         return len(self.libraries) > 0
  630.  
  631.     
  632.     def has_modules(self):
  633.         if not self.has_pure_modules():
  634.             pass
  635.         return self.has_ext_modules()
  636.  
  637.     
  638.     def has_headers(self):
  639.         if self.headers:
  640.             pass
  641.         return len(self.headers) > 0
  642.  
  643.     
  644.     def has_scripts(self):
  645.         if self.scripts:
  646.             pass
  647.         return len(self.scripts) > 0
  648.  
  649.     
  650.     def has_data_files(self):
  651.         if self.data_files:
  652.             pass
  653.         return len(self.data_files) > 0
  654.  
  655.     
  656.     def is_pure(self):
  657.         if self.has_pure_modules() and not self.has_ext_modules():
  658.             pass
  659.         return not self.has_c_libraries()
  660.  
  661.  
  662.  
  663. class DistributionMetadata:
  664.     _METHOD_BASENAMES = ('name', 'version', 'author', 'author_email', 'maintainer', 'maintainer_email', 'url', 'license', 'description', 'long_description', 'keywords', 'platforms', 'fullname', 'contact', 'contact_email', 'license', 'classifiers', 'download_url', 'provides', 'requires', 'obsoletes')
  665.     
  666.     def __init__(self):
  667.         self.name = None
  668.         self.version = None
  669.         self.author = None
  670.         self.author_email = None
  671.         self.maintainer = None
  672.         self.maintainer_email = None
  673.         self.url = None
  674.         self.license = None
  675.         self.description = None
  676.         self.long_description = None
  677.         self.keywords = None
  678.         self.platforms = None
  679.         self.classifiers = None
  680.         self.download_url = None
  681.         self.provides = None
  682.         self.requires = None
  683.         self.obsoletes = None
  684.  
  685.     
  686.     def write_pkg_info(self, base_dir):
  687.         pkg_info = open(os.path.join(base_dir, 'PKG-INFO'), 'w')
  688.         self.write_pkg_file(pkg_info)
  689.         pkg_info.close()
  690.  
  691.     
  692.     def write_pkg_file(self, file):
  693.         version = '1.0'
  694.         if self.provides and self.requires or self.obsoletes:
  695.             version = '1.1'
  696.         
  697.         self._write_field(file, 'Metadata-Version', version)
  698.         self._write_field(file, 'Name', self.get_name())
  699.         self._write_field(file, 'Version', self.get_version())
  700.         self._write_field(file, 'Summary', self.get_description())
  701.         self._write_field(file, 'Home-page', self.get_url())
  702.         self._write_field(file, 'Author', self.get_contact())
  703.         self._write_field(file, 'Author-email', self.get_contact_email())
  704.         self._write_field(file, 'License', self.get_license())
  705.         if self.download_url:
  706.             self._write_field(file, 'Download-URL', self.download_url)
  707.         
  708.         long_desc = rfc822_escape(self.get_long_description())
  709.         self._write_field(file, 'Description', long_desc)
  710.         keywords = string.join(self.get_keywords(), ',')
  711.         if keywords:
  712.             self._write_field(file, 'Keywords', keywords)
  713.         
  714.         self._write_list(file, 'Platform', self.get_platforms())
  715.         self._write_list(file, 'Classifier', self.get_classifiers())
  716.         self._write_list(file, 'Requires', self.get_requires())
  717.         self._write_list(file, 'Provides', self.get_provides())
  718.         self._write_list(file, 'Obsoletes', self.get_obsoletes())
  719.  
  720.     
  721.     def _write_field(self, file, name, value):
  722.         if isinstance(value, unicode):
  723.             value = value.encode(PKG_INFO_ENCODING)
  724.         else:
  725.             value = str(value)
  726.         file.write('%s: %s\n' % (name, value))
  727.  
  728.     
  729.     def _write_list(self, file, name, values):
  730.         for value in values:
  731.             self._write_field(file, name, value)
  732.         
  733.  
  734.     
  735.     def get_name(self):
  736.         if not self.name:
  737.             pass
  738.         return 'UNKNOWN'
  739.  
  740.     
  741.     def get_version(self):
  742.         if not self.version:
  743.             pass
  744.         return '0.0.0'
  745.  
  746.     
  747.     def get_fullname(self):
  748.         return '%s-%s' % (self.get_name(), self.get_version())
  749.  
  750.     
  751.     def get_author(self):
  752.         if not self.author:
  753.             pass
  754.         return 'UNKNOWN'
  755.  
  756.     
  757.     def get_author_email(self):
  758.         if not self.author_email:
  759.             pass
  760.         return 'UNKNOWN'
  761.  
  762.     
  763.     def get_maintainer(self):
  764.         if not self.maintainer:
  765.             pass
  766.         return 'UNKNOWN'
  767.  
  768.     
  769.     def get_maintainer_email(self):
  770.         if not self.maintainer_email:
  771.             pass
  772.         return 'UNKNOWN'
  773.  
  774.     
  775.     def get_contact(self):
  776.         if not self.maintainer and self.author:
  777.             pass
  778.         return 'UNKNOWN'
  779.  
  780.     
  781.     def get_contact_email(self):
  782.         if not self.maintainer_email and self.author_email:
  783.             pass
  784.         return 'UNKNOWN'
  785.  
  786.     
  787.     def get_url(self):
  788.         if not self.url:
  789.             pass
  790.         return 'UNKNOWN'
  791.  
  792.     
  793.     def get_license(self):
  794.         if not self.license:
  795.             pass
  796.         return 'UNKNOWN'
  797.  
  798.     get_licence = get_license
  799.     
  800.     def get_description(self):
  801.         if not self.description:
  802.             pass
  803.         return 'UNKNOWN'
  804.  
  805.     
  806.     def get_long_description(self):
  807.         if not self.long_description:
  808.             pass
  809.         return 'UNKNOWN'
  810.  
  811.     
  812.     def get_keywords(self):
  813.         if not self.keywords:
  814.             pass
  815.         return []
  816.  
  817.     
  818.     def get_platforms(self):
  819.         if not self.platforms:
  820.             pass
  821.         return [
  822.             'UNKNOWN']
  823.  
  824.     
  825.     def get_classifiers(self):
  826.         if not self.classifiers:
  827.             pass
  828.         return []
  829.  
  830.     
  831.     def get_download_url(self):
  832.         if not self.download_url:
  833.             pass
  834.         return 'UNKNOWN'
  835.  
  836.     
  837.     def get_requires(self):
  838.         if not self.requires:
  839.             pass
  840.         return []
  841.  
  842.     
  843.     def set_requires(self, value):
  844.         import distutils.versionpredicate as distutils
  845.         for v in value:
  846.             distutils.versionpredicate.VersionPredicate(v)
  847.         
  848.         self.requires = value
  849.  
  850.     
  851.     def get_provides(self):
  852.         if not self.provides:
  853.             pass
  854.         return []
  855.  
  856.     
  857.     def set_provides(self, value):
  858.         value = [ v.strip() for v in value ]
  859.         for v in value:
  860.             import distutils.versionpredicate as distutils
  861.             distutils.versionpredicate.split_provision(v)
  862.         
  863.         self.provides = value
  864.  
  865.     
  866.     def get_obsoletes(self):
  867.         if not self.obsoletes:
  868.             pass
  869.         return []
  870.  
  871.     
  872.     def set_obsoletes(self, value):
  873.         import distutils.versionpredicate as distutils
  874.         for v in value:
  875.             distutils.versionpredicate.VersionPredicate(v)
  876.         
  877.         self.obsoletes = value
  878.  
  879.  
  880.  
  881. def fix_help_options(options):
  882.     new_options = []
  883.     for help_tuple in options:
  884.         new_options.append(help_tuple[0:3])
  885.     
  886.     return new_options
  887.  
  888. if __name__ == '__main__':
  889.     dist = Distribution()
  890.     print 'ok'
  891.  
  892.