Skip to content

Commit

Permalink
Add curry
Browse files Browse the repository at this point in the history
  • Loading branch information
hamiltonleemark committed Dec 28, 2016
1 parent 0f1d03b commit 7ee1a90
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion TODO
@@ -1,5 +1,6 @@
-Figure out best way to connect to KVM, ssh password is cumbersome.
-Make sure disks get cleaned up
-Look into openssh-askpass
-Show actions in web pages and CLI
-Add kibana support
-Add Graphana support
-Create a style for the web pages
Expand Down
27 changes: 20 additions & 7 deletions testpool/core/coding.py
@@ -1,14 +1,27 @@
class curry:
def __init__(self, fun, *args, **kwargs):
self.fun = fun
"""
Coding concepts.
"""


# pylint: disable=R0903
class Curry(object):
""" Supports curry algorithm.
defer calling a function with a specific set of parameters.
"""

def __init__(self, func, *args, **kwargs):
""" Store arguments and function for later. """
self.func = func
self.pending = args[:]
self.kwargs = kwargs.copy()

def __call__(self, *args, **kwargs):
""" Call's the self.func with arguments now. """

if kwargs and self.kwargs:
kw = self.kwargs.copy()
kw.update(kwargs)
kwarg = self.kwargs.copy()
kwarg.update(kwargs)
else:
kw = kwargs or self.kwargs
kwarg = kwargs or self.kwargs

return self.fun(*(self.pending + args), **kw)
return self.func(*(self.pending + args), **kwarg)
2 changes: 1 addition & 1 deletion testpool/core/server.py
Expand Up @@ -302,7 +302,7 @@ def main(args):
args.max_sleep_time)
time.sleep(args.max_sleep_time)
elif vmh.action_time < current or args.max_sleep_time == 0:
exceptions.try_catch(coding.curry(action_vm, vmh))
exceptions.try_catch(coding.Curry(action_vm, vmh))
else:
action_delay = abs(vmh.action_time - current).seconds

Expand Down

0 comments on commit 7ee1a90

Please sign in to comment.