Mercurial > hg-allpaths
comparison mercurial_all_paths.py @ 13:8cca585b11cc
Module renamed to mercurial_all_paths for possible pypi installation.
Extended README.
author | Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl> |
---|---|
date | Sun, 15 Nov 2015 10:16:21 +0100 |
parents | allpaths.py@bed42905e871 |
children | 9d595bda6f2f |
comparison
equal
deleted
inserted
replaced
12:bed42905e871 | 13:8cca585b11cc |
---|---|
1 # allpaths.py - execute commands on multiple paths | |
2 # | |
3 # This software may be used and distributed according to the terms of | |
4 # the GNU General Public License version 2 or any later version. | |
5 | |
6 '''execute commands on multiple paths''' | |
7 | |
8 import mercurial.util | |
9 import mercurial.commands | |
10 import mercurial.cmdutil | |
11 from mercurial.i18n import _ | |
12 | |
13 #pylint:disable=invalid-name,broad-except,line-too-long | |
14 | |
15 | |
16 def _iter_over_paths(command, ui, repo, **opts): | |
17 """execute given command on multiple paths""" | |
18 # Extract our options and filter them out | |
19 group = opts.pop('group', None) or 'paths' | |
20 ignore_errors = opts.pop('ignore_errors', None) | |
21 | |
22 # Get the paths to push to. | |
23 paths = ui.configitems(group) | |
24 if not paths: | |
25 raise mercurial.util.Abort(_('No paths defined in section %s') % group) | |
26 | |
27 # Used to avoid handling duplicate paths twice | |
28 handled = {} | |
29 | |
30 # Act! | |
31 for alias, path in paths: | |
32 if path in handled: | |
33 ui.note(_("Skipping %s as it aliases already handled %s\n") % (alias, handled[path])) | |
34 else: | |
35 handled[path] = alias | |
36 try: | |
37 command(ui, repo, path, **opts) | |
38 except Exception as e: | |
39 if not ignore_errors: | |
40 raise | |
41 ui.warn(_('error handling %s: %s') % (path[1], e)) | |
42 | |
43 | |
44 def pushall(ui, repo, **opts): | |
45 """execute pull on multiple paths""" | |
46 _iter_over_paths(mercurial.commands.push, ui, repo, **opts) | |
47 | |
48 | |
49 def pullall(ui, repo, **opts): | |
50 """execute push on multiple paths""" | |
51 _iter_over_paths(mercurial.commands.pull, ui, repo, **opts) | |
52 | |
53 | |
54 def incomingall(ui, repo, **opts): | |
55 """execute incoming on multiple paths""" | |
56 _iter_over_paths(mercurial.commands.incoming, ui, repo, **opts) | |
57 | |
58 | |
59 def outgoingall(ui, repo, **opts): | |
60 """execute outgoing on multiple paths""" | |
61 _iter_over_paths(mercurial.commands.outgoing, ui, repo, **opts) | |
62 | |
63 | |
64 def _original_options(cmdname): | |
65 """Gets list of given command options as specified in Mercurial core""" | |
66 _, spec = mercurial.cmdutil.findcmd(cmdname, mercurial.commands.table) | |
67 return spec[1] | |
68 | |
69 | |
70 EXT_OPTS = [ | |
71 ('g', 'group', 'paths', _('use a named group of paths')), | |
72 ('', 'ignore-errors', None, _('continue execution despite errors')), | |
73 ] | |
74 | |
75 cmdtable = { | |
76 "pushall": ( | |
77 pushall, | |
78 EXT_OPTS + _original_options('push'), | |
79 _('[-g GROUP] [--ignore-errors] <push options>')), | |
80 "pullall": ( | |
81 pullall, | |
82 EXT_OPTS + _original_options('pull'), | |
83 _('[-g GROUP] [--ignore-errors] <pull options>')), | |
84 "incomingall": ( | |
85 incomingall, | |
86 EXT_OPTS + _original_options('incoming'), | |
87 _('[-g GROUP] [--ignore-errors] <incoming options>')), | |
88 "outgoingall": ( | |
89 outgoingall, | |
90 EXT_OPTS + _original_options('outgoing'), | |
91 _('[-g GROUP] [--ignore-errors] <outgoing options>')), | |
92 } |