def load_suppliers(path=None, customer_idurl=None, all_customers=False): """ Load suppliers list from disk. """ if all_customers: for customer_id in os.listdir(settings.SuppliersDir()): if not global_id.IsValidGlobalUser(customer_id): lg.warn('invalid customer record %s found in %s' % (customer_id, settings.SuppliersDir())) continue path = os.path.join(settings.SuppliersDir(), customer_id, 'supplierids') lst = bpio._read_list(path) if lst is None: lst = list() set_suppliers( lst, customer_idurl=global_id.GlobalUserToIDURL(customer_id)) lg.out( 4, 'contactsdb.load_suppliers %d items from %s' % (len(lst), path)) return True if path is None: if customer_idurl is None: path = settings.SupplierIDsFilename() else: path = os.path.join(settings.SuppliersDir(), global_id.UrlToGlobalID(customer_idurl), 'supplierids') lst = bpio._read_list(path) if lst is None: lst = list() set_suppliers(lst) lg.out(4, 'contactsdb.load_suppliers %d items from %s' % (len(lst), path)) return True
def save_suppliers(path=None, customer_idurl=None): """ Write current suppliers list on the disk, ``path`` is a file path to save. """ if path is None: path = settings.SupplierIDsFilename() if customer_idurl is not None: path += ('_%s' % global_id.UrlToGlobalID(customer_idurl)) bpio._write_list(path, suppliers())
def save_suppliers(path=None, customer_idurl=None): """ Write current suppliers list on the disk, ``path`` is a file path to save. """ if path is None: if customer_idurl is None: path = settings.SupplierIDsFilename() else: path = os.path.join( settings.SuppliersDir(), global_id.UrlToGlobalID(customer_idurl), 'supplierids', ) bpio._write_list(path, suppliers(customer_idurl=customer_idurl)) return True
def init(): """ We read from disk and if we have all the info we are set. If we don't have enough, then we have to ask BitDust to list contacts and use that list to get and then store all the identities for our contacts. """ global _SuppliersChangedCallback global _CustomersChangedCallback global _CorrespondentsChangedCallback lg.out(4, "contactsdb.init") load_suppliers(settings.SupplierIDsFilename()) if _SuppliersChangedCallback is not None: _SuppliersChangedCallback([], suppliers()) load_customers(settings.CustomerIDsFilename()) if _CustomersChangedCallback is not None: _CustomersChangedCallback([], customers()) load_correspondents(settings.CorrespondentIDsFilename()) if _CorrespondentsChangedCallback is not None: _CorrespondentsChangedCallback([], correspondents())