3
from resource_manager.models import *
4
from datetime import datetime
7
for app in settings.INSTALLED_APPS:
8
appmod = __import__(app + ".models")
9
if hasattr(appmod, 'models'):
10
for clsname in dir(appmod.models):
11
cls = getattr(appmod.models, clsname)
12
if hasattr(cls, '__bases__'):
13
if issubclass(cls, BaseResource) and cls != BaseResource:
14
resource_classes += [cls]
15
print resource_classes
16
for res in resource_classes:
17
todo = res.objects.filter(processed=False)
22
newstatus = obj.status
23
if obj.status == RESOURCE_STATUS_TOBEACTIVE:
24
script = obj.create_script
25
args = obj.create_args()
26
newstatus = RESOURCE_STATUS_ACTIVE
27
elif obj.status == RESOURCE_STATUS_TOBECLOSED:
28
script = obj.delete_script
29
args = obj.delete_args()
30
newstatus = RESOURCE_STATUS_CLOSED
33
print 'run: ', obj.update_script, obj.update_args()
36
if obj.status == RESOURCE_STATUS_TOBESUSPENDED:
37
script = obj.suspend_script
38
args = obj.suspend_args()
39
newstatus = RESOURCE_STATUS_SUSPENDED
43
print 'run: ', script, args
44
#TODO - run the script, and check return value for errors
47
obj.modified = datetime.now()
48
obj.status = newstatus
49
obj.save(processed_done=True)