equal
deleted
inserted
replaced
61 # XXX: not strictly true, merge lists |
61 # XXX: not strictly true, merge lists |
62 out.update(opts) |
62 out.update(opts) |
63 |
63 |
64 return out |
64 return out |
65 |
65 |
|
66 def normalize_args (args) : |
|
67 """ |
|
68 Flatten the given nested iterables list into a flat one |
|
69 """ |
|
70 |
|
71 for arg in args : |
|
72 # naasty type-checks :) |
|
73 if isinstance(arg, (list, tuple, types.GeneratorType)) : |
|
74 # recurse -> flatten |
|
75 for subarg in normalize_args(arg) : |
|
76 yield subarg |
|
77 |
|
78 else : |
|
79 # flat |
|
80 yield str(arg) |
|
81 |
66 def run_cmd (func, pre_args, opts, post_args) : |
82 def run_cmd (func, pre_args, opts, post_args) : |
67 """ |
83 """ |
68 Run the given rrdtool.* function, formatting the given positional arguments and options. |
84 Run the given rrdtool.* function, formatting the given positional arguments and options. |
69 """ |
85 """ |
70 |
86 |
73 |
89 |
74 # decomposed series of cmd-args |
90 # decomposed series of cmd-args |
75 opt_args = [item for items in opt_items for item in items] |
91 opt_args = [item for items in opt_items for item in items] |
76 |
92 |
77 # positional arguments |
93 # positional arguments |
78 pre_args = [str(arg) for arg in pre_args] |
94 pre_args = normalize_args(pre_args) |
79 post_args = [str(arg) for arg in post_args] |
95 post_args = normalize_args(post_args) |
80 |
96 |
81 # full arguments |
97 # full arguments |
82 args = pre_args + opt_args + post_args |
98 args = pre_args + opt_args + post_args |
83 |
99 |
84 return func(*args) |
100 return func(*args) |