equal
deleted
inserted
replaced
19 # along with this program; if not, write to the Free Software |
19 # along with this program; if not, write to the Free Software |
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 |
21 |
22 from mercurial import hg, util |
22 from mercurial import hg, util |
23 import os |
23 import os |
|
24 |
|
25 def _(s): |
|
26 return s |
24 |
27 |
25 class Purge(object): |
28 class Purge(object): |
26 def __init__(self, act=True, abort_on_err=False): |
29 def __init__(self, act=True, abort_on_err=False): |
27 self._repo = None |
30 self._repo = None |
28 self._ui = None |
31 self._ui = None |
58 |
61 |
59 def _error(self, msg): |
62 def _error(self, msg): |
60 if self._abort_on_err: |
63 if self._abort_on_err: |
61 raise util.Abort(msg) |
64 raise util.Abort(msg) |
62 else: |
65 else: |
63 self._ui.warn('warning: ' + msg + '\n') |
66 self._ui.warn(_('warning: %s\n') % msg) |
64 |
67 |
65 def _remove_file(self, name): |
68 def _remove_file(self, name): |
66 relative_name = self._relative_name(name) |
69 relative_name = self._relative_name(name) |
67 # dirstate.state() requires a path relative to the root |
70 # dirstate.state() requires a path relative to the root |
68 # directory. |
71 # directory. |
71 self._ui.note(name + '\n') |
74 self._ui.note(name + '\n') |
72 if self._act: |
75 if self._act: |
73 try: |
76 try: |
74 os.remove(name) |
77 os.remove(name) |
75 except OSError, e: |
78 except OSError, e: |
76 self._error('"%s" cannot be removed' % name) |
79 self._error(_('%s cannot be removed') % name) |
77 |
80 |
78 def _remove_dir(self, name): |
81 def _remove_dir(self, name): |
79 self._ui.note(name + '\n') |
82 self._ui.note(name + '\n') |
80 if self._act: |
83 if self._act: |
81 try: |
84 try: |
82 os.rmdir(name) |
85 os.rmdir(name) |
83 except OSError, e: |
86 except OSError, e: |
84 self._error('"%s" cannot be removed' % name) |
87 self._error(_('%s cannot be removed') % name) |
85 |
88 |
86 def _relative_name(self, path): |
89 def _relative_name(self, path): |
87 ''' |
90 ''' |
88 Returns "path" but relative to the root directory of the |
91 Returns "path" but relative to the root directory of the |
89 repository and with '\\' replaced with '/'. |
92 repository and with '\\' replaced with '/'. |
156 p.purge(ui, repo, paths) |
159 p.purge(ui, repo, paths) |
157 |
160 |
158 |
161 |
159 cmdtable = { |
162 cmdtable = { |
160 'purge': (purge, |
163 'purge': (purge, |
161 [('a', 'abort-on-err', None, 'abort if an error occurs'), |
164 [('a', 'abort-on-err', None, _('abort if an error occurs')), |
162 ('n', 'nothing', None, 'do nothing on files, useful with --verbose'), |
165 ('n', 'nothing', None, _('do nothing on files, useful with --verbose')), |
163 ], |
166 ], |
164 'hg purge [OPTIONS] [NAME]') |
167 _('hg purge [OPTIONS] [NAME]')) |
165 } |
168 } |