New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gsoc: Make "Chain Actions" default #4603

Merged
merged 1 commit into from Aug 22, 2017
Jump to file or symbol
Failed to load files and symbols.
+98 −250
Diff settings

Always

Just for now

Make "Chain Actions" default

User can choose if wants more actions to be applied in a single input.
This deletes the action "Chain Actions"

Closes #4602
  • Loading branch information...
Nosferatul committed Aug 1, 2017
commit 0911078532a49c42afb06effec750be24a7b4139
@@ -18,7 +18,6 @@
from coalib.results.result_actions.OpenEditorAction import OpenEditorAction
from coalib.results.result_actions.IgnoreResultAction import IgnoreResultAction
from coalib.results.result_actions.DoNothingAction import DoNothingAction
from coalib.results.result_actions.ChainPatchAction import ChainPatchAction
from coalib.results.result_actions.ShowAppliedPatchesAction import (
ShowAppliedPatchesAction)
from coalib.results.result_actions.PrintDebugMessageAction import (
@@ -89,7 +88,6 @@ def highlight_text(no_color, text, lexer=TextLexer(), style=None):
PrintMoreInfoAction(),
ShowPatchAction(),
IgnoreResultAction(),
ChainPatchAction(),
ShowAppliedPatchesAction())
DIFF_EXCERPT_MAX_SIZE = 4
@@ -627,14 +625,18 @@ def choose_action(console_printer, actions, apply_single=False):
:param actions: Actions available to the user.
:param apply_single: The action that should be applied for all results.
If it's not selected, has a value of False.
:return: Return choice of action of user.
:return: Return a tuple of lists, a list with the names of
actions that needs to be applied and a list with
with the description of the actions.
"""
actions.insert(0, DoNothingAction().get_metadata())
actions_desc = []
actions_name = []
if apply_single:
for i, action in enumerate(actions, 0):
if apply_single == action.desc:
return i
return 0
return ([action.desc], [action.name])
return (['Do (N)othing'], ['Do (N)othing'])
else:
while True:
for i, action in enumerate(actions, 0):
@@ -645,48 +647,34 @@ def choose_action(console_printer, actions, apply_single=False):
line = format_lines(STR_ENTER_NUMBER, symbol='[')
choice = input(line)
if not choice:
return 0
choice = str(choice)
if choice.isalpha():
choice = choice.upper()
choice = '(' + choice + ')'
for i, action in enumerate(actions, 0):
if choice in action.desc:
return i
elif choice.isnumeric():
choice = int(choice)
if 0 <= choice <= len(actions):
return choice
console_printer.print(format_lines(
'Please enter a valid letter.', symbol='['))
def print_actions(console_printer, section, actions, failed_actions,
apply_single):
"""
Prints the given actions and lets the user choose.
:param console_printer: Object to print messages on the console.
:param actions: A list of FunctionMetadata objects.
:param failed_actions: A set of all actions that have failed. A failed
action remains in the list until it is
successfully executed.
:param apply_single: The action that should be applied for all results.
If it's not selected, has a value of False.
:return: A tuple with the name member of the
FunctionMetadata object chosen by the user
and a Section containing at least all needed
values for the action. If the user did
choose to do nothing, return (None, None).
"""
choice = choose_action(console_printer, actions, apply_single)
if choice == 0:
return None, None
for c in choice:
c = str(c)
actions_desc_len = len(actions_desc)
if c.isnumeric():
for i, action in enumerate(actions, 0):
c = int(c)
if i == c:
actions_desc.append(action.desc)
actions_name.append(action.name)
break
elif c.isalpha():
c = c.upper()
c = '(' + c + ')'
for i, action in enumerate(actions, 1):
if c in action.desc:
actions_desc.append(action.desc)
actions_name.append(action.name)
break
if actions_desc_len == len(actions_desc):
console_printer.print(format_lines(
'Please enter a valid letter.', symbol='['))
return get_action_info(section, actions[choice], failed_actions)
if not choice:
actions_desc.append(DoNothingAction().get_metadata().desc)
actions_name.append(DoNothingAction().get_metadata().name)
return (actions_desc, actions_name)
def try_to_apply_action(action_name,
@@ -742,85 +730,6 @@ def try_to_apply_action(action_name,
failed_actions.add(action_name)
def apply_chain_action(console_printer,
section,
metadata_list,
action_dict,
failed_actions,
result,
file_diff_dict,
file_dict,
applied_actions):
"""
Asks the user for an action and applies it.
:param console_printer: Object to print messages on the console.
:param section: Currently active section.
:param metadata_list: Contains metadata for all the actions.
:param action_dict: Contains the action names as keys and their
references as values.
:param failed_actions: A set of all actions that have failed. A failed
action remains in the list until it is successfully
executed.
:param result: Result corresponding to the actions.
:param file_diff_dict: If it is an action which applies a patch, this
contains the diff of the patch to be applied to
the file with filename as keys.
:param file_dict: Dictionary with filename as keys and its contents
as values.
:param applied_actions: A dictionary that contains the result, file_dict,
file_diff_dict and the section for an action.
:return: Return False if the action that is applied is Do
(N)othing or True otherwise.
"""
flag = False
action_list = str(section['actions'])
action_list = list(action_list)
for action_choice in action_list:
if action_choice.isalpha():
action_choice = action_choice.upper()
action_choice = '(' + action_choice + ')'
if action_choice == '(N)':
return False
flag = False
for action_n in metadata_list:
if action_choice in action_n.desc:
chosen_action = action_dict[action_n.name]
action_choice_made = action_choice
flag = True
break
if flag:
for index, action_details in enumerate(metadata_list, 1):
if action_choice_made in action_details.desc:
action_name, section = get_action_info(
section, metadata_list[index-1], failed_actions)
try_to_apply_action(action_name,
chosen_action,
console_printer,
section,
metadata_list,
action_dict,
failed_actions,
result,
file_diff_dict,
file_dict,
applied_actions)
else:
console_printer.print(
format_lines('Couldn\'t apply \'{}\''.format(
action_choice), symbol='['),
color=HIGHLIGHTED_CODE_COLOR)
else:
console_printer.print(
format_lines('Please enter a letter'.format(
action_choice), symbol='['),
color=HIGHLIGHTED_CODE_COLOR)
section.delete_setting('actions')
return True
def ask_for_action_and_apply(console_printer,
section,
metadata_list,
@@ -856,37 +765,52 @@ def ask_for_action_and_apply(console_printer,
it makes sense that the user may choose to execute
another action, False otherwise.
"""
action_name, section = print_actions(console_printer, section,
metadata_list, failed_actions,
apply_single=apply_single)
if action_name is None:
return False
if action_name == 'ChainPatchAction':
ret = apply_chain_action(console_printer,
section,
metadata_list,
action_dict,
failed_actions,
result,
file_diff_dict,
file_dict,
applied_actions)
return ret
actions_desc, actions_name = choose_action(console_printer, metadata_list,
apply_single)
if apply_single:
if apply_single == 'Do (N)othing':
return False
for index, action_details in enumerate(metadata_list, 1):
if apply_single == action_details.desc:
action_name, section = get_action_info(
section, metadata_list[index - 1], failed_actions)
chosen_action = action_dict[action_details.name]
try_to_apply_action(action_name,
chosen_action,
console_printer,
section,
metadata_list,
action_dict,
failed_actions,
result,
file_diff_dict,
file_dict,
applied_actions)
else:
chosen_action = action_dict[action_name]
try_to_apply_action(action_name,
chosen_action,
console_printer,
section,
metadata_list,
action_dict,
failed_actions,
result,
file_diff_dict,
file_dict,
applied_actions)
return True
for action_choice, action_choice_name in zip(actions_desc,
actions_name):
if action_choice == 'Do (N)othing':
return False
chosen_action = action_dict[action_choice_name]
action_choice_made = action_choice
for index, action_details in enumerate(metadata_list, 1):
if action_choice_made in action_details.desc:
action_name, section = get_action_info(
section, metadata_list[index-1], failed_actions)
try_to_apply_action(action_name,
chosen_action,
console_printer,
section,
metadata_list,
action_dict,
failed_actions,
result,
file_diff_dict,
file_dict,
applied_actions)
return True
def show_enumeration(console_printer,
@@ -16,7 +16,6 @@
from coalib.results.result_actions.DoNothingAction import DoNothingAction
from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction
from coalib.results.result_actions.IgnoreResultAction import IgnoreResultAction
from coalib.results.result_actions.ChainPatchAction import ChainPatchAction
from coalib.results.result_actions.ShowAppliedPatchesAction \
import ShowAppliedPatchesAction
from coalib.results.result_actions.PrintDebugMessageAction import (
@@ -33,7 +32,6 @@
PrintDebugMessageAction,
ShowPatchAction,
IgnoreResultAction,
ChainPatchAction,
ShowAppliedPatchesAction]

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.