[Spambayes-checkins] spambayes rebal.py,1.2,1.3

Tim Peters tim_one@users.sourceforge.net
Fri, 13 Sep 2002 20:32:49 -0700


Update of /cvsroot/spambayes/spambayes
In directory usw-pr-cvs1:/tmp/cvs-serv832

Modified Files:
	rebal.py 
Log Message:
migrate():  If there's a file extension, preserve it instead of blowing
up (files w/o extensions are a PITA on Windows).  Also replaced the
renaming strategy w/ a randomized scheme that should run much faster.


Index: rebal.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/rebal.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** rebal.py	12 Sep 2002 19:33:54 -0000	1.2
--- rebal.py	14 Sep 2002 03:32:47 -0000	1.3
***************
*** 18,22 ****
  must already exist.
  
! Example: 
  
      rebal.py -r reservoir -s Set -n 300
--- 18,22 ----
  must already exist.
  
! Example:
  
      rebal.py -r reservoir -s Set -n 300
***************
*** 64,83 ****
     -Q     - be quiet and don't confirm moves
  """ % globals()
!     
  def migrate(f, dir, verbose):
      """rename f into dir, making sure to avoid name clashes."""
      base = os.path.split(f)[-1]
!     if os.path.exists(os.path.join(dir,base)):
!         # this path can get slow if we have a lot of name collisions
!         # but we should rarely encounter that case (so he says smugly)
!         reslist = [int(n) for n in os.listdir(dir)]
!         reslist.sort()
!         out = os.path.join(dir, "%d"%(reslist[-1]+1))
!     else:
!         out = os.path.join(dir, base)
      if verbose:
          print "moving", f, "to", out
      os.rename(f, out)
!     
  def main(args):
      nperdir = NPERDIR
--- 64,80 ----
     -Q     - be quiet and don't confirm moves
  """ % globals()
! 
  def migrate(f, dir, verbose):
      """rename f into dir, making sure to avoid name clashes."""
      base = os.path.split(f)[-1]
!     out = os.path.join(dir, base)
!     while os.path.exists(out):
!         basename, ext = os.path.splitext(base)
!         digits = random.randrange(100000000)
!         out = os.path.join(dir, str(digits) + ext)
      if verbose:
          print "moving", f, "to", out
      os.rename(f, out)
! 
  def main(args):
      nperdir = NPERDIR
***************
*** 86,90 ****
      verbose = VERBOSE
      confirm = CONFIRM
!     
      try:
          opts, args = getopt.getopt(args, "r:s:n:vqcQh")
--- 83,87 ----
      verbose = VERBOSE
      confirm = CONFIRM
! 
      try:
          opts, args = getopt.getopt(args, "r:s:n:vqcQh")