Commit 8afb6416beee527489061dc36ecb9da6ce753527

Authored by Quillot Mathias
1 parent 6b32d8c5b6
Exists in master

Just converting some french sentences into english

Showing 1 changed file with 3 additions and 3 deletions Inline Diff

1 1
2 class SubCommandRunner: 2 class SubCommandRunner:
3 """This class provides a simple way to call subcommands 3 """This class provides a simple way to call subcommands
4 from argparsers ones. Soon, we will add some examples to 4 from argparsers ones. Soon, we will add some examples to
5 into the documentation. 5 into the documentation.
6 """ 6 """
7 7
8 def __init__(self, choice_dict): 8 def __init__(self, choice_dict):
9 """Initialisation of choices 9 """Initialisation of choices
10 10
11 Args: 11 Args:
12 choice_dict (dict): A dictionary where each string key is associated 12 choice_dict (dict): A dictionary where each string key is associated
13 to a function to call. 13 to a function to call.
14 """ 14 """
15 self._choice_dict = choice_dict 15 self._choice_dict = choice_dict
16 16
17 def run(self, choice, args=None, remove=[]): 17 def run(self, choice, args=None, remove=[]):
18 """Run a function as the choice key. 18 """Run a function as the choice key.
19 19
20 Args: 20 Args:
21 choice (str): [description] 21 choice (str): [description]
22 args (dict, optional): dictionnary of arguments. Defaults to None. 22 args (dict, optional): dictionnary of arguments. Defaults to None.
23 remove (list, optional): list of key to remove from arguments. Defaults to []. 23 remove (list, optional): list of key to remove from arguments. Defaults to [].
24 """ 24 """
25 if args is not None: 25 if args is not None:
26 copy_dict = args.copy() 26 copy_dict = args.copy()
27 if type(remove) == list: 27 if type(remove) == list:
28 [copy_dict.pop(v) for v in remove] 28 [copy_dict.pop(v) for v in remove]
29 else: 29 else:
30 copy_dict.pop(remove) 30 copy_dict.pop(remove)
31 31
32 try: 32 try:
33 if args is None: 33 if args is None:
34 self._choice_dict.get(choice)() 34 self._choice_dict.get(choice)()
35 else: 35 else:
36 self._choice_dict.get(choice)(**copy_dict) 36 self._choice_dict.get(choice)(**copy_dict)
37 except TypeError as e: 37 except TypeError as e:
38 print("TYPE ERROR HANDLED") 38 print("TYPE ERROR HANDLED")
39 print("Value of args: ", args) 39 print("Value of args: ", args)
40 raise(e) 40 raise(e)
41 41
42 if __name__ == "__main__": 42 if __name__ == "__main__":
43 ''' Just a dumb function ''' 43 ''' Just a dumb function '''
44 def dumb1(): 44 def dumb1():
45 print("Dumb 1") 45 print("Dumb 1")
46 46
47 ''' Just a dumb function with one parameter ''' 47 ''' Just a dumb function with one parameter '''
48 def dumb2(param1): 48 def dumb2(param1):
49 print("Dumb 2: ", param1) 49 print("Dumb 2: ", param1)
50 50
51 print("Utils run mode is just used to test implementation of class and function implementation.") 51 print("Utils run mode is just used to test implementation of class and function implementation.")
52 52
53 runner = SubCommandRunner({ 53 runner = SubCommandRunner({
54 "dumb1": dumb1, 54 "dumb1": dumb1,
55 "dumb2": dumb2 55 "dumb2": dumb2
56 }) 56 })
57 57
58 dumb2_args = { 58 dumb2_args = {
59 "param1": "Le paramètre 1" 59 "param1": "Parameter 1"
60 } 60 }
61 61
62 dumb2_args_which = { 62 dumb2_args_which = {
63 "param1": "Le paramètre 1 une seconde fois", 63 "param1": "Parameter one a second time",
64 "which": "which value usally defined and need to be removed" 64 "which": "which value usally defined and need to be removed"
65 } 65 }
66 66
67 dumb2_args_which_array = { 67 dumb2_args_which_array = {
68 "param1": "Le paramètre 1 une troisième fois", 68 "param1": "Parameter one a third time",
69 "which": "which value usally defined and need to be removed", 69 "which": "which value usally defined and need to be removed",
70 "param2": "Imagine you want to remove multiple values" 70 "param2": "Imagine you want to remove multiple values"
71 } 71 }
72 72
73 runner.run("dumb1", None) 73 runner.run("dumb1", None)
74 runner.run("dumb2", dumb2_args) 74 runner.run("dumb2", dumb2_args)
75 runner.run("dumb2", dumb2_args_which, remove="which") 75 runner.run("dumb2", dumb2_args_which, remove="which")
76 runner.run("dumb2", dumb2_args_which_array, remove=["which", "param2"]) 76 runner.run("dumb2", dumb2_args_which_array, remove=["which", "param2"])