Index: quickstart/utils.py |
=== modified file 'quickstart/utils.py' |
--- quickstart/utils.py 2014-01-09 11:22:54 +0000 |
+++ quickstart/utils.py 2014-01-10 15:30:49 +0000 |
@@ -24,6 +24,7 @@ |
import collections |
import datetime |
import errno |
+import functools |
import httplib |
import json |
import logging |
@@ -326,6 +327,20 @@ |
return parse_status_output(output, ['machines', '0', 'series']) |
+def run_once(function): |
+ """Return a decorated version of the given function which runs only once. |
+ |
+ Subsequent runs are just ignored and return None. |
+ """ |
+ @functools.wraps(function) |
+ def decorated(*args, **kwargs): |
+ if not decorated.called: |
+ decorated.called = True |
+ return function(*args, **kwargs) |
+ decorated.called = False |
+ return decorated |
+ |
+ |
def unit_changes(unit_name, changeset): |
"""Parse the changeset and return the change related to the given unit. |