def req_start(devId): oldest_active = datetime.now() - timedelta(0, inactive_timeout, 0) active_trans_no = db_api.get_active_upload(oldest_active) if active_trans_no < max_concurrent_trans: print "currently active : " + str(active_trans_no) chunk_path_dev = chunk_path + str(devId) print chunk_path_dev try: shutil.rmtree(chunk_path_dev + "/") except Exception as e: print str(e) try: os.makedirs(chunk_path_dev) except OSError as exc: print str(exc) # call(["mkdir -p " + chunk_path_dev], shell=True) # call(["rm " + chunk_path_dev + "/*"], shell=True) # call(["rm " + file_path_dev + "/*"], shell=True) filename = id_generator() db_api.update_upload_activity(devId) return jsonify({"filename": filename}) else: return jsonify({})
def info_kill(devId): chunk_path_dev = chunk_path + str(devId) file_path_dev = file_path + str(devId) try: shutil.rmtree(chunk_path_dev + "/") shutil.rmtree(file_path_dev + "/") except Exception as e: print str(e) print("device " + str(devId) + " too slow ... killed") db_api.update_upload_activity(devId, False, datetime.now() - timedelta(0, inactive_timeout, 0)) return jsonify({})
def confirm_done(devId): content = request.json if (not content and "filename" not in content): abort(400) filename = content['filename'] file_path_dev = file_path + str(devId) + "/" chunk_path_dev = chunk_path + str(devId) + "/" + filename + "*" try: shutil.rmtree(file_path_dev + "/") except Exception as e: print str(e) try: os.makedirs(file_path_dev) except OSError as exc: print str(exc) os.system("/bin/cat " + chunk_path_dev + "*" + " > " + file_path_dev + filename) db_api.update_upload_activity(devId, False, datetime.now() - timedelta(0, inactive_timeout, 0)) try: app_socket = socket.socket() app_socket.connect((host, upload_port)) app_socket.send(str(devId) + ":" + file_path_dev + filename) app_socket.close() return jsonify({"success": True}) except Exception, e: return jsonify({"success": False, "reason": str(e)})