Commits

zhangchunlin committed bdfaaef

now can edit build info,'note' and 'keep'

  • Participants
  • Parent commits 590d99b

Comments (0)

Files changed (4)

File apps/autobuild/forms.py

 #coding=utf-8
 
 from uliweb.form import *
+from uliweb.i18n import ugettext as _
+
 
 class ChangeLogForm(Form):
     form_buttons = Submit(value='提交查询', _class="button")
     branch = StringField(label='branch(i.e.:a60_dev):',html_attrs={'size':16})
     limit = IntField(label='limit(i.e.:500):',html_attrs={'size':8})
 
+class EditBuildInfoForm(Form):
+    note = StringField(label='build note',name='note')
+    keep = BooleanField(label=_('keep this file from clean'),name='keep',id='string_keep')
+
+
 if __name__ == '__main__':
     f = ChangeLogForm(data={"status":"merged","branch":"a60_dev"},html_attrs={"size":8})
     print f

File apps/autobuild/templates/builds_view.html

 <table class="table table-striped">
 <tbody>
 <tr>
-<th>board</th><th>branch</th><th>build type</th><th>manifest xml</th><th>file download</th>
+<th>board</th><th>branch</th><th>build type</th><th>manifest xml</th><th>file download</th><th>info</th>
 </tr>
 '''
 
 </table>
 '''
 
+from uliweb.utils.textconvert import text2html
+
 c = 1
 for d in view_data:
     if len(d["list"])!=0:
             pass
             out.write("<td>%s</td>"%(btype), escape=False)
             out.write("<td>%s.xml</td>"%(f["manifest"]), escape=False)
-            s = ""
+            s = "<td>"
             if f.has_key("title"):
                 s+="%s<br />"%(f["title"])
                 pass
             for item in f["download"]:
                 s+='<a href="/builds_dl/%s">%s</a>(%s) '%(item["path"],item["fn"],item["size"])
                 pass
-            out.write('<td>%s</td>'%(s),escape=False)
+            s += "</td>"
+            s += "<td>"
+            if f["info"]!=None:
+                txt = ""
+                for k in f["info"]:
+                    txt += "%s:%s\n"%(k,f["info"][k])
+                pass
+                s += "<strong>"
+                s += text2html(txt)
+                s += "</strong>"
+            pass
+            
+            s += '<a href="/editinfo/%s?next=%s&vtype=%s&anchor=%s">edit</a>'%(f["title"],request.path,vtype,"time%d"%(c))
+            s += "</td>"
+            out.write(s,escape=False)
             out.write("</tr>\n", escape=False)
         pass
         out.write(table_end, escape=False)

File apps/autobuild/templates/editinfo.html

+{{extend "layout.html"}}
+
+{{block userinfo}}{{end}}
+
+{{block menu}}{{end}}
+
+{{block content}}
+<a href="{{<< '%s?vtype=%s#%s'%(next,vtype,anchor)}}">back</a>
+<div class="container">
+{{<< dn}}
+<br /><br />
+{{<< ebiform}}
+</div>
+{{end content}}
+
+{{block footer}}{{end}}

File apps/autobuild/views.py

 #coding=utf-8
 
 import os,re,datetime,string,subprocess
+import json as json_
 
 from uliweb import expose,settings,request,application
 from uliweb.utils.filedown import filedown
 from uliweb.utils.textconvert import text2html
-from werkzeug.exceptions import NotFound 
+from werkzeug.exceptions import NotFound
 
 @expose('/')
 def index():
         s = "%d"%(num)
     return s
 
+
+def get_build_info(fp):
+    if not os.path.exists(fp):
+        return None
+    
+    f = open(fp)
+    try:
+        binfo = json_.loads(f.read())
+    except ValueError,e:
+        binfo = None
+        print e
+    f.close()
+    #print fp,binfo
+    return binfo
+
+def set_build_info(fp,data):
+    f = open(fp,"w")
+    f.write(json_.dumps(data, sort_keys=True, indent=2))
+    f.close()
+
+def get_build_info_with_dn(dn):
+    for dp in settings.AUTOBUILD.BUILDS_DIRS:
+        fp = os.path.join(dp,dn,'.info')
+        if os.path.exists(fp):
+            return get_build_info(fp)
+    return None
+
+def set_build_info_with_dn(dn,data):
+    if data['note']=="":
+        del data['note']
+    if data['keep']!=True:
+        del data['keep']
+    
+    for dp in settings.AUTOBUILD.BUILDS_DIRS:
+        dpbuild = os.path.join(dp,dn)
+        if os.path.exists(dpbuild):
+            fp = os.path.join(dpbuild,'.info')
+            if len(data)>0:
+                set_build_info(fp,data)
+            elif os.path.exists(fp):
+                os.remove(fp)
+            break
+
 def get_view_data(vtype=None):
     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)
     
-    import json
     jfp = settings.AUTOBUILD.BUILDS_JSON_FP
     global cache_touched
     cache_touched = False
     if os.path.exists(jfp):
         f = open(jfp)
-        cache = json.loads(f.read())
+        try:
+            cache = json_.loads(f.read())
+        except ValueError,e:
+            cache = {}
+            cache_touched = True
         f.close()
     else:
         cache = {}
                         int(hour),
                         int(minute))
                     download = []
-                    for fn_7z in os.listdir(dp_archive):
-                        fp_7z = os.path.join(dp_archive,fn_7z)
-                        d = {"fn":fn_7z,"path":"%s/%s"%(dn,fn_7z),"size":hnum(get_file_size(fp_7z))}
-                        download.append(d)
+                    info = None
+                    for fn_download in os.listdir(dp_archive):
+                        fp_download = os.path.join(dp_archive,fn_download)
+                        if fn_download[0]!='.':
+                            d = {"fn":fn_download,"path":"%s/%s"%(dn,fn_download),"size":hnum(get_file_size(fp_download))}
+                            download.append(d)
+                    
+                    info = get_build_info_with_dn(dn)
                     
                     fl.append({"download":download,
                         "title":dn,
                         "branch":branch,
                         "btype":btype,
                         "manifest":manifest,
-                        "dt":dt})
+                        "dt":dt,
+                        "info":info,})
                 else:
                     unknowfiles.append(fn)
         #print  >> sys.stderr, "after:%s"%(datetime.datetime.now())
     
     if cache_touched:
         f = open(jfp,"w")
-        f.write(json.dumps(cache, sort_keys=True, indent=2))
+        f.write(json_.dumps(cache, sort_keys=True, indent=2))
         f.close()
     
     return data,unknowfiles
         elif out!="":
             buf += out
 
-
 @expose('/builds_view')
 def builds_view():
-    vtype = 'by_time'#'by_branch','by_btype'
-    if request.method == 'GET':
-        if request.GET.has_key('vtype'):
-            vtype = request.GET['vtype']
+    #'by_branch','by_btype'
+    vtype = request.GET.get('vtype','by_time')
     current_menu = "builds_view_%s"%(vtype)
     view_data,unknown_files = get_view_data(vtype)
     return {
         "current_menu":current_menu,
         "view_data":view_data,
         "unknown_files":unknown_files,
+        "vtype":vtype,
         "header_diminish":vtype=='by_time',
         "df":text2html(cmdout("df -h"))
         }
     #return filedown(request.environ,filename="%s-%s"%(dn,fn.replace("_","-")),download=True,real_filename = fp)
     return filedown(request.environ,fp)
 
+from forms import EditBuildInfoForm
+@expose('/editinfo/<dn>')
+def editinfo(dn):
+    ebiform = EditBuildInfoForm()
+    next = request.GET.get('next','/builds_view')
+    vtype = request.GET.get('vtype','by_time')
+    anchor = request.GET.get('anchor','')
+    if request.method == "POST":
+        flag = ebiform.validate(request.values, request.files)
+        if flag:
+            set_build_info_with_dn(dn,ebiform.data)
+            flash("build info saved!")
+            #return redirect("/builds_view")
+        else:
+            flash("not saved.")
+    else:
+        info = get_build_info_with_dn(dn)
+        if info!=None:
+            for k in info:
+                ebiform.data[k]=info[k]
+    return {
+        'ebiform':ebiform,
+        'dn':dn,
+        'next':next,
+        'vtype':vtype,
+        'anchor':anchor,
+    }
+
 from forms import ChangeLogForm
 import gerritchangelog