comparison mercurial_all_paths.py @ 77:772d75b1a030

Fallback to normal Mercurial API if `mercurial_extension_utils` isn't found.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 20 Aug 2017 16:24:22 -0700
parents 03cc0603800e
children 02b85549369b
comparison
equal deleted inserted replaced
76:03cc0603800e 77:772d75b1a030
5 # This software may be used and distributed according to the terms of 5 # This software may be used and distributed according to the terms of
6 # the GNU General Public License version 2 or any later version. 6 # the GNU General Public License version 2 or any later version.
7 7
8 '''execute commands on multiple paths''' 8 '''execute commands on multiple paths'''
9 9
10 import os
11 import sys
10 import mercurial.util 12 import mercurial.util
11 import mercurial.commands 13 import mercurial.commands
12 import mercurial.cmdutil 14 import mercurial.cmdutil
13 from mercurial.i18n import _ 15 from mercurial.i18n import _
14 16
29 os.path.join(os.path.dirname(my_dir), "mercurial-extension_utils"), 31 os.path.join(os.path.dirname(my_dir), "mercurial-extension_utils"),
30 ]) 32 ])
31 try: 33 try:
32 import mercurial_extension_utils 34 import mercurial_extension_utils
33 except ImportError: 35 except ImportError:
34 raise mercurial.util.Abort(_("""Can not import mercurial_extension_utils. 36 return None
35 Please install this module in Python path.
36 See Installation chapter in https://bitbucket.org/Mekk/mercurial-dynamic_username/ for details
37 (and for info about TortoiseHG on Windows, or other bundled Python)."""))
38 37
39 if not hasattr(mercurial_extension_utils, 'command'): 38 if not hasattr(mercurial_extension_utils, 'command'):
40 raise mercurial.util.Abort(_("""Your mercurial_extension_utils is outdated. 39 raise mercurial.util.Abort(_("""Your mercurial_extension_utils is outdated.
41 See Installation chapter in https://bitbucket.org/Mekk/mercurial-dynamic_username/ for details.""")) 40 See Installation chapter in https://bitbucket.org/Mekk/mercurial-dynamic_username/ for details."""))
42 41
43 return mercurial_extension_utils 42 return mercurial_extension_utils
44 43
45 meu = import_meu() 44 meu = import_meu()
45 if meu:
46 command_decorator = meu.command
47 else:
48 command_decorator = mercurial.cmdutil.command
46 49
47 50
48 # pylint:disable=invalid-name,broad-except,line-too-long 51 # pylint:disable=invalid-name,broad-except,line-too-long
49 52
50 def _find_all_paths(ui, skip_ignored=False, sort_by_priority=False): 53 def _find_all_paths(ui, skip_ignored=False, sort_by_priority=False):
149 _, spec = mercurial.cmdutil.findcmd(cmdname, mercurial.commands.table) 152 _, spec = mercurial.cmdutil.findcmd(cmdname, mercurial.commands.table)
150 return spec[1] 153 return spec[1]
151 154
152 155
153 cmdtable = {} 156 cmdtable = {}
154 command = meu.command(cmdtable) 157 command = command_decorator(cmdtable)
155 158
156 159
157 @command("pushall", 160 @command("pushall",
158 EXT_OPTS + _original_options('push'), 161 EXT_OPTS + _original_options('push'),
159 _('[-g GROUP] [--ignore-errors] <push options>')) 162 _('[-g GROUP] [--ignore-errors] <push options>'))