home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2417 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.9 KB  |  63 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import distutils
  5. import os
  6. from setuptools import Command
  7. from distutils.util import convert_path
  8. from distutils import log
  9. from distutils.errors import *
  10.  
  11. class rotate(Command):
  12.     description = 'delete older distributions, keeping N newest files'
  13.     user_options = [
  14.         ('match=', 'm', 'patterns to match (required)'),
  15.         ('dist-dir=', 'd', 'directory where the distributions are'),
  16.         ('keep=', 'k', 'number of matching distributions to keep')]
  17.     boolean_options = []
  18.     
  19.     def initialize_options(self):
  20.         self.match = None
  21.         self.dist_dir = None
  22.         self.keep = None
  23.  
  24.     
  25.     def finalize_options(self):
  26.         if self.match is None:
  27.             raise DistutilsOptionError("Must specify one or more (comma-separated) match patterns (e.g. '.zip' or '.egg')")
  28.         self.match is None
  29.         if self.keep is None:
  30.             raise DistutilsOptionError('Must specify number of files to keep')
  31.         self.keep is None
  32.         
  33.         try:
  34.             self.keep = int(self.keep)
  35.         except ValueError:
  36.             raise DistutilsOptionError('--keep must be an integer')
  37.  
  38.         self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
  39.  
  40.     
  41.     def run(self):
  42.         self.run_command('egg_info')
  43.         glob = glob
  44.         import glob
  45.         for pattern in self.match:
  46.             pattern = self.distribution.get_name() + '*' + pattern
  47.             files = glob(os.path.join(self.dist_dir, pattern))
  48.             files = [ (os.path.getmtime(f), f) for f in files ]
  49.             files.sort()
  50.             files.reverse()
  51.             log.info('%d file(s) matching %s', len(files), pattern)
  52.             files = files[self.keep:]
  53.             for t, f in files:
  54.                 log.info('Deleting %s', f)
  55.                 if not self.dry_run:
  56.                     os.unlink(f)
  57.                     continue
  58.                 []
  59.             
  60.         
  61.  
  62.  
  63.