|
3 | 3 | import os |
4 | 4 | from datetime import datetime |
5 | 5 |
|
6 | | -#import smartdispatch |
7 | | -#from smartdispatch import utils |
| 6 | +import smartdispatch |
| 7 | +from smartdispatch import utils |
8 | 8 |
|
9 | 9 | UID_TAG = "{UID}" |
10 | 10 |
|
11 | 11 |
|
12 | | -# def generate_name_from_command(command, max_length_arg=None, max_length=None): |
13 | | -# ''' Generates name from a given command. |
| 12 | +def generate_name_from_command(command, max_length_arg=None, max_length=None): |
| 13 | + ''' Generates name from a given command. |
14 | 14 |
|
15 | | -# Generate a name by replacing spaces in command with dashes and |
16 | | -# by trimming lengthty (as defined by max_length_arg) arguments. |
| 15 | + Generate a name by replacing spaces in command with dashes and |
| 16 | + by trimming lengthty (as defined by max_length_arg) arguments. |
17 | 17 |
|
18 | | -# Parameters |
19 | | -# ---------- |
20 | | -# command : str |
21 | | -# command from which to generate the name |
22 | | -# max_length_arg : int |
23 | | -# arguments longer than this will be trimmed keeping last characters (Default: inf) |
24 | | -# max_length : int |
25 | | -# trim name if longer than this keeping last characters (Default: inf) |
| 18 | + Parameters |
| 19 | + ---------- |
| 20 | + command : str |
| 21 | + command from which to generate the name |
| 22 | + max_length_arg : int |
| 23 | + arguments longer than this will be trimmed keeping last characters (Default: inf) |
| 24 | + max_length : int |
| 25 | + trim name if longer than this keeping last characters (Default: inf) |
26 | 26 |
|
27 | | -# Returns |
28 | | -# ------- |
29 | | -# name : str |
30 | | -# slugified name |
31 | | -# ''' |
32 | | -# if max_length_arg is not None: |
33 | | -# max_length_arg = min(-max_length_arg, max_length_arg) |
| 27 | + Returns |
| 28 | + ------- |
| 29 | + name : str |
| 30 | + slugified name |
| 31 | + ''' |
| 32 | + if max_length_arg is not None: |
| 33 | + max_length_arg = min(-max_length_arg, max_length_arg) |
34 | 34 |
|
35 | | -# if max_length is not None: |
36 | | -# max_length = min(-max_length, max_length) |
| 35 | + if max_length is not None: |
| 36 | + max_length = min(-max_length, max_length) |
37 | 37 |
|
38 | | -# name = '_'.join([utils.slugify(argvalue)[max_length_arg:] for argvalue in command.split()]) |
39 | | -# return name[max_length:] |
| 38 | + name = '_'.join([utils.slugify(argvalue)[max_length_arg:] for argvalue in command.split()]) |
| 39 | + return name[max_length:] |
40 | 40 |
|
41 | 41 |
|
42 | | -# def generate_name_from_arguments(arguments, max_length_arg=None, max_length=None, prefix=datetime.now().strftime('%Y-%m-%d_%H-%M-%S_')): |
43 | | -# ''' Generates name from given unfolded arguments. |
| 42 | +def generate_name_from_arguments(arguments, max_length_arg=None, max_length=None, prefix=datetime.now().strftime('%Y-%m-%d_%H-%M-%S_')): |
| 43 | + ''' Generates name from given unfolded arguments. |
44 | 44 |
|
45 | | -# Generate a name by concatenating the first and last values of every |
46 | | -# unfolded arguments and by trimming lengthty (as defined by max_length_arg) |
47 | | -# arguments. |
| 45 | + Generate a name by concatenating the first and last values of every |
| 46 | + unfolded arguments and by trimming lengthty (as defined by max_length_arg) |
| 47 | + arguments. |
48 | 48 |
|
49 | | -# Parameters |
50 | | -# ---------- |
51 | | -# arguments : list of list of str |
52 | | -# list of unfolded arguments |
53 | | -# max_length_arg : int |
54 | | -# arguments longer than this will be trimmed keeping last characters (Default: inf) |
55 | | -# max_length : int |
56 | | -# trim name if longer than this keeping last characters (Default: inf) |
57 | | -# prefix : str |
58 | | -# text to preprend to the name (Default: current datetime) |
| 49 | + Parameters |
| 50 | + ---------- |
| 51 | + arguments : list of list of str |
| 52 | + list of unfolded arguments |
| 53 | + max_length_arg : int |
| 54 | + arguments longer than this will be trimmed keeping last characters (Default: inf) |
| 55 | + max_length : int |
| 56 | + trim name if longer than this keeping last characters (Default: inf) |
| 57 | + prefix : str |
| 58 | + text to preprend to the name (Default: current datetime) |
59 | 59 |
|
60 | | -# Returns |
61 | | -# ------- |
62 | | -# name : str |
63 | | -# slugified name |
64 | | -# ''' |
65 | | -# if max_length_arg is not None: |
66 | | -# max_length_arg = min(-max_length_arg, max_length_arg) |
| 60 | + Returns |
| 61 | + ------- |
| 62 | + name : str |
| 63 | + slugified name |
| 64 | + ''' |
| 65 | + if max_length_arg is not None: |
| 66 | + max_length_arg = min(-max_length_arg, max_length_arg) |
67 | 67 |
|
68 | | -# if max_length is not None: |
69 | | -# max_length = min(-max_length, max_length) |
| 68 | + if max_length is not None: |
| 69 | + max_length = min(-max_length, max_length) |
70 | 70 |
|
71 | | -# name = [] |
72 | | -# for argvalues in arguments: |
73 | | -# argvalues = map(utils.slugify, argvalues) |
74 | | -# name.append(argvalues[0][max_length_arg:]) |
75 | | -# if len(argvalues) > 1: |
76 | | -# name[-1] += '-' + argvalues[-1][max_length_arg:] |
| 71 | + name = [] |
| 72 | + for argvalues in arguments: |
| 73 | + argvalues = map(utils.slugify, argvalues) |
| 74 | + name.append(argvalues[0][max_length_arg:]) |
| 75 | + if len(argvalues) > 1: |
| 76 | + name[-1] += '-' + argvalues[-1][max_length_arg:] |
77 | 77 |
|
78 | | -# name = "_".join(name) |
| 78 | + name = "_".join(name) |
79 | 79 |
|
80 | | -# name = prefix + name[max_length:] |
81 | | -# return name |
| 80 | + name = prefix + name[max_length:] |
| 81 | + return name |
82 | 82 |
|
83 | 83 |
|
84 | | -# def get_commands_from_file(fileobj): |
85 | | -# ''' Reads commands from `fileobj`. |
| 84 | +def get_commands_from_file(fileobj): |
| 85 | + ''' Reads commands from `fileobj`. |
86 | 86 |
|
87 | | -# Parameters |
88 | | -# ---------- |
89 | | -# fileobj : file |
90 | | -# opened file where to read commands from |
| 87 | + Parameters |
| 88 | + ---------- |
| 89 | + fileobj : file |
| 90 | + opened file where to read commands from |
91 | 91 |
|
92 | | -# Returns |
93 | | -# ------- |
94 | | -# commands : list of str |
95 | | -# commands read from the file |
96 | | -# ''' |
97 | | -# return fileobj.read().strip().split('\n') |
| 92 | + Returns |
| 93 | + ------- |
| 94 | + commands : list of str |
| 95 | + commands read from the file |
| 96 | + ''' |
| 97 | + return fileobj.read().strip().split('\n') |
98 | 98 |
|
99 | 99 |
|
100 | 100 | def get_commands_from_arguments(arguments): |
@@ -130,48 +130,48 @@ def get_commands_from_arguments(arguments): |
130 | 130 | return unfolded_commands |
131 | 131 |
|
132 | 132 |
|
133 | | -# def unfold_argument(argument): |
134 | | -# ''' Unfolds a folded argument into a list of unfolded arguments. |
| 133 | +def unfold_argument(argument): |
| 134 | + ''' Unfolds a folded argument into a list of unfolded arguments. |
135 | 135 |
|
136 | | -# An argument can be folded e.g. a list of unfolded arguments separated by spaces. |
137 | | -# An unfolded argument unfolds to itself. |
| 136 | + An argument can be folded e.g. a list of unfolded arguments separated by spaces. |
| 137 | + An unfolded argument unfolds to itself. |
138 | 138 |
|
139 | | -# Parameters |
140 | | -# ---------- |
141 | | -# argument : str |
142 | | -# argument to unfold |
| 139 | + Parameters |
| 140 | + ---------- |
| 141 | + argument : str |
| 142 | + argument to unfold |
143 | 143 |
|
144 | | -# Returns |
145 | | -# ------- |
146 | | -# unfolded_arguments : list of str |
147 | | -# result of the unfolding |
| 144 | + Returns |
| 145 | + ------- |
| 146 | + unfolded_arguments : list of str |
| 147 | + result of the unfolding |
148 | 148 |
|
149 | | -# Complex arguments |
150 | | -# ----------------- |
151 | | -# *list (space)*: "item1 item2 ... itemN" |
152 | | -# ''' |
| 149 | + Complex arguments |
| 150 | + ----------------- |
| 151 | + *list (space)*: "item1 item2 ... itemN" |
| 152 | + ''' |
153 | 153 |
|
154 | | -# # Suppose `argument`is a space separated list |
155 | | -# return argument.split(" ") |
| 154 | + # Suppose `argument`is a space separated list |
| 155 | + return argument.split(" ") |
156 | 156 |
|
157 | 157 |
|
158 | | -# def replace_uid_tag(commands): |
159 | | -# return [command.replace("{UID}", utils.generate_uid_from_string(command)) for command in commands] |
| 158 | +def replace_uid_tag(commands): |
| 159 | + return [command.replace("{UID}", utils.generate_uid_from_string(command)) for command in commands] |
160 | 160 |
|
161 | 161 |
|
162 | | -# def get_available_queues(cluster_name=utils.detect_cluster()): |
163 | | -# """ Fetches all available queues on the current cluster """ |
164 | | -# if cluster_name is None: |
165 | | -# return {} |
| 162 | +def get_available_queues(cluster_name=utils.detect_cluster()): |
| 163 | + """ Fetches all available queues on the current cluster """ |
| 164 | + if cluster_name is None: |
| 165 | + return {} |
166 | 166 |
|
167 | | -# smartdispatch_dir, _ = os.path.split(smartdispatch.__file__) |
168 | | -# config_dir = os.path.join(smartdispatch_dir, 'config') |
| 167 | + smartdispatch_dir, _ = os.path.split(smartdispatch.__file__) |
| 168 | + config_dir = os.path.join(smartdispatch_dir, 'config') |
169 | 169 |
|
170 | | -# config_filename = cluster_name + ".json" |
171 | | -# config_filepath = os.path.join(config_dir, config_filename) |
| 170 | + config_filename = cluster_name + ".json" |
| 171 | + config_filepath = os.path.join(config_dir, config_filename) |
172 | 172 |
|
173 | | -# if not os.path.isfile(config_filepath): |
174 | | -# return {} # Unknown cluster |
| 173 | + if not os.path.isfile(config_filepath): |
| 174 | + return {} # Unknown cluster |
175 | 175 |
|
176 | | -# queues_infos = utils.load_dict_from_json_file(config_filepath) |
177 | | -# return queues_infos |
| 176 | + queues_infos = utils.load_dict_from_json_file(config_filepath) |
| 177 | + return queues_infos |
0 commit comments