progress report

This commit is contained in:
Massimo Di Pierro
2012-03-26 17:19:23 -05:00
parent 4f17616b0f
commit e82f2c2b5c
4 changed files with 2654 additions and 10 deletions
+1 -1
View File
@@ -1 +1 @@
Version 1.99.7 (2012-03-26 16:15:22) dev
Version 1.99.7 (2012-03-26 17:19:14) dev
+43 -9
View File
@@ -26,6 +26,17 @@ if FILTER_APPS and request.args(0) and not request.args(0) in FILTER_APPS:
session.flash = T('disabled in demo mode')
redirect(URL('site'))
def count_lines(data):
return len([line for line in data.split('\n') if line.strip() and not line.startswith('#')])
def log_progress(app,mode='EDIT',filename=None,progress=0):
progress_file = os.path.join(apath(app, r=request), 'progress.log')
now = str(request.now)[:19]
if not os.path.exists(progress_file):
open(progress_file,'w').write('[%s] START\n' % now)
if filename:
open(progress_file,'a').write('[%s] %s %s: %s\n' % (now,mode,filename,progress))
def safe_open(a,b):
if DEMO_MODE and 'w' in b:
class tmp:
@@ -159,7 +170,7 @@ def site():
if app_create(appname, request):
if MULTI_USER_MODE:
db.app.insert(name=appname,owner=auth.user.id)
# LOG_PROGRESS
log_progress(appname)
session.flash = T('new application "%s" created', appname)
redirect(URL('design',args=appname))
else:
@@ -192,7 +203,7 @@ def site():
overwrite=request.vars.overwrite_check)
if f and installed:
msg = 'application %(appname)s installed with md5sum: %(digest)s'
# LOG_PROGRESS
log_progress(app)
session.flash = T(msg, dict(appname=appname,
digest=md5_hash(installed)))
elif f and request.vars.overwrite_check:
@@ -220,6 +231,22 @@ def site():
return dict(app=None, apps=apps, myversion=myversion)
def report_progress(app):
import datetime
progress_file = os.path.join(apath(app, r=request), 'progress.log')
regex = re.compile('\[(.*?)\][^\:]+\:\s+(\-?\d+)')
if not os.path.exists(progress_file):
return []
matches = regex.findall(open(progress_file,'r').read())
events,counter = [],0
for m in matches:
if not m: continue
days = -(request.now - datetime.datetime.strptime(m[0],'%Y-%m-%d %H:%M:%S')).days
counter += int(m[1])
events.append([days,counter])
return events
def pack():
app = get_app()
@@ -331,8 +358,10 @@ def delete():
redirect(URL(sender))
elif 'delete' in request.vars:
try:
os.unlink(apath(filename, r=request))
# LOG_PROGRESS
full_path = apath(filename, r=request)
lineno = count_lines(open(full_path,'r').read())
os.unlink(full_path)
log_progress(app,'DELETE',filename,progress=-lineno)
session.flash = T('file "%(filename)s" deleted',
dict(filename=filename))
except Exception:
@@ -448,6 +477,7 @@ def edit():
else:
redirect(URL('site'))
lineno_old = count_lines(data)
file_hash = md5_hash(data)
saved_on = time.ctime(os.stat(path)[stat.ST_MTIME])
@@ -465,7 +495,8 @@ def edit():
safe_write(path + '.bak', data)
data = request.vars.data.replace('\r\n', '\n').strip() + '\n'
safe_write(path, data)
# LOG_PROGRESS
lineno_new = count_lines(data)
log_progress(app,'EDIT',filename,progress=lineno_new-lineno_old)
file_hash = md5_hash(data)
saved_on = time.ctime(os.stat(path)[stat.ST_MTIME])
response.flash = T('file saved on %s', saved_on)
@@ -684,7 +715,7 @@ def about():
# ## check if file is not there
about = safe_read(apath('%s/ABOUT' % app, r=request))
license = safe_read(apath('%s/LICENSE' % app, r=request))
return dict(app=app, about=MARKMIN(about), license=MARKMIN(license))
return dict(app=app, about=MARKMIN(about), license=MARKMIN(license),progress=report_progress(app))
def design():
@@ -1001,7 +1032,7 @@ def create_file():
raise SyntaxError
safe_write(full_filename, text)
# LOG_PROGRESS
log_progress(app,'CREATE',filename)
session.flash = T('file "%(filename)s" created',
dict(filename=full_filename[len(path):]))
redirect(URL('edit',
@@ -1047,8 +1078,10 @@ def upload_file():
if not os.path.exists(dirpath):
os.makedirs(dirpath)
safe_write(filename, request.vars.file.file.read(), 'wb')
# LOG_PROGRESS
data = request.vars.file.file.read()
lineno = count_lines(data)
safe_write(filename, data, 'wb')
log_progress(app,'UPLOAD',filename,lineno)
session.flash = T('file "%(filename)s" uploaded',
dict(filename=filename[len(path):]))
except Exception:
@@ -1380,3 +1413,4 @@ def bulk_register():
session.flash = T('%s students registered',n)
redirect(URL('site'))
return locals()
File diff suppressed because it is too large Load Diff
@@ -11,3 +11,14 @@
<div class="license_text legalese">{{=license}}</div>
</ul>
<script language="javascript" type="text/javascript" src="{{=URL('static','js/jquery.flot.js')}}"></script>
<h3>{{=T('Project Progress')}}</h3>
<p>
<center>
<div id="placeholder" style="width:600px;height:300px;"></div>
</center>
<script type="text/javascript">
jQuery(function () { jQuery.plot(jQuery("#placeholder"), [ {{=progress}} ]); });
</script>
</p>