Beispiel #1
0
class StandardLog(r.Base):
    # PERMA : DO NOT CHANGE ANYTHING HERE UNLESS NECESSARY
    id = r.Column(r.Integer, primary_key=True)

    def __repr__(self):
        return '<%r %r>' % (self.__tablename__, self.id)

    #---------------------------------------------------------

    ######################################################################################################
    # EDITABLE ZONE
    ######################################################################################################
    # TODO: CHANGE TABLENAME
    __tablename__ = "Standard_Logs"
    # TODO: DEFINE LIST OF COLUMNS
    timev0 = r.Column(r.DateTime, nullable=False)  #insertion time
    timev1 = r.Column(r.DateTime, nullable=True)  #time logging
    timev2 = r.Column(r.DateTime, nullable=True)

    param0 = r.Column(r.String(r.lim.MAX_UUPARAM_SIZE),
                      nullable=False)  #for data logging
    param1 = r.Column(r.String(r.lim.MAX_UUPARAM_SIZE), nullable=True)
    param2 = r.Column(r.String(r.lim.MAX_UUPARAM_SIZE), nullable=True)

    ref0 = r.Column(r.Integer, nullable=False)  #for references
    ref1 = r.Column(r.Integer, nullable=True)
    ref2 = r.Column(r.Integer, nullable=True)

    # TODO: DEFINE THE RLIST
    #The following is for r-listing (resource listing)
    # the values in the rlist must be the same as the column var name
    rlist = r.OrderedDict([
        ("Entity ID", "id"), ("Param0", "param0"), ("Param1", "param1"),
        ("Param2", "param2"), ("Ref0", "ref0"), ("Ref1", "ref1"),
        ("Ref2", "ref2"), ("Time v0", "__time__/%b-%d-%Y %H:%M:%S/timev0"),
        ("Time v1", "__time__/%b-%d-%Y/timev1"),
        ("Time v2", "__time__/%H:%M:%S/timev2")
    ])  #header,row data

    # TODO: DEFINE THE priKey and display text
    #this primary key is used for rlisting/adding and mod.
    rlist_priKey = "id"
    rlist_dis = "Standard Log Model"  #display for r routes

    # TODO: CONSTRUCTOR DEFINES, PLEASE ADD IN ACCORDING TO COLUMNS
    # the key in the insert_list must be the same as the column var name
    def __init__(self, insert_list):

        self.timev0 = datetime.datetime.now()
        self.timev1 = r.checkNull(insert_list, "timev1")
        self.timev1 = r.checkNull(insert_list, "timev2")

        self.param0 = insert_list["param0"]
        self.param1 = r.checkNull(insert_list, "param1")
        self.param2 = r.checkNull(insert_list, "param2")

        self.ref0 = insert_list["ref0"]
        self.ref1 = r.checkNull(insert_list, "ref1")
        self.ref2 = r.checkNull(insert_list, "ref2")
Beispiel #2
0
class Msgapi_User(Base):
    __tablename__ = "Msgapi_Users"  #Try to use plurals here (i.e car's')
    id = r.Column(r.Integer, primary_key=True)

    def __repr__(self):
        return '<%r %r>' % (self.__tablename__, self.id)

    username = r.Column(r.String(r.lim.MAX_USERNAME_SIZE), unique=True)
    access_key = r.Column(r.String(r.lim.MAX_PASSWORD_SIZE))
    # TODO: figure out a way to secure this more
    # justification for access_key storage here. the reason is
    # to allow the administrator to easily obtain the password from
    # the database
    usertype = r.Column(r.String(r.lim.MAX_USERNAME_SIZE), unique=False)

    rlist = r.OrderedDict([("Username", "username"),
                           ("Access Key", "access_key"),
                           ("API Type", "usertype")])
    rlist_priKey = "id"
    rlist_dis = "Msgapi Users"  #display for r routes

    @staticmethod
    def update_auth(apitype):
        if (apitype == "MQTTv0"):
            # TODO : use mosquitto_passwd tool
            authfile = os.path.join(r.const.CFG_FILEDIR, 'mosquitto.auth')
            if (os.path.isfile(authfile)):
                os.remove(authfile)
            users = Msgapi_User.query.filter(
                Msgapi_User.usertype == apitype).all()
            with open(authfile, 'w') as afile:
                for u in users:
                    afile.write(u.username)
                    afile.write(':')
                    afile.write(u.access_key)
                    afile.write('\n')  #this line bugged the config file.
            rewrite_pwdfile = Popen(['mosquitto_passwd', '-U', authfile])
            rewrite_pwdfile.wait()
            BrokerThread.restart()  # restart the broker
        else:
            pass

    def __init__(self, insert_list):
        self.username = insert_list["username"]
        self.access_key = insert_list["access_key"]
        self.usertype = insert_list["usertype"]

    def default_add_action(self):
        # updates the config file
        Msgapi_User.update_auth(self.usertype)

    def default_mod_action(self):
        # updates the config file
        Msgapi_User.update_auth(self.usertype)

    def default_del_action(self):
        # updates the config file
        Msgapi_User.update_auth(self.usertype)
Beispiel #3
0
class StandardFile(r.Base):
    # PERMA : DO NOT CHANGE ANYTHING HERE UNLESS NECESSARY
    id = r.Column(r.Integer, primary_key=True)

    def __repr__(self):
        return '<%r %r>' % (self.__tablename__, self.id)

    #---------------------------------------------------------

    ######################################################################################################
    # EDITABLE ZONE
    ######################################################################################################
    # TODO: CHANGE TABLENAME
    __tablename__ = "Standard_Files"
    # TODO: DEFINE LIST OF COLUMNS
    filename = r.Column(r.String(r.lim.MAX_FILENAME_SIZE),
                        nullable=False,
                        unique=True)
    mimetype = r.Column(r.String(r.lim.MAX_UUPARAM_SIZE),
                        nullable=False,
                        unique=False)
    uptime = r.Column(r.DateTime,
                      nullable=False)  #time logging (time of upload)
    fileown = r.Column(r.Integer, nullable=True)

    # TODO: DEFINE THE RLIST
    #The following is for r-listing (resource listing)
    # the values in the rlist must be the same as the column var name
    rlist = r.OrderedDict([("Filename", "filename"),
                           ("URL",
                            "__url__/stdfile.retrieve_uploads/filename"),
                           ("MIME type", "mimetype"),
                           ("Uploaded Time", "__time__/%b %d %Y/uptime"),
                           ("Uploader", "fileown")])  #header,row data

    # TODO: DEFINE THE priKey and display text
    #this primary key is used for rlisting/adding and mod.
    rlist_priKey = "id"
    rlist_dis = "Standard File Model"  #display for r routes

    # TODO: CONSTRUCTOR DEFINES, PLEASE ADD IN ACCORDING TO COLUMNS
    # the key in the insert_list must be the same as the column var name
    def __init__(self, insert_list):
        self.filename = insert_list["filename"]
        self.mimetype = insert_list["mimetype"]
        self.uptime = datetime.datetime.now()
        self.fileown = r.checkNull(insert_list, "fileown")

    def default_del_action(self):
        # This will be run when the table is deleted
        # may do some imports here i.e (from pkg.database.fsqlite import db_session)
        os.remove(os.path.join('pkg', r.const.STD_FILEDIR, self.filename))
Beispiel #4
0
class CanvasLine(r.Base):
    # PERMA : DO NOT CHANGE ANYTHING HERE UNLESS NECESSARY
    __tablename__ = "Canvas_Lines"
    id = r.Column(r.Integer, primary_key=True)
    def __repr__(self):
    	return '<%r %r>' % (self.__tablename__,self.id)
    #---------------------------------------------------------

    ######################################################################################################
    # EDITABLE ZONE
    ######################################################################################################
    # TODO: DEFINE LIST OF COLUMNS
    startx = r.Column(r.Integer, nullable=False,unique=False)
    starty = r.Column(r.Integer, nullable=False,unique=False)
    endx = r.Column(r.Integer, nullable=False,unique=False)
    endy = r.Column(r.Integer, nullable=False,unique=False)
    width = r.Column(r.Integer, nullable=False,unique=False)
    color = r.Column(r.String(r.lim.MAX_UUPARAM_SIZE), nullable=False, unique=False)
    tcolor = r.Column(r.String(r.lim.MAX_UUPARAM_SIZE), nullable=False, unique=False)

    # rlinking - do not have to change the variable name

    # TODO: DEFINE THE RLIST
    #The following is for r-listing (resource listing)
    # the values in the rlist must be the same as the column var name
    rlist = r.OrderedDict([
    ("startx","startx"),
    ("starty","starty"),
    ("endx","endx"),
    ("endy","endy"),
    ("width","width"),
    ("defcolor","color"),
    ("trgcolor","tcolor")# __link__ is a reserved keyword
    ]) #header,row data
    # use the __link__/ and __ route_id to 'link' route_id onto something
    # the linkage is defined under the rlink dictionary down there
    # see 'RLINK'

    # TODO: DEFINE THE priKey and display text
    #this primary key is used for rlisting/adding and mod.
    rlist_priKey = "id"
    rlist_dis = "Canvas Lines" #display for r routes

    #RLINK - indicate a link (foreign key reference lookup)
    #rlink - ref tablename, fkey, lookup
    #the key defines how a column is linked, route_id is linked
    #to the table Georoute, looking up for the ID in Georoute and retrieving
    #the name.

    # TODO: CONSTRUCTOR DEFINES, PLEASE ADD IN ACCORDING TO COLUMNS
    # the key in the insert_list must be the same as the column var name
    def __init__(self,insert_list):
        self.startx = insert_list["startx"]
        self.starty = insert_list["starty"]
        self.endx = insert_list["endx"]
        self.endy = insert_list["endy"]
        self.width = insert_list["width"]
        self.color = insert_list["color"]
        self.tcolor = insert_list["tcolor"]
Beispiel #5
0
class Param3(r.Base):
    # PERMA : DO NOT CHANGE ANYTHING HERE UNLESS NECESSARY
    id = r.Column(r.Integer, primary_key=True)

    def __repr__(self):
        return '<%r %r>' % (self.__tablename__, self.id)

    #---------------------------------------------------------

    ######################################################################################################
    # EDITABLE ZONE
    ######################################################################################################
    # TODO: CHANGE TABLENAME
    __tablename__ = "Param3s"
    # TODO: DEFINE LIST OF COLUMNS
    param0 = r.Column(r.String(r.lim.MAX_UUPARAM_SIZE), nullable=False)
    param1 = r.Column(r.String(r.lim.MAX_UUPARAM_SIZE), nullable=True)
    param2 = r.Column(r.String(r.lim.MAX_UUPARAM_SIZE), nullable=True)

    # TODO: DEFINE THE RLIST
    #The following is for r-listing (resource listing)
    # the values in the rlist must be the same as the column var name
    rlist = r.OrderedDict([("Entity ID", "id"), ("Param0", "param0"),
                           ("Param1", "param1"),
                           ("Param2", "param2")])  #header,row data

    # TODO: DEFINE THE priKey and display text
    #this primary key is used for rlisting/adding and mod.
    rlist_priKey = "id"
    rlist_dis = "Param 3 Model"  #display for r routes

    # TODO: CONSTRUCTOR DEFINES, PLEASE ADD IN ACCORDING TO COLUMNS
    # the key in the insert_list must be the same as the column var name
    def __init__(self, insert_list):
        self.param0 = insert_list["param0"]
        self.param1 = r.checkNull(insert_list, "param1")
        self.param2 = r.checkNull(insert_list, "param2")
Beispiel #6
0
class MQTT_Msg(Base):
    # PERMA : DO NOT CHANGE ANYTHING HERE UNLESS NECESSARY
    __tablename__ = "MQTT_Msgs"  #Try to use plurals here (i.e car's')
    id = r.Column(r.Integer, primary_key=True)

    def __repr__(self):
        return '<%r %r>' % (self.__tablename__, self.id)

    #---------------------------------------------------------

    ######################################################################################################
    # EDITABLE ZONE
    ######################################################################################################
    # TODO: DEFINE LIST OF COLUMNS
    # the string topic of the topic to subscribe to
    topic = r.Column(r.String(r.lim.MAX_MQTT_TOPIC_SIZE), nullable=False)
    tlink = r.Column(r.Integer,
                     nullable=True)  #links to one of our subscribed topic
    msg = r.Column(r.String(r.lim.MAX_MQTT_MSGCT_SIZE), nullable=False)
    timev0 = r.Column(r.DateTime, nullable=False)  #insertion time
    timed0 = r.Column(r.DateTime,
                      nullable=True)  #deletion time (msg to be kept until)
    pflag0 = r.Column(
        r.Boolean,
        nullable=False)  #flag to check if the msg has been processed
    pflag1 = r.Column(
        r.Boolean, nullable=False
    )  #flag to check if the msg has been processed successfully
    delonproc = r.Column(
        r.Boolean, nullable=False
    )  #flag to check if this message should be delete on process

    # TODO: DEFINE THE RLIST
    # CHANGED ON U6 : RLISTING NOW MERGED WITH RLINKING : see 'RLINKING _ HOW TO USE:'
    # The following is for r-listing (as of u6, rlinking as well) (resource listing)
    # the values in the rlist must be the same as the column var name
    rlist = r.OrderedDict([
        ("Topic", "topic"),
        ("Linked (description)", "__link__/tlink/MQTT_Subs/id:description"),
        ("Content", "msg"), ("Received", "__time__/%b-%d-%Y %H:%M:%S/timev0"),
        ("Delete on", "__time__/%b-%d-%Y %H:%M:%S/timed0"),
        ("Processed?", "pflag0"), ("Process OK?", "pflag1")
    ])  #header,row data

    # RLINKING _ HOW TO USE :
    # using the __link__ keyword, seperate the arguments with /
    # The first argument is the local reference, the field in which we use to refer
    # the second argument is the foreign table
    # the third argument is the foreign table Primary key
    # the fourth argument is the field we want to find from the foreign table
    # NOTICE that the fourth table uses ':' instead of /.
    # Example
    # "RPi id":"__link__/rpi_id/RPi/id:rpi_name"
    # for the display of RPi id, we link to a foreign table that is called RPi
    # we use the rpi_id foreign key on this table, to locate the id on the foreign table
    # then we query for the field rpi_name

    # TODO: DEFINE THE priKey and display text
    #this primary key is used for rlisting/adding and mod.
    rlist_priKey = "id"
    rlist_dis = "MQTT Message Stack"  #display for r routes

    def get_onrecv(self):
        # get the name of the process used on this msg
        from pkg.msgapi.mqtt.models import MQTT_Sub
        t = MQTT_Sub.query.filter(MQTT_Sub.id == self.tlink).first()
        if (t is not None):
            return t.onrecv

    # TODO: CONSTRUCTOR DEFINES, PLEASE ADD IN ACCORDING TO COLUMNS
    # the key in the insert_list must be the same as the column var name
    def __init__(self, insert_list):
        '''requirements in insert_list
        @param tlink - link to the mqtt sub record
        @param topic - the topic string (incase linking failed)
        @param msg - the msg content'''
        from pkg.msgapi.mqtt.models import MQTT_Sub
        from pkg.system.servlog import srvlog
        import datetime
        from datetime import timedelta
        # find links
        self.tlink = r.checkNull(insert_list, "tlink")
        self.topic = insert_list["topic"]
        self.msg = insert_list["msg"]
        self.timev0 = datetime.datetime.now()
        self.pflag0 = insert_list["pflag0"]
        self.pflag1 = insert_list["pflag1"]
        submaster = MQTT_Sub.query.filter(MQTT_Sub.id == self.tlink).first()
        if (submaster is not None):
            if (submaster.stordur is None):
                self.timed0 = None  #store forever
            else:
                self.timed0 = self.timev0 + timedelta(
                    seconds=submaster.stordur)
            self.delonproc = submaster.delonproc  #inherits from the topic master
        else:
            srvlog["oper"].warning(
                "MQTT message added to unknown link topic:" + self.topic +
                " id=" + int(self.tlink))
            self.timed0 = r.lim.DEF_MQTT_MSGST_DURA
            self.delonproc = True

    def default_add_action(self):
        # This will be run when the table is added via r-add
        # may do some imports here i.e (from pkg.database.fsqlite import db_session)
        # TODO add a MQTT restart function here
        pass

    def default_mod_action(self):
        # This will be run when the table is added modified via r-mod
        # may do some imports here i.e (from pkg.database.fsqlite import db_session)
        pass

    def default_del_action(self):
        # This will be run when the table is deleted
        # may do some imports here i.e (from pkg.database.fsqlite import db_session)
        pass
Beispiel #7
0
class MQTT_Broker_Configuration(Base):
    # PERMA : DO NOT CHANGE ANYTHING HERE UNLESS NECESSARY
    __tablename__ = "MQTT_Broker_Configs"  #Try to use plurals here (i.e car's')
    id = r.Column(r.Integer, primary_key=True)

    def __repr__(self):
        return '<%r %r>' % (self.__tablename__, self.id)

    config_name = r.Column(r.String(r.lim.MAX_CONFIG_NAME_SIZE),
                           nullable=False)
    config_value = r.Column(r.String(r.lim.MAX_CONFIG_VALU_SIZE),
                            unique=False,
                            nullable=False)

    rlist = r.OrderedDict([("Configuration Name", "config_name"),
                           ("Value", "config_value")])
    #header:row ,data

    rlist_priKey = "id"
    rlist_dis = "MQTT Broker Configuration"  #display for r routes

    reserved_keys = [
        "log_dest", "password_file", "cafile", "certfile", "keyfile", "use_ssl"
    ]

    def __init__(self, insert_list):
        self.config_name = insert_list["config_name"]
        self.config_value = insert_list["config_value"]

    @staticmethod
    def update_config():
        mbconf_file = os.path.join(r.const.CFG_FILEDIR, 'mosquitto.conf')
        if (os.path.isfile(mbconf_file)):
            os.remove(mbconf_file)
            print("[WR]", __name__, " : ", "Removing old mosquitto.conf")
        copyfile(os.path.join(r.const.CFG_FILEDIR, 'mosquitto.conf.bak'),
                 mbconf_file)
        conf = MQTT_Broker_Configuration.query.all()

        ssl_ca = r.const.SSL_CA
        ssl_cert = r.const.SSL_CERT
        ssl_skey = r.const.SSL_SKEY

        import __main__
        srvabs = os.path.dirname(os.path.abspath(__main__.__file__))
        print("[IF]", __name__, " : ", "Updating Broker Configuration file",
              mbconf_file)
        with open(mbconf_file, 'a') as cfile:
            cfile.write("log_dest file "+os.path.join(srvabs,r.const.LOGS_DIR,\
                    'mosquitto.log.tmp')+'\n')
            cfile.write("password_file "+os.path.join(srvabs,\
                    r.const.CFG_FILEDIR,'mosquitto.auth')+'\n')
            for c in conf:
                if (c.config_name in MQTT_Broker_Configuration.reserved_keys):
                    #log_dest must not be changed, so does the password_file loc
                    #TLS params should not be edited at all.
                    if (c.config_name == "use_ssl"
                            and c.config_value in ['true', 'True', 1, '1']):
                        cfile.write("cafile " + os.path.join(srvabs, ssl_ca) +
                                    '\n')
                        cfile.write("certfile " +
                                    os.path.join(srvabs, ssl_cert) + '\n')
                        cfile.write("keyfile " +
                                    os.path.join(srvabs, ssl_skey) + '\n')
                else:
                    cfile.write(c.config_name)
                    cfile.write(' ')
                    cfile.write(c.config_value)
                    cfile.write('\n')
        srvlog["sys"].info("Broker Configuration file updated " + mbconf_file)
        BrokerThread.restart()  # restart the broker

    def default_add_action(self):
        # updates the config file
        MQTT_Broker_Configuration.update_config()

    def default_mod_action(self):
        # updates the config file
        MQTT_Broker_Configuration.update_config()

    def default_del_action(self):
        # updates the config file
        MQTT_Broker_Configuration.update_config()
Beispiel #8
0
class MQTT_Sub(Base):
    # PERMA : DO NOT CHANGE ANYTHING HERE UNLESS NECESSARY
    __tablename__ = "MQTT_Subs"  #Try to use plurals here (i.e car's')
    id = r.Column(r.Integer, primary_key=True)

    def __repr__(self):
        return '<%r %r>' % (self.__tablename__, self.id)

    #---------------------------------------------------------

    ######################################################################################################
    # EDITABLE ZONE
    ######################################################################################################
    # TODO: DEFINE LIST OF COLUMNS
    # the string topic of the topic to subscribe to
    topic = r.Column(r.String(r.lim.MAX_MQTT_TOPIC_SIZE),
                     nullable=False,
                     unique=True)
    description = r.Column(r.String(r.lim.MAX_DESCRIPTION_SIZE),
                           nullable=True,
                           unique=False)
    stordur = r.Column(r.Integer, nullable=True)  #how long to store messages
    delonproc = r.Column(
        r.Boolean, nullable=False)  #delete the messages after processing?
    deloncas = r.Column(
        r.Boolean, nullable=False)  #delete all msg if the topics get deleted
    instantp = r.Column(
        r.Boolean, nullable=False)  #delete all msg if the topics get deleted
    onrecv = r.Column(r.String,
                      nullable=True)  #instantly process message upon receive

    # TODO: DEFINE THE RLIST
    # CHANGED ON U6 : RLISTING NOW MERGED WITH RLINKING : see 'RLINKING _ HOW TO USE:'
    # The following is for r-listing (as of u6, rlinking as well) (resource listing)
    # the values in the rlist must be the same as the column var name
    rlist = r.OrderedDict([("Subscription ID", "id"), ("Topic Name", "topic"),
                           ("Description", "description"),
                           ("Store N seconds (None/Null = Forever)",
                            "stordur"), ("Delete on processed?", "delonproc"),
                           ("Delete on cascade?", "deloncas"),
                           ("Instantly Process?", "instantp"),
                           ("OnReceive Action", "onrecv")])  #header,row data

    # RLINKING _ HOW TO USE :
    # using the __link__ keyword, seperate the arguments with /
    # The first argument is the local reference, the field in which we use to refer
    # the second argument is the foreign table
    # the third argument is the foreign table Primary key
    # the fourth argument is the field we want to find from the foreign table
    # NOTICE that the fourth table uses ':' instead of /.
    # Example
    # "RPi id":"__link__/rpi_id/RPi/id:rpi_name"
    # for the display of RPi id, we link to a foreign table that is called RPi
    # we use the rpi_id foreign key on this table, to locate the id on the foreign table
    # then we query for the field rpi_name

    # TODO: DEFINE THE priKey and display text
    #this primary key is used for rlisting/adding and mod.
    rlist_priKey = "id"
    rlist_dis = "MQTT Subscriptions"  #display for r routes

    # TODO: CONSTRUCTOR DEFINES, PLEASE ADD IN ACCORDING TO COLUMNS
    # the key in the insert_list must be the same as the column var name
    def __init__(self, insert_list):
        self.topic = insert_list["topic"]
        self.delonproc = bool(insert_list["delonproc"])
        self.deloncas = bool(insert_list["deloncas"])
        self.instantp = bool(insert_list["instantp"])

        #FOR nullable=True, use a the checkNull method
        self.description = r.checkNull(insert_list, "description")
        self.stordur = r.checkNull(insert_list, "stordur")
        self.onrecv = r.checkNull(insert_list, "onrecv")

    def default_add_action(self):
        # This will be run when the table is added via r-add
        # may do some imports here i.e (from pkg.database.fsqlite import db_session)
        # TODO add a MQTT restart function here
        pass

    def default_mod_action(self):
        # This will be run when the table is added modified via r-mod
        # may do some imports here i.e (from pkg.database.fsqlite import db_session)
        pass

    def default_del_action(self):
        # This will be run when the table is deleted
        # may do some imports here i.e (from pkg.database.fsqlite import db_session)
        # delete all linked on cascade
        if (self.deloncas):
            import pkg.system.database.dbms as dbms
            from pkg.msgapi.mqtt.models import MQTT_Msg
            links = MQTT_Msg.query.filter(MQTT_Msg.tlink == self.id).all()
            for m in links:
                dbms.sy_session.delete(m)
            srvlog["oper"].warning(
                "Removed MQTT SubTopic and messages with cascade")
            dbms.sy_session.commit()
Beispiel #9
0
class TODO_SAMPLE(r.Base):
    # PERMA : DO NOT CHANGE ANYTHING HERE UNLESS NECESSARY
    __tablename__ = "CHANGE_THIS"  #Try to use plurals here (i.e car's')
    id = r.Column(r.Integer, primary_key=True)

    def __repr__(self):
        return '<%r %r>' % (self.__tablename__, self.id)

    #---------------------------------------------------------

    ######################################################################################################
    # EDITABLE ZONE
    ######################################################################################################
    # TODO: DEFINE LIST OF COLUMNS
    long = r.Column(r.Float, nullable=False)  #longitude
    lati = r.Column(r.Float, nullable=False)  #latitude
    time = r.Column(r.DateTime, nullable=False)

    # rlinking - do not have to change the variable name
    route_id = r.Column(r.Integer, nullable=True)

    # TODO: DEFINE THE RLIST
    # CHANGED ON U6 : RLISTING NOW MERGED WITH RLINKING : see 'RLINKING _ HOW TO USE:'
    # The following is for r-listing (as of u6, rlinking as well) (resource listing)
    # the values in the rlist must be the same as the column var name
    rlist = r.OrderedDict([
        ("Geopoint ID", "id"),
        ("Longitude", "long"),
        ("Latitude", "lati"),
        ("Linked Entity", "__link__/route_id/Georoute/id:name"
         ),  # __link__ is a reserved keyword
        ("Timestamp", "__time__/%b-%d-%Y %H:%M:%S/time")
    ])  #header,row data

    # RLINKING _ HOW TO USE :
    # using the __link__ keyword, seperate the arguments with /
    # The first argument is the local reference, the field in which we use to refer
    # the second argument is the foreign table
    # the third argument is the foreign table Primary key
    # the fourth argument is the field we want to find from the foreign table
    # NOTICE that the fourth table uses ':' instead of /.
    # Example
    # "RPi id":"__link__/rpi_id/RPi/id:rpi_name"
    # for the display of RPi id, we link to a foreign table that is called RPi
    # we use the rpi_id foreign key on this table, to locate the id on the foreign table
    # then we query for the field rpi_name

    # TODO: DEFINE THE priKey and display text
    #this primary key is used for rlisting/adding and mod.
    rlist_priKey = "id"
    rlist_dis = "Geopoints"  #display for r routes
    rmod_nodel = False  # Set to true to disable R from deleting it

    # TODO: CONSTRUCTOR DEFINES, PLEASE ADD IN ACCORDING TO COLUMNS
    # the key in the insert_list must be the same as the column var name
    def __init__(self, insert_list):
        self.long = insert_list["long"]
        self.lati = insert_list["lati"]
        self.time = insert_list["time"]

        #FOR nullable=True, use a the checkNull method
        self.route_id = r.checkNull(insert_list, "route_id")

    def default_add_action(self):
        # This will be run when the table is added via r-add
        # may do some imports here i.e (from pkg.database.fsqlite import db_session)
        pass

    def default_mod_action(self):
        # This will be run when the table is added modified via r-mod
        # may do some imports here i.e (from pkg.database.fsqlite import db_session)
        pass

    def default_del_action(self):
        # This will be run when the table is deleted
        # may do some imports here i.e (from pkg.database.fsqlite import db_session)
        pass
Beispiel #10
0
class NetNode(r.Base):
    # PERMA : DO NOT CHANGE ANYTHING HERE UNLESS NECESSARY
    __tablename__ = "NetworkNode"
    id = r.Column(r.Integer, primary_key=True)

    def __repr__(self):
        return '<%r %r>' % (self.__tablename__, self.id)

    #---------------------------------------------------------

    ######################################################################################################
    # EDITABLE ZONE
    ######################################################################################################
    # TODO: DEFINE LIST OF COLUMNS
    ip_address = r.Column(r.String(r.lim.MAX_IPADDR_SIZE),
                          nullable=False,
                          unique=True)
    description = r.Column(r.String(r.lim.MAX_DESCRIPTION_SIZE),
                           nullable=False,
                           unique=False)

    # rlinking - do not have to change the variable name

    # TODO: DEFINE THE RLIST
    #The following is for r-listing (resource listing)
    # the values in the rlist must be the same as the column var name
    rlist = r.OrderedDict([
        ("NodeID", "id"),
        ("IP address", "ip_address"),
        ("Description", "description"),
    ])  #header,row data
    # use the __link__/ and __ route_id to 'link' route_id onto something
    # the linkage is defined under the rlink dictionary down there
    # see 'RLINK'

    # TODO: DEFINE THE priKey and display text
    #this primary key is used for rlisting/adding and mod.
    rlist_priKey = "id"
    rlist_dis = "Network Node List"  #display for r routes

    #RLINK - indicate a link (foreign key reference lookup)
    #rlink - ref tablename, fkey, lookup
    #the key defines how a column is linked, route_id is linked
    #to the table Georoute, looking up for the ID in Georoute and retrieving
    #the name.

    # TODO: CONSTRUCTOR DEFINES, PLEASE ADD IN ACCORDING TO COLUMNS
    # the key in the insert_list must be the same as the column var name
    def __init__(self, insert_list):
        self.ip_address = insert_list["ip_address"]
        self.description = insert_list["description"]

    def default_add_action(self):
        #This will be run when the table is added via r-add
        pass

    def default_mod_action(self):
        #This will be run when the table is added via r-mod
        pass

    def default_del_action(self):
        #This will be run when the table is added via r-del
        pass