Commits

zhangchunlin committed 2af5467

add abcleanold command

Comments (0)

Files changed (2)

apps/autobuild/commands.py

+#! /usr/bin/env python
+#coding=utf-8
+
+from uliweb.core.commands import Command
+from uliweb import settings
+
+
+def get_app():
+    from uliweb.manage import make_application
+    app = make_application(start=False, debug_console=False, debug=False)
+    return app
+
+class AbCleanOldCommand(Command):
+    name = 'abcleanold'
+    help = 'Autobuild Clean Old builds'
+    
+    def handle(self, options, global_options, *args):
+        get_app()
+        
+        import re,os,datetime,shutil
+        
+        if len(args)>0 and args[0]=="dryrun":
+            dryrun = True
+        else:
+            dryrun = False
+        
+        rawstr = r"(\w+)-([\w\.0-9_]+)-(\w+)-([\[\]\w\+]+)-([0-9]{4})_([0-9]{2})_([0-9]{2})-([0-9]{2})_([0-9]{2})(\[[\w|]+\])?"
+        compile_obj = re.compile(rawstr)
+        keeplimit = datetime.timedelta(days=settings.AUTOBUILD.KEEP_DAYS)
+        for dp in settings.AUTOBUILD.BUILDS_DIRS:
+            for name in os.listdir(dp):
+                path = os.path.join(dp,name)
+                if os.path.isdir(path):
+                    match_obj = compile_obj.search(name)
+                    if match_obj!=None:
+                        board,branch,manifest,btype,year,month,day,hour,minute,properties = match_obj.groups()
+                        dt = datetime.datetime(int(year),
+                            int(month),
+                            int(day),
+                            int(hour),
+                            int(minute))
+                        tonow = datetime.datetime.now()-dt
+                        if tonow>keeplimit:
+                            print tonow,name
+                            if not dryrun:
+                                print "remove %s"%(name)
+                                shutil.rmtree(path)

apps/autobuild/settings.ini

 
 [AUTOBUILD]
 BUILDS_JSON_FP = "/tmp/abw_builds.json"
+KEEP_DAYS = 50
 
 [LAYOUT]
 TITLE = "autobuild"