You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Greg Stein <gs...@lyra.org> on 2003/10/13 21:57:36 UTC

Re: svn commit: rev 7367 - trunk/tools/dev

On Thu, Oct 09, 2003 at 02:51:05PM -0500, fitz@tigris.org wrote:
>...
> +++ trunk/tools/dev/scramble-tree.py	Thu Oct  9 14:51:04 2003
>...
> +  def walker_callback(self, baselen, dirname, fnames):
> +    if ((dirname.find('.svn') != -1)
> +        or dirname.find('CVS') != -1):

If you're going to use string methods, then you may as well go all the way
and remove the use of the 'string' module. Note that the above code can
falsely select '.svnfoobar' or somesuch.

>...
> +    self.file_modders = {0: self.append_to_file,
> +                         1: self.append_to_file,
> +                         2: self.append_to_file,                         
> +                         3: self.remove_from_file,
> +                         4: self.remove_from_file,
> +                         5: self.remove_from_file,
> +                         6: self.delete_file,
> +                         }

Seems a bit complicated. See below.

> +    self.rand = random.Random(seed)
> +
> +
> +  def shrink_list(self, list):
> +    # remove 5 random lines
> +    if len(list) < 6:
> +      return list
> +    for i in range(5):
> +      j = self.rand.randint(0, len(list) - 1)
> +      del list[j]

.randint() is deprecated. Use self.rand.randrange(len(list))

>...
> +  def remove_from_file(self):
> +    print 'remove_from_file:', self.path
> +    fh= open(self.path, "r")

Space before equals.

> +    lines = self.shrink_list(fh.readlines())
> +    fh.close()
> +
> +    fh= open(self.path, "w")
> +    for l in lines:
> +      fh.write(l)
> +    fh.close()

f = open() ; do something ; f.close() ... just do:

  open(self.path, 'r').readlines()

Or somesuch. Also note:

  open(self.path, 'w').writelines(lines)

>...
> +  def munge_file(self, path):
> +    self.path = path
> +    # Only do something 33% of the time
> +    num = self.rand.randint(0, len(self.file_modders) * 3)
> +    if not self.file_modders.has_key(num):
> +      return
> +    else:
> +      method = self.file_modders[num]
> +      method()

I'd suggest simplifying like:

  self.file_modders = [ self.append_to_file,
                        self.append_to_file,
			...
			self.delete_file,
			]
  ...
  
  # Only do something 33% of the time
  if self.rand.randrange(3) == 0:
    self.rand.choice(self.file_modders)()

You might also consider passing the path as an argument rather than
sneaking it around via an instance variable.

> +
> +
> +  def maybe_add_file(self, dir):
> +    if self.rand.randint(1,3) == 3:
> +      path = os.path.join(dir, 'newfile.txt')
> +      print "maybe_add_file:", path
> +      fh = open(path, 'w')
> +      fh.write(self.greeking)
> +      fh.close()

  open(...).write(self.greeking)

>...

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: svn commit: rev 7367 - trunk/tools/dev

Posted by "B. W. Fitzpatrick" <fi...@red-bean.com>.
Applied in 7422.  Thanks!

-Fitz

--
Brian W. Fitzpatrick    <fi...@red-bean.com>   http://www.red-bean.com/fitz/


Greg Stein <gs...@lyra.org> writes:
> On Thu, Oct 09, 2003 at 02:51:05PM -0500, fitz@tigris.org wrote:
> >...
> > +++ trunk/tools/dev/scramble-tree.py	Thu Oct  9 14:51:04 2003
> >...
> > +  def walker_callback(self, baselen, dirname, fnames):
> > +    if ((dirname.find('.svn') != -1)
> > +        or dirname.find('CVS') != -1):
> 
> If you're going to use string methods, then you may as well go all the way
> and remove the use of the 'string' module. Note that the above code can
> falsely select '.svnfoobar' or somesuch.

...&c.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org