connectordb/_device.py
def import_stream(self, directory):
        """Imports a stream from the given directory. You export the Stream
        by using stream.export()"""

        # read the stream's info
        with open(os.path.join(directory, "stream.json"), "r") as f:
            sdata = json.load(f)

        s = self[sdata["name"]]
        if s.exists():
            raise ValueError("The stream " + s.name + " already exists")

        # Create the stream empty first, so we can insert all the data without
        # worrying about schema violations or downlinks
        s.create()

        # Now, in order to insert data into this stream, we must be logged in as
        # the owning device
        ddb = DatabaseConnection(self.apikey, url=self.db.baseurl)
        d = Device(ddb, self.path)

        # Set up the owning device
        sown = d[s.name]

        # read the stream's info
        sown.insert_array(DatapointArray().loadExport(directory))

        # Now we MIGHT be able to recover the downlink data,
        # only if we are not logged in as the device that the stream is being inserted into
        # So we check. When downlink is true, data is inserted into the
        # downlink stream
        if (sdata["downlink"] and self.db.path != self.path):
            s.downlink = True
            with open(os.path.join(directory, "downlink.json"), "r") as f:
                s.insert_array(json.load(f))

        # And finally, update the device
        del sdata["name"]
        s.set(sdata)
def import_stream(self, directory):
        """Imports a stream from the given directory. You export the Stream
        by using stream.export()"""

        # read the stream's info
        with open(os.path.join(directory, "stream.json"), "r") as f:
            sdata = json.load(f)

        s = self[sdata["name"]]
        if s.exists():
            raise ValueError("The stream " + s.name + " already exists")

        # Create the stream empty first, so we can insert all the data without
        # worrying about schema violations or downlinks
        s.create()

        # Now, in order to insert data into this stream, we must be logged in as
        # the owning device
        ddb = DatabaseConnection(self.apikey, url=self.db.baseurl)
        d = Device(ddb, self.path)

        # Set up the owning device
        sown = d[s.name]

        # read the stream's info
        sown.insert_array(DatapointArray().loadExport(directory))

        # Now we MIGHT be able to recover the downlink data,
        # only if we are not logged in as the device that the stream is being inserted into
        # So we check. When downlink is true, data is inserted into the
        # downlink stream
        if (sdata["downlink"] and self.db.path != self.path):
            s.downlink = True
            with open(os.path.join(directory, "downlink.json"), "r") as f:
                s.insert_array(json.load(f))

        # And finally, update the device
        del sdata["name"]
        s.set(sdata)
def import_stream ( self , directory ) : # read the stream's info with open ( os . path . join ( directory , "stream.json" ) , "r" ) as f : sdata = json . load ( f ) s = self [ sdata [ "name" ] ] if s . exists ( ) : raise ValueError ( "The stream " + s . name + " already exists" ) # Create the stream empty first, so we can insert all the data without # worrying about schema violations or downlinks s . create ( ) # Now, in order to insert data into this stream, we must be logged in as # the owning device ddb = DatabaseConnection ( self . apikey , url = self . db . baseurl ) d = Device ( ddb , self . path ) # Set up the owning device sown = d [ s . name ] # read the stream's info sown . insert_array ( DatapointArray ( ) . loadExport ( directory ) ) # Now we MIGHT be able to recover the downlink data, # only if we are not logged in as the device that the stream is being inserted into # So we check. When downlink is true, data is inserted into the # downlink stream if ( sdata [ "downlink" ] and self . db . path != self . path ) : s . downlink = True with open ( os . path . join ( directory , "downlink.json" ) , "r" ) as f : s . insert_array ( json . load ( f ) ) # And finally, update the device del sdata [ "name" ] s . set ( sdata )
Imports a stream from the given directory. You export the Stream
        by using stream.export()
Imports a stream from the given directory . You export the Stream by using stream . export ()