summaryrefslogtreecommitdiff
path: root/kbas
diff options
context:
space:
mode:
authorPaul Sherwood <paul.sherwood@codethink.co.uk>2016-03-12 19:44:11 +0000
committerPaul Sherwood <paul.sherwood@codethink.co.uk>2016-03-12 19:44:58 +0000
commitf3cf4bfa48f10fe9f7b45ab8194511174e567a1b (patch)
tree645b19f19b962bbcd09753ba8317d61ff0dbf78e /kbas
parentf52a8e24fdcb9baa8da7d73127c1fff1255d86fb (diff)
downloadybd-f3cf4bfa48f10fe9f7b45ab8194511174e567a1b.tar.gz
Log last upload and password fail times
Diffstat (limited to 'kbas')
-rwxr-xr-xkbas/__main__.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/kbas/__main__.py b/kbas/__main__.py
index 55100c3..534b581 100755
--- a/kbas/__main__.py
+++ b/kbas/__main__.py
@@ -20,7 +20,7 @@ import os
import glob
import shutil
from time import strftime, gmtime
-import datetime
+from datetime import datetime
import tempfile
import yaml
from bottle import Bottle, request, response, template, static_file
@@ -41,7 +41,8 @@ class KeyedBinaryArtifactServer(object):
app.load_configs([
os.path.join(os.getcwd(), 'kbas.conf'),
os.path.join(os.path.dirname(__file__), 'config', 'kbas.conf')])
- app.config['start-time'] = datetime.datetime.now()
+ app.config['start-time'] = datetime.now()
+ app.config['last-upload'] = datetime.now()
try:
import cherrypy
@@ -105,7 +106,11 @@ class KeyedBinaryArtifactServer(object):
free = stat.f_frsize * stat.f_bavail / 1000000000
artifacts = len(os.listdir(app.config['artifact-dir']))
started = app.config['start-time'].strftime('%y-%m-%d %H:%M:%S')
+ last_upload = app.config['last-upload'].strftime('%y-%m-%d %H:%M:%S')
content = [['Started:', started]]
+ content += [['Last upload:', last_upload]]
+ if app.config.get('last-reject'):
+ content += [['Last reject:', app.config['last-reject']]]
content += [['Space:', str(free) + 'GB']]
content += [['Artifacts:', str(artifacts)]]
return template('kbas',
@@ -118,6 +123,8 @@ class KeyedBinaryArtifactServer(object):
if app.config['password'] is 'insecure' or \
request.forms.get('password') != app.config['password']:
print 'Upload attempt: password fail'
+ app.config['last-reject'] = \
+ datetime.now().strftime('%y-%m-%d %H:%M:%S')
response.status = 401 # unauthorized
return
cache_id = request.forms.get('filename')
@@ -143,6 +150,7 @@ class KeyedBinaryArtifactServer(object):
shutil.move(tmpdir, os.path.join(app.config['artifact-dir'],
cache_id))
response.status = 201 # success!
+ app.config['last-upload'] = datetime.now()
return
except:
# something went wrong, clean up