def GET(self,rname):
		conn = Connector('localhost',27017,'receipts','receipt')
		temparr = conn.read()
		arr = []
		for x in temparr:
			arr.append(str(x['_id']))

		for v in arr:
			if (rname == v):
				return "Hello World! %s" % rname
		return arr
Beispiel #2
0
    def GET(self, rname):
        conn = Connector('localhost', 27017, 'receipts', 'receipt')
        temparr = conn.read()
        arr = []
        for x in temparr:
            arr.append(str(x['_id']))

        for v in arr:
            if (rname == v):
                return "Hello World! %s" % rname
        return arr
def main():
	#establish a new connection
	x = Connector('localhost',27017,'receipts','receipt')
	#create a new document for the collection
	a = {"storeName": 'Hemköp',"amountCurrency": 1260,"typeOfCurrency": 'SEK',"date": '29.10.2015',"typeOfReceipt": 'Food',"deprecated": False}
	#call the create method
	#x.create(a)
	store = 'Pressbyrån'
	b = {"storeName":store,"typeOfReceipt":"Entertainment"}
	#print(b)
	#x.update('56eead25316a1164283b8733',b)
	#reads all current documents
	b = x.read()
	#prints the store name of the first array value
	print b[0]['storeName']
Beispiel #4
0
def main():
    #establish a new connection
    x = Connector('localhost', 27017, 'receipts', 'receipt')
    #create a new document for the collection
    a = {
        "storeName": 'Hemköp',
        "amountCurrency": 1260,
        "typeOfCurrency": 'SEK',
        "date": '29.10.2015',
        "typeOfReceipt": 'Food',
        "deprecated": False
    }
    #call the create method
    #x.create(a)
    store = 'Pressbyrån'
    b = {"storeName": store, "typeOfReceipt": "Entertainment"}
    #print(b)
    #x.update('56eead25316a1164283b8733',b)
    #reads all current documents
    b = x.read()
    #prints the store name of the first array value
    print b[0]['storeName']
class Index:
	def __init__(self):

		#create a new connection to the db
		self.conn = Connector('localhost',27017,'receipts','receipt')

	def GET(self, name='None'):
		#read the names from the database
		names = self.conn.read()

		#return the render of index with the array
		return render.index(names)

	def POST(self,name):
		return "post"
Beispiel #6
0
class Index:
    def __init__(self):

        #create a new connection to the db
        self.conn = Connector('localhost', 27017, 'receipts', 'receipt')

    def GET(self, name='None'):
        #read the names from the database
        names = self.conn.read()

        #return the render of index with the array
        return render.index(names)

    def POST(self, name):
        return "post"
Beispiel #7
0
    def run(self):
        """
            Main thread loop
        """

        self.running = True

        # start progress event queue hander thread
        progressOpEventRunner = threading.Thread(
            target=self.progressOpsEventThread)
        progressOpEventRunner.start()

        # Add connectors
        for c in list(Connector.select().where(Connector.state > -1).dicts()):
            self.addConnector(c)

        while self.running:
            for i in range(0, self.heartbeatInterval):
                if not self.running: break
                time.sleep(1)
            self.pumpEvent({'eventType': 'heartbeat', 'eventSource': 'vcube'})

        self.connectorsLock.acquire(True)
        try:
            """ join event queue runner """
            progressOpEventRunner.join()
            """ Stop event listener clients """
            for cid, c in self.connectorEventListeners.iteritems():
                logger.info("Stopping connector client %s" % (cid, ))
                c.stop()
            """ Stop action pool clients """
            for cid, c in self.connectorActionPool.iteritems():
                logger.info("Stopping connector client %s" % (cid, ))
                c.stop()
            """ Join event listeners """
            for cid, c in self.connectorEventListeners.iteritems():
                c.join()
            """ Join clients """
            for cid, c in self.connectorActionPool.iteritems():
                c.join()

            self.connectorActionPool = {}
            self.connectorEventListeners = {}

        finally:
            self.connectorsLock.release()
	def __init__(self):

		#create a new connection to the db
		self.conn = Connector('localhost',27017,'receipts','receipt')
Beispiel #9
0
 def get(self):
     connectors = list(Connector.objects())
     if not connectors:
         abort(404, "networks not found")
     return connectors
Beispiel #10
0
    def __init__(self):

        #create a new connection to the db
        self.conn = Connector('localhost', 27017, 'receipts', 'receipt')
Beispiel #11
0
    def onConnectorStatusChange(self, cid, state, message=''):
        """
            Pump event to clients first
        """
        self.pumpEvent({
            'eventSource': 'vcube',
            'eventType': 'ConnectorStateChanged',
            'connector_id': cid,
            'state': state,
            'state_text': message
        })

        logEvent = False

        try:
            c = Connector.get(Connector.id == int(cid)
                              and Connector.state > -1)
            if int(c.state) != int(state):
                logEvent = True
            c.state = state
            c.state_text = message
            c.save()

        except Connector.DoesNotExist:
            return

        except Exception as e:
            traceback.print_exc()
            logger.exception(e)

        if logEvent:

            sevLookups = {
                constants.CONNECTOR_STATES['DISABLED']:
                constants.SEVERITY['WARNING'],
                constants.CONNECTOR_STATES['DISCONNECTED']:
                constants.SEVERITY['INFO'],
                constants.CONNECTOR_STATES['ERROR']:
                constants.SEVERITY['CRITICAL'],
                constants.CONNECTOR_STATES['REGISTERING']:
                constants.SEVERITY['WARNING'],
                constants.CONNECTOR_STATES['RUNNING']:
                constants.SEVERITY['INFO']
            }

            try:
                self.logEvent({
                    'name':
                    'Connector state changed to ' +
                    constants.CONNECTOR_STATES_TEXT.get(state, 'Unknown'),
                    'details':
                    message,
                    'connector':
                    cid,
                    'severity':
                    sevLookups.get(state, constants.SEVERITY['INFO']),
                    'category':
                    constants.LOG_CATEGORY['CONNECTOR']
                })

            except Exception as e:
                traceback.print_exc()
                logger.exception(e)
Beispiel #12
0
    def createBuilding(self, building):
        db.begin()
        try:
            Building(name=building.get("name")).save()
            if building.get("floors") is not None:
                for floor in building.get("floors"):
                    Floor(level=floor.get("level"),
                          buildingName=building.get("name")).save()

                    if floor.get("waypoints") is not None:
                        for waypoint in floor.get("waypoints"):
                            if ("type" in waypoint):
                                if (waypoint.get("type") ==
                                        WAYPOINT_TYPES["ClassRoom"]):
                                    classRoom = ClassRoom(
                                        name=waypoint.get("name"),
                                        markerId=waypoint.get("markerId"),
                                        buildingName=building.get("name"),
                                        floorLevel=floor.get("level"),
                                        shapeType=waypoint.get("shapeType"),
                                        color=waypoint.get("color"),
                                        width=waypoint.get("width"),
                                        length=waypoint.get("length"),
                                        x=waypoint.get("x"),
                                        y=waypoint.get("y")).save()
                                    for schedule in waypoint["schedule"]:
                                        group = Group.nodes.get_or_none(
                                            name=schedule["group"],
                                            buildingName=building.get("name"))
                                        if group is None:
                                            group = Group(
                                                name=schedule["group"],
                                                buildingName=building.get(
                                                    "name")).save()
                                        group.classes.connect(
                                            classRoom, {
                                                'course':
                                                schedule["course"],
                                                'dayOfWeek':
                                                schedule["dayOfWeek"],
                                                'startTime':
                                                schedule["startTime"],
                                                'finishTime':
                                                schedule["finishTime"]
                                            })
                                elif (waypoint.get("type") ==
                                      WAYPOINT_TYPES["Office"]):
                                    office = Office(
                                        name=waypoint.get("name"),
                                        markerId=waypoint.get("markerId"),
                                        buildingName=building.get("name"),
                                        floorLevel=floor.get("level"),
                                        shapeType=waypoint.get("shapeType"),
                                        color=waypoint.get("color"),
                                        width=waypoint.get("width"),
                                        length=waypoint.get("length"),
                                        x=waypoint.get("x"),
                                        y=waypoint.get("y")).save()
                                    for prof in waypoint["professors"]:
                                        teacher = Teacher.nodes.get_or_none(
                                            name=prof,
                                            buildingName=building.get("name"))
                                        if teacher is None:
                                            teacher = Teacher(
                                                name=prof,
                                                buildingName=building.get(
                                                    "name")).save()
                                        teacher.office.connect(office)
                                elif (waypoint.get("type") ==
                                      WAYPOINT_TYPES["Connector"]):
                                    Connector(
                                        name=waypoint.get("name"),
                                        markerId=waypoint.get("markerId"),
                                        buildingName=building.get("name"),
                                        floorLevel=floor.get("level"),
                                        shapeType=waypoint.get("shapeType"),
                                        color=waypoint.get("color"),
                                        width=waypoint.get("width"),
                                        length=waypoint.get("length"),
                                        x=waypoint.get("x"),
                                        y=waypoint.get("y")).save()
                                else:
                                    Waypoint(
                                        name=waypoint.get("name"),
                                        markerId=waypoint.get("markerId"),
                                        buildingName=building.get("name"),
                                        floorLevel=floor.get("level"),
                                        shapeType=waypoint.get("shapeType"),
                                        color=waypoint.get("color"),
                                        width=waypoint.get("width"),
                                        length=waypoint.get("length"),
                                        x=waypoint.get("x"),
                                        y=waypoint.get("y")).save()
                            else:
                                Waypoint(name=waypoint.get("name"),
                                         markerId=waypoint.get("markerId"),
                                         buildingName=building.get("name"),
                                         floorLevel=floor.get("level"),
                                         shapeType=waypoint.get("shapeType"),
                                         color=waypoint.get("color"),
                                         width=waypoint.get("width"),
                                         length=waypoint.get("length"),
                                         x=waypoint.get("x"),
                                         y=waypoint.get("y")).save()

                    if floor.get("hallways") is not None:
                        for hallway in floor.get("hallways"):
                            Hallway(name=hallway["name"],
                                    markerId=hallway["markerId"],
                                    buildingName=building.get("name"),
                                    floorLevel=floor.get("level"),
                                    shapeType=hallway["shapeType"],
                                    color=hallway["color"],
                                    width=hallway["width"],
                                    length=hallway["length"],
                                    x=hallway["x"],
                                    y=hallway["y"]).save()

                if building.get("floors") is not None:
                    for floor in building.get("floors"):
                        if floor.get("waypoints") is not None:
                            for waypoint in floor.get("waypoints"):
                                base = Waypoint.nodes.get(
                                    name=waypoint.get("name"),
                                    floorLevel=floor.get("level"),
                                    buildingName=building.get("name"))
                                for neighbor in waypoint["neighbors"]:
                                    base.neighbors.connect(
                                        Waypoint.nodes.get(
                                            name=neighbor.get("name"),
                                            floorLevel=floor.get("level"),
                                            buildingName=building.get("name")),
                                        {
                                            'direction':
                                            neighbor.get("direction")
                                        })
            self.checkBuilding(building.get("name"))
            db.commit()
            return self.get(building.get("name")), 200
        except Exception as e:
            db.rollback()
            return str(e), 500