4 from cola
.i18n
import N_
7 class Interaction(object):
8 """Prompts the user and answers questions"""
10 VERBOSE
= bool(os
.getenv('GIT_COLA_VERBOSE'))
13 def information(title
,
14 message
=None, details
=None, informative_text
=None):
18 scope
['title'] = title
19 scope
['title_dashes'] = '-' * len(title
)
20 scope
['message'] = message
21 scope
['details'] = details
and '\n'+details
or ''
22 scope
['informative_text'] = (informative_text
and
23 '\n'+informative_text
or '')
27 %(message)s%(details)s%(informative_text)s""" % scope
)
30 def critical(cls
, title
, message
=None, details
=None):
31 """Show a warning with the provided title and message."""
32 cls
.information(title
, message
=message
, details
=details
)
35 def confirm(cls
, title
, text
, informative_text
, ok_text
,
36 icon
=None, default
=True):
38 cls
.information(title
, message
=text
,
39 informative_text
=informative_text
)
41 prompt
= '%s? [Y/n]:' % ok_text
43 prompt
= '%s? [y/N]: ' % ok_text
44 answer
= raw_input(prompt
)
47 return answer
.lower().startswith('y')
50 def question(cls
, title
, message
, default
=True):
51 return cls
.confirm(title
, message
, '',
52 ok_text
=N_('Continue'), default
=default
)
55 def run_command(cls
, title
, cmd
):
56 cls
.log('$ ' + subprocess
.list2cmdline(cmd
))
57 status
, out
, err
= core
.run_command(cmd
)
58 cls
.log_status(status
, out
, err
)
61 def confirm_config_action(cls
, name
, opts
):
62 return cls
.confirm(N_('Run %s?') % name
,
63 N_('Run the "%s" command?') % name
,
67 def log_status(cls
, status
, out
, err
=None):
69 (out
and ((N_('Output: %s') % out
) + '\n') or '') +
70 (err
and ((N_('Errors: %s') % err
) + '\n') or '') +
71 N_('Exit code: %s') % status
76 def log(cls
, message
):