From e4210ad4445c3b016eefd781a2ae8c438b3271c7 Mon Sep 17 00:00:00 2001 From: RusAnon Date: Mon, 3 May 2010 18:02:33 +1100 Subject: [PATCH] Decorator to enforce suspend --- dfhack/python/pydfhack/decorators.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 dfhack/python/pydfhack/decorators.py diff --git a/dfhack/python/pydfhack/decorators.py b/dfhack/python/pydfhack/decorators.py new file mode 100644 index 000000000..702cf18f9 --- /dev/null +++ b/dfhack/python/pydfhack/decorators.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +""" +Decorators for bound classes +""" +from decorator import decorator + +@decorator +def suspend(func, self, *args, **kw): + """ + This decorator will try to suspend DF and start needed module before running func + """ + if self.prepare(): + return func(self, *args, **kw) + else: + raise Exception(u"Could not suspend/start")