~eddres-maintainers/eddres/trunk

« back to all changes in this revision

Viewing changes to resource_manager/cron.py

  • Committer: Mads Chr. Olesen
  • Date: 2008-12-26 20:31:50 UTC
  • Revision ID: shiyee@shiyee.dk-20081226203150-vt00vute3w0p87l3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
import settings
 
3
from resource_manager.models import *
 
4
from datetime import datetime
 
5
 
 
6
resource_classes = []
 
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)
 
18
    for obj in todo:
 
19
        script = None
 
20
        args = []
 
21
        doupdate = 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
 
31
        else:
 
32
            #TODO Perform update
 
33
            print 'run: ', obj.update_script, obj.update_args()
 
34
            obj.update_done()
 
35
        
 
36
        if obj.status == RESOURCE_STATUS_TOBESUSPENDED:
 
37
            script = obj.suspend_script
 
38
            args = obj.suspend_args()
 
39
            newstatus = RESOURCE_STATUS_SUSPENDED
 
40
            doupdate = True
 
41
 
 
42
        if script:
 
43
            print 'run: ', script, args
 
44
            #TODO - run the script, and check return value for errors
 
45
 
 
46
        obj.processed = True
 
47
        obj.modified = datetime.now()
 
48
        obj.status = newstatus
 
49
        obj.save(processed_done=True)
 
50