[PATCH 09 of 13] Use nested functions instead of object methods
Emanuele Aina
faina.mail at tiscali.it
Tue Feb 27 07:06:09 UTC 2007
# HG changeset patch
# User Emanuele Aina <em at nerd.ocracy.org>
# Date 1172563536 -3600
# Node ID 0f9e732424724ad3ea74dc730b8440494bcc19b2
# Parent e19d0f6da2049c8e319e9648764d0e11c85ac5b3
Use nested functions instead of object methods
diff --git a/contrib/purge/purge.py b/contrib/purge/purge.py
--- a/contrib/purge/purge.py
+++ b/contrib/purge/purge.py
@@ -33,6 +33,21 @@ class Purge(object):
self._repo = repo
self._ui = ui
+ def error(self, msg):
+ if self._abort_on_err:
+ raise util.Abort(msg)
+ else:
+ self._ui.warn(_('warning: %s\n') % msg)
+
+ def remove(remove_func, name):
+ if self._act:
+ try:
+ remove_func(os.path.join(self._repo.root, name))
+ except OSError, e:
+ error(_('%s cannot be removed') % name)
+ else:
+ self._ui.write('%s%s' % (name, self._eol))
+
if not dirs:
dirs = [repo.root]
@@ -51,30 +66,16 @@ class Purge(object):
for f in files:
if f not in self._repo.dirstate:
self._ui.note(_('Removing file %s\n') % f)
- self._remove(os.remove, f)
+ remove(os.remove, f)
for f in directories[::-1]:
if not os.listdir(os.path.join(repo.root, f)):
self._ui.note(_('Removing directory %s\n') % f)
- self._remove(os.rmdir, f)
+ remove(os.rmdir, f)
self._repo = None
self._ui = None
- def _error(self, msg):
- if self._abort_on_err:
- raise util.Abort(msg)
- else:
- self._ui.warn(_('warning: %s\n') % msg)
-
- def _remove(self, remove_func, name):
- if self._act:
- try:
- remove_func(os.path.join(self._repo.root, name))
- except OSError, e:
- self._error(_('%s cannot be removed') % name)
- else:
- self._ui.write('%s%s' % (name, self._eol))
def purge(ui, repo, *dirs, **opts):
More information about the Mercurial-devel
mailing list