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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. __revision__ = '$Id: cmd.py 37828 2004-11-10 22:23:15Z loewis $'
  5. import sys
  6. import os
  7. import string
  8. import re
  9. from types import *
  10. from distutils.errors import *
  11. from distutils import util, dir_util, file_util, archive_util, dep_util
  12. from distutils import log
  13.  
  14. class Command:
  15.     sub_commands = []
  16.     
  17.     def __init__(self, dist):
  18.         Distribution = Distribution
  19.         import distutils.dist
  20.         if not isinstance(dist, Distribution):
  21.             raise TypeError, 'dist must be a Distribution instance'
  22.         isinstance(dist, Distribution)
  23.         if self.__class__ is Command:
  24.             raise RuntimeError, 'Command is an abstract class'
  25.         self.__class__ is Command
  26.         self.distribution = dist
  27.         self.initialize_options()
  28.         self._dry_run = None
  29.         self.verbose = dist.verbose
  30.         self.force = None
  31.         self.help = 0
  32.         self.finalized = 0
  33.  
  34.     
  35.     def __getattr__(self, attr):
  36.         if attr == 'dry_run':
  37.             myval = getattr(self, '_' + attr)
  38.             if myval is None:
  39.                 return getattr(self.distribution, attr)
  40.             return myval
  41.         attr == 'dry_run'
  42.         raise AttributeError, attr
  43.  
  44.     
  45.     def ensure_finalized(self):
  46.         if not self.finalized:
  47.             self.finalize_options()
  48.         
  49.         self.finalized = 1
  50.  
  51.     
  52.     def initialize_options(self):
  53.         raise RuntimeError, 'abstract method -- subclass %s must override' % self.__class__
  54.  
  55.     
  56.     def finalize_options(self):
  57.         raise RuntimeError, 'abstract method -- subclass %s must override' % self.__class__
  58.  
  59.     
  60.     def dump_options(self, header = None, indent = ''):
  61.         longopt_xlate = longopt_xlate
  62.         import distutils.fancy_getopt
  63.         if header is None:
  64.             header = "command options for '%s':" % self.get_command_name()
  65.         
  66.         print indent + header
  67.         indent = indent + '  '
  68.         for option, _, _ in self.user_options:
  69.             option = string.translate(option, longopt_xlate)
  70.             if option[-1] == '=':
  71.                 option = option[:-1]
  72.             
  73.             value = getattr(self, option)
  74.             print indent + '%s = %s' % (option, value)
  75.         
  76.  
  77.     
  78.     def run(self):
  79.         raise RuntimeError, 'abstract method -- subclass %s must override' % self.__class__
  80.  
  81.     
  82.     def announce(self, msg, level = 1):
  83.         log.log(level, msg)
  84.  
  85.     
  86.     def debug_print(self, msg):
  87.         DEBUG = DEBUG
  88.         import distutils.debug
  89.         if DEBUG:
  90.             print msg
  91.             sys.stdout.flush()
  92.         
  93.  
  94.     
  95.     def _ensure_stringlike(self, option, what, default = None):
  96.         val = getattr(self, option)
  97.         if val is None:
  98.             setattr(self, option, default)
  99.             return default
  100.         if type(val) is not StringType:
  101.             raise DistutilsOptionError, "'%s' must be a %s (got `%s`)" % (option, what, val)
  102.         type(val) is not StringType
  103.         return val
  104.  
  105.     
  106.     def ensure_string(self, option, default = None):
  107.         self._ensure_stringlike(option, 'string', default)
  108.  
  109.     
  110.     def ensure_string_list(self, option):
  111.         val = getattr(self, option)
  112.         if val is None:
  113.             return None
  114.         if type(val) is StringType:
  115.             setattr(self, option, re.split(',\\s*|\\s+', val))
  116.         elif type(val) is ListType:
  117.             types = map(type, val)
  118.             ok = types == [
  119.                 StringType] * len(val)
  120.         else:
  121.             ok = 0
  122.         if not ok:
  123.             raise DistutilsOptionError, "'%s' must be a list of strings (got %r)" % (option, val)
  124.         ok
  125.  
  126.     
  127.     def _ensure_tested_string(self, option, tester, what, error_fmt, default = None):
  128.         val = self._ensure_stringlike(option, what, default)
  129.         if val is not None and not tester(val):
  130.             raise DistutilsOptionError, ("error in '%s' option: " + error_fmt) % (option, val)
  131.         not tester(val)
  132.  
  133.     
  134.     def ensure_filename(self, option):
  135.         self._ensure_tested_string(option, os.path.isfile, 'filename', "'%s' does not exist or is not a file")
  136.  
  137.     
  138.     def ensure_dirname(self, option):
  139.         self._ensure_tested_string(option, os.path.isdir, 'directory name', "'%s' does not exist or is not a directory")
  140.  
  141.     
  142.     def get_command_name(self):
  143.         if hasattr(self, 'command_name'):
  144.             return self.command_name
  145.         return self.__class__.__name__
  146.  
  147.     
  148.     def set_undefined_options(self, src_cmd, *option_pairs):
  149.         src_cmd_obj = self.distribution.get_command_obj(src_cmd)
  150.         src_cmd_obj.ensure_finalized()
  151.         for src_option, dst_option in option_pairs:
  152.             if getattr(self, dst_option) is None:
  153.                 setattr(self, dst_option, getattr(src_cmd_obj, src_option))
  154.                 continue
  155.         
  156.  
  157.     
  158.     def get_finalized_command(self, command, create = 1):
  159.         cmd_obj = self.distribution.get_command_obj(command, create)
  160.         cmd_obj.ensure_finalized()
  161.         return cmd_obj
  162.  
  163.     
  164.     def reinitialize_command(self, command, reinit_subcommands = 0):
  165.         return self.distribution.reinitialize_command(command, reinit_subcommands)
  166.  
  167.     
  168.     def run_command(self, command):
  169.         self.distribution.run_command(command)
  170.  
  171.     
  172.     def get_sub_commands(self):
  173.         commands = []
  174.         for cmd_name, method in self.sub_commands:
  175.             if method is None or method(self):
  176.                 commands.append(cmd_name)
  177.                 continue
  178.         
  179.         return commands
  180.  
  181.     
  182.     def warn(self, msg):
  183.         sys.stderr.write('warning: %s: %s\n' % (self.get_command_name(), msg))
  184.  
  185.     
  186.     def execute(self, func, args, msg = None, level = 1):
  187.         util.execute(func, args, msg, dry_run = self.dry_run)
  188.  
  189.     
  190.     def mkpath(self, name, mode = 511):
  191.         dir_util.mkpath(name, mode, dry_run = self.dry_run)
  192.  
  193.     
  194.     def copy_file(self, infile, outfile, preserve_mode = 1, preserve_times = 1, link = None, level = 1):
  195.         return file_util.copy_file(infile, outfile, preserve_mode, preserve_times, not (self.force), link, dry_run = self.dry_run)
  196.  
  197.     
  198.     def copy_tree(self, infile, outfile, preserve_mode = 1, preserve_times = 1, preserve_symlinks = 0, level = 1):
  199.         return dir_util.copy_tree(infile, outfile, preserve_mode, preserve_times, preserve_symlinks, not (self.force), dry_run = self.dry_run)
  200.  
  201.     
  202.     def move_file(self, src, dst, level = 1):
  203.         return file_util.move_file(src, dst, dry_run = self.dry_run)
  204.  
  205.     
  206.     def spawn(self, cmd, search_path = 1, level = 1):
  207.         spawn = spawn
  208.         import distutils.spawn
  209.         spawn(cmd, search_path, dry_run = self.dry_run)
  210.  
  211.     
  212.     def make_archive(self, base_name, format, root_dir = None, base_dir = None):
  213.         return archive_util.make_archive(base_name, format, root_dir, base_dir, dry_run = self.dry_run)
  214.  
  215.     
  216.     def make_file(self, infiles, outfile, func, args, exec_msg = None, skip_msg = None, level = 1):
  217.         if exec_msg is None:
  218.             exec_msg = 'generating %s from %s' % (outfile, string.join(infiles, ', '))
  219.         
  220.         if skip_msg is None:
  221.             skip_msg = 'skipping %s (inputs unchanged)' % outfile
  222.         
  223.         if type(infiles) is StringType:
  224.             infiles = (infiles,)
  225.         elif type(infiles) not in (ListType, TupleType):
  226.             raise TypeError, "'infiles' must be a string, or a list or tuple of strings"
  227.         
  228.         if self.force or dep_util.newer_group(infiles, outfile):
  229.             self.execute(func, args, exec_msg, level)
  230.         else:
  231.             log.debug(skip_msg)
  232.  
  233.  
  234.  
  235. class install_misc(Command):
  236.     user_options = [
  237.         ('install-dir=', 'd', 'directory to install the files to')]
  238.     
  239.     def initialize_options(self):
  240.         self.install_dir = None
  241.         self.outfiles = []
  242.  
  243.     
  244.     def _install_dir_from(self, dirname):
  245.         self.set_undefined_options('install', (dirname, 'install_dir'))
  246.  
  247.     
  248.     def _copy_files(self, filelist):
  249.         self.outfiles = []
  250.         if not filelist:
  251.             return None
  252.         self.mkpath(self.install_dir)
  253.         for f in filelist:
  254.             self.copy_file(f, self.install_dir)
  255.             self.outfiles.append(os.path.join(self.install_dir, f))
  256.         
  257.  
  258.     
  259.     def get_outputs(self):
  260.         return self.outfiles
  261.  
  262.  
  263. if __name__ == '__main__':
  264.     print 'ok'
  265.  
  266.