summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntanas Uršulis <antanas.ursulis@gmail.com>2013-07-04 02:38:24 +0100
committerAntanas Uršulis <antanas.ursulis@gmail.com>2013-07-04 02:38:24 +0100
commitc74e38905e87acd4075e96cb3e4ad2c474e23f25 (patch)
tree04c637091545bf370ec8180d42c0fd6c181f199c
parentSimple file submission client, based on urllib and protobuf (diff)
downloadlog-analysis-c74e38905e87acd4075e96cb3e4ad2c474e23f25.tar.gz
log-analysis-c74e38905e87acd4075e96cb3e4ad2c474e23f25.tar.bz2
log-analysis-c74e38905e87acd4075e96cb3e4ad2c474e23f25.zip
Implement simple storage in the filesystem
-rw-r--r--flask_app.py7
-rw-r--r--storage.py23
2 files changed, 28 insertions, 2 deletions
diff --git a/flask_app.py b/flask_app.py
index a69f4f8..87697e5 100644
--- a/flask_app.py
+++ b/flask_app.py
@@ -3,10 +3,12 @@ The web application built on Flask is contained within this file.
When run as a script, the Flask development server is started.
"""
-import submission_pb2
+import os
+import submission_pb2, storage
from flask import Flask, request
app = Flask(__name__)
+store = storage.FilesystemStorage('logs/')
@app.route('/')
def index():
@@ -20,7 +22,8 @@ def submit():
"""
submission = submission_pb2.Submission()
submission.ParseFromString(request.data)
- return str(submission)
+ store.save_file(request.remote_addr, submission.filename, submission.data)
+ return ''
if __name__ == '__main__':
app.run(host='::1', debug=True)
diff --git a/storage.py b/storage.py
new file mode 100644
index 0000000..847806f
--- /dev/null
+++ b/storage.py
@@ -0,0 +1,23 @@
+"""
+Implements storage of collected log files in the local filesystem.
+"""
+
+import os, errno
+
+class FilesystemStorage:
+ def __init__(self, root):
+ self.root = root
+ try:
+ os.mkdir(root)
+ except OSError:
+ pass # TODO: proper handling
+
+ def save_file(self, source, filename, data):
+ try:
+ os.mkdir(os.path.join(self.root, source))
+ except OSError:
+ pass # TODO: proper handling
+
+ path = os.path.join(self.root, source, filename) # TODO: consider adding in date at some point
+ with open(path, 'wb') as f:
+ f.write(data)