def save_correspondents(path=None):
    """
    Write current correspondents list on the disk, ``path`` is a file path to
    save.
    """
    if path is None:
        path = settings.CorrespondentIDsFilename()
    bpio._write_list(path, map(lambda t: "%s %s" % t, correspondents()))
Beispiel #2
0
def save_correspondents(path=None):
    """
    Write current correspondents list on the disk, ``path`` is a file path to
    save.
    """
    if path is None:
        path = settings.CorrespondentIDsFilename()
    lst = ["%s %s" % (strng.to_text(t[0]), strng.to_text(t[1]),) for t in correspondents()]
    bpio._write_list(path, lst)
def load_correspondents(path=None):
    """
    Load correspondents list from disk.
    """
    if path is None:
        path = settings.CorrespondentIDsFilename()
    lst = bpio._read_list(path)
    if lst is None:
        lst = list()
    for i in xrange(len(lst)):
        lst[i] = tuple(lst[i].strip().split(' ', 1))
        if len(lst[i]) < 2:
            lst[i] = (lst[i][0], '')
        if lst[i][1].strip() == '':
            lst[i] = (lst[i][0], nameurl.GetName(lst[i][0]))
    set_correspondents(lst)
    lg.out(4, 'contactsdb.load_correspondents %d items' % len(lst))
Beispiel #4
0
def load_correspondents(path=None):
    """
    Load correspondents list from disk.
    """
    if path is None:
        path = settings.CorrespondentIDsFilename()
    lst = bpio._read_list(path)
    if lst is None:
        lst = list()
    for i in range(len(lst)):
        lst[i] = tuple(lst[i].strip().split(' ', 1))
        if len(lst[i]) < 2:
            lst[i] = (lst[i][0], '')
        if not lst[i][1].strip():
            lst[i] = (id_url.field(lst[i][0]), nameurl.GetName(lst[i][0]))
    lst = list(filter(lambda i: id_url.is_cached(i[0]), lst))
    set_correspondents(lst)
    if _Debug:
        lg.out(_DebugLevel, 'contactsdb.load_correspondents %d items' % len(lst))
Beispiel #5
0
def cache_correspondents(path=None):
    """
    Make sure identities of all correspondents we know are cached.
    """
    dl = []
    if path is None:
        path = settings.CorrespondentIDsFilename()
    lst = bpio._read_list(path) or []
    for i in range(len(lst)):
        try:
            one_correspondent_idurl = lst[i].strip().split(' ', 1)[0]
        except:
            lg.exc()
            continue
        if one_correspondent_idurl:
            if not id_url.is_cached(one_correspondent_idurl):
                dl.append(identitycache.immediatelyCaching(one_correspondent_idurl))
    if _Debug:
        lg.out(_DebugLevel, 'contactsdb.cache_correspondents prepared %d idurls to be cached' % len(dl))
    return DeferredList(dl, consumeErrors=True)
Beispiel #6
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())