Exemple #1
0
def save_customers(path=None, save_meta_info=False):
    """
    Write current customers list on the disk, ``path`` is a file path to save.
    """
    global _CustomersMetaInfo
    if path is None:
        path = settings.CustomerIDsFilename()
    lst = customers()
    lst = list(map(strng.to_text, lst))
    bpio._write_list(path, lst)
    if save_meta_info:
        json_info = id_url.to_bin_dict(_CustomersMetaInfo)
        local_fs.WriteTextFile(
            settings.CustomersMetaInfoFilename(),
            jsn.dumps(
                json_info,
                indent=2,
                sort_keys=True,
                keys_to_text=True,
            ))
    if _Debug:
        lg.out(
            _DebugLevel, 'contactsdb.save_customers save_meta_info=%r : %r' % (
                save_meta_info,
                lst,
            ))
def save_customers(path=None):
    """
    Write current customers list on the disk, ``path`` is a file path to save.
    """
    if path is None:
        path = settings.CustomerIDsFilename()
    bpio._write_list(path, customers())
def load_customers(path=None):
    """
    Load customers list from disk.
    """
    if path is None:
        path = settings.CustomerIDsFilename()
    lst = bpio._read_list(path)
    if lst is None:
        lst = list()
    set_customers(lst)
    lg.out(4, 'contactsdb.load_customers %d items' % len(lst))
Exemple #4
0
def cache_customers(path=None):
    """
    Make sure identities of all customers we know are cached.
    """
    dl = []
    if path is None:
        path = settings.CustomerIDsFilename()
    lst = bpio._read_list(path) or []
    for one_customer_idurl in lst:
        if one_customer_idurl:
            if not id_url.is_cached(one_customer_idurl):
                dl.append(identitycache.immediatelyCaching(one_customer_idurl))
    if _Debug:
        lg.out(_DebugLevel, 'contactsdb.cache_customers prepared %d idurls to be cached' % len(dl))
    return DeferredList(dl, consumeErrors=True)
Exemple #5
0
def load_customers(path=None):
    """
    Load customers list from disk.
    """
    global _CustomersMetaInfo
    if path is None:
        path = settings.CustomerIDsFilename()
    lst = bpio._read_list(path)
    if lst is None:
        lst = list()
    lst = list(map(strng.to_bin, lst))
    set_customers(lst)
    _CustomersMetaInfo = jsn.loads(
        local_fs.ReadTextFile(settings.CustomersMetaInfoFilename()) or '{}')
    lg.out(4, 'contactsdb.load_customers %d items' % len(lst))
Exemple #6
0
def save_customers(path=None, save_meta_info=False):
    """
    Write current customers list on the disk, ``path`` is a file path to save.
    """
    global _CustomersMetaInfo
    if path is None:
        path = settings.CustomerIDsFilename()
    lst = customers()
    lst = list(map(strng.to_text, lst))
    bpio._write_list(path, lst)
    if save_meta_info:
        local_fs.WriteTextFile(settings.CustomersMetaInfoFilename(),
                               jsn.dumps(_CustomersMetaInfo))
    if _Debug:
        lg.out(_DebugLevel, 'contactsdb.save_customers : %r' % lst)
Exemple #7
0
def load_customers(path=None):
    """
    Load customers list from disk.
    """
    global _CustomersMetaInfo
    if path is None:
        path = settings.CustomerIDsFilename()
    lst = bpio._read_list(path)
    if lst is None:
        lst = list()
    lst = list(filter(id_url.is_cached, lst))
    set_customers(lst)
    _CustomersMetaInfo = jsn.loads(
        local_fs.ReadTextFile(settings.CustomersMetaInfoFilename()) or '{}',
        keys_to_bin=True,
    )
    _CustomersMetaInfo = id_url.to_bin_dict(_CustomersMetaInfo)
    _CustomersMetaInfo = jsn.dict_values_to_text(_CustomersMetaInfo)
    if _Debug:
        lg.out(_DebugLevel, 'contactsdb.load_customers %d items' % len(lst))
Exemple #8
0
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())