[Python-Dev] Slash and burn in Tools/scripts. Objections?

Tim Peters tim.one@comcast.net
Thu, 14 Mar 2002 00:05:21 -0500


[Trent Mick, on a "Traverse, maybe modify and replace" file component]
> Any pointers on which script might have the best crack at that?
> reindent.py? tabnanny.py? another?

Well, that's the rub.  They all have "a feature" and they all suck <wink>.

"Innovations" I really like:

+ An -r switch to control whether directory recursion occurs.  Sometimes
  you simply don't want to touch subdirectories at all (e.g., I don't
  dare reindent the Lib/irix5 subtree, cuz I've got no way to test it).

+ A -d switch for a "dry run", just naming the files that *would* change.

reindent does those, and cleanfuture "inherited" them via cut 'n paste.  I
think they may or may not <wink> do the right thing with symlinks too.

OTOH, a shared irritating behavior may be that there's no way to get them to
tell you about *just* the files they change (their -v is too crude).  They
also "support" -h only in the sense that any unrecognized option triggers
the usage blurb.

Their backup code is arguable.  It's good to ensure that the new file can be
written before removing the original file, and good to do some form of
backup.  Also good not to just "remove" the original file but simply rename
it.  Whether existing backups should be silently nuked is debatable.

See, e.g., Guido's old classfix.py for a different approach.  That also
renames, but renames with a tilde turd at the end (jarring on Windows;
perhaps .bak is jarring on Unix); may or may not (I can't remember how Unix
works here) give up if the tilde form already exists; and (most important)
strives to reproduce the original file's permissions.  I got out of that
habit after years of Windows, and got lazy about hunting the code down to
paste in to new tools.  Curiously, nobody ever griped!  Maybe it was
actually a YDNI (You Didn't Need It)?

BTW, classfix.py is good for something else too:  getting out of this
directory <wink>.  It's trying to "fix" scripts that haven't been legal
since before Python 1.0.  It may belong next to the even more out-of-date
eqfix.py in Demo/scripts (did you know that Python *used* to use "=" for
both assignment and equality?!).

methfix.py is also one for the museum.

OTOH, I personally never tire of chuckling over of the existence of both
md5sum.py and sum5.py <wink>.