Example #1
0
    def __init__(self):
        log.debug("Initialising Push Script")
        engine = sqlalchemy.create_engine(LOCAL_URL)

        #Intialise the databse
        models.initialise_sql(engine)
        models.populate_data()

        #Get relevant models etc
        session = meta.Session()

        #Check if our data exists
        theDeployment = session.query(
            models.Deployment).filter_by(name="PushTest").first()
        if theDeployment is None:
            log.debug("--> Create New Deployment")
            #Create a new Deployment
            theDeployment = models.Deployment(name="PushTest")
            session.add(theDeployment)
            session.flush()
        log.debug("Deployment is {0}".format(theDeployment))

        theHouse = session.query(
            models.House).filter_by(address="Push Address").first()
        if theHouse is None:
            log.debug("--> Create new House")
            theHouse = models.House(address="Push Address",
                                    deploymentId=theDeployment.id)
            session.add(theHouse)
            session.flush()

        log.debug("House is {0}".format(theHouse))
        #Two Rooms

        roomType = session.query(
            models.RoomType).filter_by(name="Bedroom").first()

        masterBed = session.query(
            models.Room).filter_by(name="Master Bedroom").first()
        if masterBed is None:
            masterBed = models.Room(name="Master Bedroom",
                                    roomTypeId=roomType.id)
            session.add(masterBed)

        secondBed = session.query(
            models.Room).filter_by(name="Second Bedroom").first()
        if secondBed is None:
            secondBed = models.Room(name="Second Bedroom",
                                    roomTypeId=roomType.id)
            session.add(secondBed)
        session.flush()

        #Locations
        masterLoc = session.query(models.Location).filter_by(
            houseId=theHouse.id, roomId=masterBed.id).first()

        if masterLoc is None:
            log.debug("Create New Master Location")
            masterLoc = models.Location(houseId=theHouse.id,
                                        roomId=masterBed.id)
            session.add(masterLoc)

        secondLoc = session.query(models.Location).filter_by(
            houseId=theHouse.id, roomId=secondBed.id).first()
        if secondLoc is None:
            log.debug("Create New Second Location")
            secondLoc = models.Location(houseId=theHouse.id,
                                        roomId=secondBed.id)
            session.add(secondLoc)

        session.flush()
        log.debug("Master Location {0}".format(masterLoc))
        log.debug("Second Location {0}".format(secondLoc))

        #Add Nodes to each Location
        node37 = session.query(models.Node).filter_by(id=37).first()
        if not node37:
            node37 = models.Node(id=37)
            session.add(node37)

        node38 = session.query(models.Node).filter_by(id=38).first()
        if node38 is None:
            node38 = models.Node(id=38)
            session.add(node38)

        node37.location = masterLoc
        node38.location = secondLoc
        session.flush()

        #All Our Data adding script needs to worry about is the Nodes
        self.node37 = node37
        self.node38 = node38

        #Finally add an Upload URL if required
        # theUrl = session.query(models.UploadURL).filter_by(url="[email protected]").first()
        # if not theUrl:
        #     theUrl = models.UploadURL(url="[email protected]",
        #                               dburl="mysql://*****:*****@localhost:3307/pushTest")
        #     session.add(theUrl)

        # theUrl = session.query(models.UploadURL).filter_by(url="*****@*****.**").first()
        # if not theUrl:
        #     theUrl = models.UploadURL(url="*****@*****.**",
        #                               dburl="mysql://*****:*****@localhost:3307/chtest")
        #     session.add(theUrl)

        session.commit()
Example #2
0
    def __init__(self):
        log.debug("Initialising Push Script")
        engine = sqlalchemy.create_engine(LOCAL_URL)
    
        #Intialise the databse
        models.initialise_sql(engine)
        models.populate_data()

        #Get relevant models etc
        session = meta.Session()
        
        #Check if our data exists
        theDeployment = session.query(models.Deployment).filter_by(name="PushTest").first()
        if theDeployment is None:
            log.debug("--> Create New Deployment")
            #Create a new Deployment
            theDeployment = models.Deployment(name="PushTest")
            session.add(theDeployment)
            session.flush()
        log.debug("Deployment is {0}".format(theDeployment))
            
        theHouse = session.query(models.House).filter_by(address="Push Address").first()
        if theHouse is None:
            log.debug("--> Create new House")
            theHouse = models.House(address="Push Address",deploymentId=theDeployment.id)
            session.add(theHouse)
            session.flush()

        log.debug("House is {0}".format(theHouse))
        #Two Rooms
        
        roomType = session.query(models.RoomType).filter_by(name="Bedroom").first()

        masterBed = session.query(models.Room).filter_by(name="Master Bedroom").first()
        if masterBed is None:
            masterBed = models.Room(name="Master Bedroom",roomTypeId=roomType.id)
            session.add(masterBed)
            
        secondBed = session.query(models.Room).filter_by(name="Second Bedroom").first()
        if secondBed is None:
            secondBed = models.Room(name="Second Bedroom",roomTypeId=roomType.id)
            session.add(secondBed)
        session.flush()
            

        #Locations
        masterLoc = session.query(models.Location).filter_by(houseId = theHouse.id,roomId=masterBed.id).first()
        
        if masterLoc is None:
            log.debug("Create New Master Location")
            masterLoc = models.Location(houseId=theHouse.id,
                                        roomId = masterBed.id)
            session.add(masterLoc)
        
        secondLoc = session.query(models.Location).filter_by(houseId=theHouse.id,
                                                             roomId=secondBed.id).first()
        if secondLoc is None:
            log.debug("Create New Second Location")
            secondLoc = models.Location(houseId = theHouse.id,
                                        roomId = secondBed.id)
            session.add(secondLoc)
        
        session.flush()
        log.debug("Master Location {0}".format(masterLoc))
        log.debug("Second Location {0}".format(secondLoc))

        #Add Nodes to each Location
        node37 = session.query(models.Node).filter_by(id=37).first()
        if not node37:
            node37 = models.Node(id=37)
            session.add(node37)

        node38 = session.query(models.Node).filter_by(id=38).first()
        if node38 is None:
            node38 = models.Node(id=38)
            session.add(node38)
                  
        node37.location = masterLoc
        node38.location = secondLoc
        session.flush()

        #All Our Data adding script needs to worry about is the Nodes
        self.node37 = node37
        self.node38 = node38

        #Finally add an Upload URL if required
        # theUrl = session.query(models.UploadURL).filter_by(url="[email protected]").first()
        # if not theUrl:
        #     theUrl = models.UploadURL(url="[email protected]",
        #                               dburl="mysql://*****:*****@localhost:3307/pushTest")
        #     session.add(theUrl)
        
        # theUrl = session.query(models.UploadURL).filter_by(url="*****@*****.**").first()
        # if not theUrl:
        #     theUrl = models.UploadURL(url="*****@*****.**",
        #                               dburl="mysql://*****:*****@localhost:3307/chtest")
        #     session.add(theUrl)

        session.commit()
Example #3
0
"""
Utility Function to remove all data from a given DB
"""

#DBURL = ['mysql://*****:*****@localhost/pushTest',
#         'mysql://*****:*****@localhost/pushSource']

DBURL = ['mysql://*****:*****@127.0.0.1:3307/chtest']

#DBURL = ['mysql://*****:*****@localhost/pushTest']

import sqlalchemy
import cogent.base.model as models
import cogent.base.model.meta as meta

for url in DBURL:
    engine = sqlalchemy.create_engine(url)

    models.initialise_sql(engine, True)
    models.populate_data()
Example #4
0
"""
Utility Function to remove all data from a given DB
"""

#DBURL = ['mysql://*****:*****@localhost/pushTest',
#         'mysql://*****:*****@localhost/pushSource']

DBURL = ['mysql://*****:*****@127.0.0.1:3307/chtest']

#DBURL = ['mysql://*****:*****@localhost/pushTest']


import sqlalchemy
import cogent.base.model as models
import cogent.base.model.meta as meta

for url in DBURL:
    engine = sqlalchemy.create_engine(url)

    models.initialise_sql(engine,True)
    models.populate_data()