def writeSupplierData(supplier_idurl, filename, data, customer_idurl): """ Writes to a config file for given supplier. """ dirPath = settings.SupplierPath(supplier_idurl, customer_idurl) if not os.path.isdir(dirPath): os.makedirs(dirPath) path = settings.SupplierPath(supplier_idurl, customer_idurl, filename) return bpio.WriteTextFile(path, data)
def state_changed(self, oldstate, newstate, event, *args, **kwargs): """ This method intended to catch the moment when automat's state were changed. """ if newstate in ['CONNECTED', 'DISCONNECTED', 'NO_SERVICE']: supplierPath = settings.SupplierPath( self.supplier_idurl, customer_idurl=self.customer_idurl) if not os.path.isdir(supplierPath): try: os.makedirs(supplierPath) except: lg.exc() return bpio.WriteTextFile( settings.SupplierServiceFilename( self.supplier_idurl, customer_idurl=self.customer_idurl), newstate, ) if newstate == 'CONNECTED': if not self._supplier_connected_event_sent: self._supplier_connected_event_sent = True events.send('supplier-connected', data=dict( supplier_idurl=self.supplier_idurl, customer_idurl=self.customer_idurl, needed_bytes=self.needed_bytes, key_id=self.key_id, )) if newstate in [ 'DISCONNECTED', 'NO_SERVICE', ]: self._supplier_connected_event_sent = False
def readSupplierData(supplier_idurl, filename, customer_idurl): """ Read a file from [BitDust data dir]/suppliers/[IDURL] folder. The file names right now is ['connected', 'disconnected', 'listfiles']. """ path = settings.SupplierPath(supplier_idurl, customer_idurl, filename) if not os.path.isfile(path): return '' return bpio.ReadTextFile(path).strip()
def state_changed(self, oldstate, newstate, event, *args, **kwargs): """ This method intended to catch the moment when automat's state were changed. """ if newstate in ['CONNECTED', 'DISCONNECTED', 'NO_SERVICE']: supplierPath = settings.SupplierPath(self.supplier_idurl, customer_idurl=self.customer_idurl) if not os.path.isdir(supplierPath): try: os.makedirs(supplierPath) except: lg.exc() return bpio.WriteTextFile( settings.SupplierServiceFilename(self.supplier_idurl, customer_idurl=self.customer_idurl), newstate, )