def handle_conflict(body_dict): # Adding a new file old_blob = db_session.query(Blob).get(body_dict["file_id"]) old_filename=old_blob.filename.split(".") new_filename = "" try: new_filename=old_filename[0]+"_conflict"+"."+old_filename[1] except IndexError: new_filename=old_filename[0]+"_conflict" new_blob = Blob(new_filename, old_blob.lob, old_blob.file_size) db_session.add(new_blob) db_session.delete(old_blob) db_session.commit() data = {"message_id":(uuid.uuid4().int & (1<<63)-1), "type":"POST", "node_id":node_id, "node_ip":node_ip, "node_port":node_port, "file_id":new_blob.id, "upload_date":str(new_blob.upload_date), "file_last_update":str(new_blob.last_change)}
def handle_conflict(body_dict): # Adding a new file old_blob = db_session.query(Blob).get(body_dict["file_id"]) old_filename = old_blob.filename.split(".") new_filename = "" try: new_filename = old_filename[0] + "_conflict" + "." + old_filename[1] except IndexError: new_filename = old_filename[0] + "_conflict" new_blob = Blob(new_filename, old_blob.lob, old_blob.file_size) db_session.add(new_blob) db_session.delete(old_blob) db_session.commit() data = { "message_id": (uuid.uuid4().int & (1 << 63) - 1), "type": "POST", "node_id": node_id, "node_ip": node_ip, "node_port": node_port, "file_id": new_blob.id, "upload_date": str(new_blob.upload_date), "file_last_update": str(new_blob.last_change) }
def show_blob(blob_id): b=db_session.query(Blob).get(blob_id) global online if request.method == 'GET': print "Online: ", online return render_template('show_file.html', node_port=node_port, node_ip=node_ip, node_id=node_id, blob=b) elif request.method == 'PUT': # Adding a new file fn = b.filename f = request.files['blob'] fn_new = secure_filename(f.filename) if not fn == fn_new: flash('File name not the same') return render_template('show_file.html', node_port=node_port, node_ip=node_ip, node_id=node_id, blob=b) else: # Adds information about the file in the database f_size = sys.getsizeof(f) f_blob = f.read() b.upload_date = b.last_change b.last_change = datetime.datetime.now() b.lob = f_blob b.file_size = f_size db_session.commit() data = {"message_id":(uuid.uuid4().int & (1<<63)-1), "type":"PUT", "node_id":node_id, "node_ip":node_ip, "node_port":node_port, "file_id":b.id, "upload_date":str(b.upload_date), "file_last_update":str(b.last_change)} global online if(online): rabbitmq.emit_update(json.dumps(data)) else: print "is offline" flash('File update successful.') return render_template('show_file.html', node_port=node_port, node_ip=node_ip, node_id=node_id, blob=b) elif request.method == 'DELETE': db_session.delete(b) db_session.commit() data = {"message_id":(uuid.uuid4().int & (1<<63)-1), "type":"DELETE", "node_id":node_id, "node_ip":node_ip, "node_port":node_port, "file_id":b.id, "upload_date":str(b.upload_date), "file_last_update":str(b.last_change), "file_last_sync":str(b.last_sync)} global online if(online): rabbitmq.emit_update(json.dumps(data)) else: print "is offline" flash('File is removed.') return redirect(url_for('blob')) elif request.method == 'POST': # This should totally never ever happen.. but it needs to support it, don't judge. flash('I think I broke something, call my mummy..') return render_template('show_file.html', node_port=node_port, node_ip=node_ip, node_id=node_id, blob=db_session.query(Blob).get(blob_id))
def delete_blob(body_dict): b = db_session.query(Blob).get(body_dict["file_id"]) if not b == None: db_session.delete(b) db_session.commit()
def delete_blob(body_dict): b=db_session.query(Blob).get(body_dict["file_id"]) if not b == None: db_session.delete(b) db_session.commit()