コード例 #1
0
def FreePort():
	if 'skip' not in sys.argv:
		logging.info("Trying to Kill process on port %s"%PORT)
		try:
			os.popen("kill -9 $(lsof -i :8081 | grep 'Python' | awk '{print $2}' )")
			pass
		except :
			logging.exception('Unable to free the port')
コード例 #2
0
def main():
	logging.debug("Inside Main Run Api Server. Trying to start the API server")
		#port = int(os.environ.get("PORT", PORT))
	try:
		run(app, host='0.0.0.0', port=PORT, reloader=True)
		logging.info("baba")

	except:
		logging.exception("An error occurred while trying to start the API server")
コード例 #3
0
    def add_parking_lot(self, jsonData):
        res = parkingResponse()
        try:
            status = addParkingLot(jsonData)
            if status:
                success = res.getSuccessResponse()
                success.status.message = 'data posted successfully'
                return success.to_JSON()
        except:
            logging.exception("Unable to post parking lot to DB")

        failure = res.getFailureResponse()
        failure.status.message = 'unable to post data'
        logging.info("parking lot post to DB of FFC failed")
        return failure.to_JSON()
コード例 #4
0
def TestMode():
    from backend.controllers.TestModeController import TestModeController
    response.content_type = 'application/json'
    logging.info("Test mode API called")
    res = parkingResponse()
    try:
        if request.query.get("command"):
            if any(word in request.query.get("command")
                   for word in ["start", "stop", "status", "pause"]):
                logging.info("test command is %s" %
                             request.query.get("command"))
                tbobj = TestModeController(request.query.get("command"))
                responsejson = tbobj.ProcessTestModeCommand()
                return responsejson
    except:
        logging.exception("Unable to process request failed")
    failure = res.getFailureResponse()
    failure.status.message = "Unable to process request, command not valid"
    return failure.to_JSON()
コード例 #5
0
def addParkingLot():
    if request.method == 'POST':
        from backend.models.Response import parkingResponse
        #removed logging from this function as it is the primary call and will be logged a lot of times
        response.content_type = 'application/json'
        from backend.controllers.ParkingController import ParkingController
        cstHand = ParkingController()
        try:
            postJson = json.load(request.body)
            logging.info("The data posted is %s" % postJson)
            postResponse = cstHand.add_parking_lot(postJson)
            return postResponse
        except:
            logging.exception(
                "Some error occurred while trying to create parking lot")

        res = parkingResponse()
        failure = res.getFailureResponse()
        failure.status.message = 'Error during creating parking lot'
        return failure.to_JSON()
コード例 #6
0
def addVehicle():
    if request.method == 'POST':
        from backend.models.Response import parkingResponse
        #removed logging from this function as it is the primary call and will be logged a lot of times
        response.content_type = 'application/json'
        from backend.controllers.VehicleController import VehicleController
        cstHand = VehicleController()
        try:

            postJson = json.load(request.body)
            obj = mngParking.getParkingDetaisByLotId(postJson["lotId"])
            logging.info("here i amj")
            logging.info(obj)
            if (postJson["vehicleType"] == "two"):
                if (obj["twoWheelerParkingCount"] -
                        obj["twoWheelerOccupied"]) > 0:
                    mngParking.updateParkingLot("two", postJson["lotId"])
            if (postJson["vehicleType"] == "lmv"):
                if (obj["lMVParkingCount"] - obj["lMVOccupied"]) > 0:
                    mngParking.updateParkingLot("lmv", postJson["lotId"])
            logging.info("The data posted is %s" % postJson)
            postResponse = cstHand.add_vehicle_at_lot(postJson)
            return postResponse
        except:
            logging.exception(
                "Some error occurred while trying to create parking")

        res = parkingResponse()
        failure = res.getFailureResponse()
        failure.status.message = 'Error during parking'
        return failure.to_JSON()
コード例 #7
0
    def response_parking(self):
        res = parkingResponse()
        logging.info("response customer controller")
        try:
            data = getParking()
        except:
            logging.exception("Error Unable to get customers")
            failure = res.getFailureResponse()
            failure.status.message = 'get Parking fail'
            return failure.to_JSON()

        success = res.getSuccessResponse()
        if data:
            # for row in data:
            # 	time = datetime.fromtimestamp(row['eventTime'])
            # 	row['eventTime'] = str(time)

            logging.info("get Parking FFC %s" % data)
            success.response = data
        else:
            success.status.message = 'customer count empty'
            logging.info("get Parking FFC empty data: %s" % data)
        return success.to_JSON()
コード例 #8
0
def usage():
    logging.info(
        "Error occurred while trying to convert JSON to xml. Incorrect usage.")
コード例 #9
0
def parse_json_stdin(root):
    js = "".join(sys.stdin.readlines())
    j = json.loads(js)
    doc = parse_doc(root, j)
    logging.info(doc.toprettyxml(encoding="utf-8", indent="  "))
コード例 #10
0
def removeVehicle():
    if request.method == 'GET':
        from backend.models.Response import parkingResponse
        logging.info("remove")
        #removed logging from this function as it is the primary call and will be logged a lot of times
        response.content_type = 'application/json'
        vehicleId = request.query.get("vehicleid")
        try:
            logging.info("v id is %s" % vehicleId)
            obj = mngParking.getVechileDetaisl(vehicleId)
            logging.info(obj)
            objLot = mngParking.getParkingDetaisByLotId(obj.lotId)

            logging.info(obj)
            if (obj.vehicleType == "two"):
                rate = objLot["twoWheelerParkingPrice"]
                mngParking.updateRemoveParkingLot("two", obj.lotId)
            if (obj.vehicleType == "lmv"):
                rate = objLot["lMVParkingPrice"]
                mngParking.updateRemoveParkingLot("lmv", obj.lotId)

            TimeStart = obj.insert_time
            now = datetime.datetime.now()
            logging.info(TimeStart)
            logging.info((now - TimeStart).total_seconds())
            delatTime = (now - TimeStart).total_seconds()
            logging.info(rate)
            return {
                "cost": (int)(delatTime / (60 * 60)) * rate,
                "vehicleid": vehicleId,
                "duration": (delatTime) / (60 * 60)
            }
        except:
            logging.exception(
                "Some error occurred while trying to create parking")

        res = parkingResponse()
        failure = res.getFailureResponse()
        failure.status.message = 'Error during removing'
        return failure.to_JSON()