def constructFilename(customerID, packetID): customerDirName = nameurl.UrlFilename(customerID) customersDir = settings.getCustomersFilesDir() if not os.path.exists(customersDir): bpio._dir_make(customersDir) ownerDir = os.path.join(customersDir, customerDirName) if not os.path.exists(ownerDir): bpio._dir_make(ownerDir) filename = os.path.join(ownerDir, packetID) return filename
def init(): """ Need to call before all other methods. Check to exist and create a folder to keep all cached identities. """ lg.out(4, "identitydb.init") iddir = settings.IdentityCacheDir() if not os.path.exists(iddir): lg.out(8, 'identitydb.init create folder ' + iddir) bpio._dir_make(iddir)
def init(): """ Need to call before all other methods. Check to exist and create a folder to keep all cached identities. """ lg.out(4, "identitydb.init") id_cache_dir = settings.IdentityCacheDir() if not os.path.exists(id_cache_dir): lg.out(8, 'identitydb.init create folder %r' % id_cache_dir) bpio._dir_make(id_cache_dir) # make sure to read and cache all known identities at startup for id_filename in os.listdir(id_cache_dir): idurl = nameurl.FilenameUrl(id_filename) get_ident(idurl)
def constructFilename(customerIDURL, packetID): customerGlobID, packetID = packetid.SplitPacketID(packetID) if customerGlobID: customerIDURL_packet = global_id.GlobalUserToIDURL(customerGlobID) if customerIDURL_packet != customerIDURL: lg.warn('construct filename for another customer: %s != %s' % (customerIDURL_packet, customerIDURL)) customerDirName = nameurl.UrlFilename(customerIDURL) customersDir = settings.getCustomersFilesDir() if not os.path.exists(customersDir): bpio._dir_make(customersDir) ownerDir = os.path.join(customersDir, customerDirName) if not os.path.exists(ownerDir): bpio._dir_make(ownerDir) filename = os.path.join(ownerDir, packetID) return filename
def make_filename(customerGlobID, packetID, keyAlias=None): keyAlias = keyAlias or 'master' customerDirName = str(customerGlobID) customersDir = settings.getCustomersFilesDir() if not os.path.exists(customersDir): if _Debug: lg.dbg(_DebugLevel, 'making a new folder: %s' % customersDir) bpio._dir_make(customersDir) ownerDir = os.path.join(customersDir, customerDirName) if not os.path.exists(ownerDir): if _Debug: lg.dbg(_DebugLevel, 'making a new folder: %s' % ownerDir) bpio._dir_make(ownerDir) keyAliasDir = os.path.join(ownerDir, keyAlias) if not os.path.exists(keyAliasDir): if _Debug: lg.dbg(_DebugLevel, 'making a new folder: %s' % keyAliasDir) bpio._dir_make(keyAliasDir) filename = os.path.join(keyAliasDir, packetID) return filename
def _do_construct_filename(self, customerGlobID, packetID, keyAlias=None): import os from logs import lg from main import settings from system import bpio keyAlias = keyAlias or 'master' customerDirName = str(customerGlobID) customersDir = settings.getCustomersFilesDir() if not os.path.exists(customersDir): lg.info('making a new folder: ' + customersDir) bpio._dir_make(customersDir) ownerDir = os.path.join(customersDir, customerDirName) if not os.path.exists(ownerDir): lg.info('making a new folder: ' + ownerDir) bpio._dir_make(ownerDir) keyAliasDir = os.path.join(ownerDir, keyAlias) if not os.path.exists(keyAliasDir): lg.info('making a new folder: ' + keyAliasDir) bpio._dir_make(keyAliasDir) filename = os.path.join(keyAliasDir, packetID) return filename
def init(): """ """ global _IdentityHistoryDir global _KnownUsers global _KnownIDURLs global _MergedIDURLs global _Ready from userid import identity if _Debug: lg.out(_DebugLevel, "id_url.init") if not _IdentityHistoryDir: _IdentityHistoryDir = settings.IdentityHistoryDir() if not os.path.exists(_IdentityHistoryDir): bpio._dir_make(_IdentityHistoryDir) lg.info('created new folder %r' % _IdentityHistoryDir) else: lg.info('using existing folder %r' % _IdentityHistoryDir) for one_user_dir in os.listdir(_IdentityHistoryDir): one_user_dir_path = os.path.join(_IdentityHistoryDir, one_user_dir) one_user_identity_files = [] for one_filename in os.listdir(one_user_dir_path): try: one_ident_number = int(one_filename) except: lg.exc() continue one_user_identity_files.append(one_ident_number) if _Debug: lg.out(_DebugLevel, 'id_url.init found %d historical records in %r' % (len(one_user_identity_files), one_user_dir_path, )) for one_ident_file in one_user_identity_files: one_ident_path = os.path.join(one_user_dir_path, strng.to_text(one_ident_file)) try: xmlsrc = local_fs.ReadTextFile(one_ident_path) known_id_obj = identity.identity(xmlsrc=xmlsrc) if not known_id_obj.isCorrect(): raise Exception('identity history in %r is broken, identity is not correct: %r' % ( one_user_dir, one_ident_path)) if not known_id_obj.Valid(): raise Exception('identity history in %r is broken, identity is not valid: %r' % ( one_user_dir, one_ident_path)) except: lg.exc() continue one_pub_key = known_id_obj.getPublicKey() one_revision = known_id_obj.getRevisionValue() if one_pub_key not in _KnownUsers: _KnownUsers[one_pub_key] = one_user_dir_path known_sources = known_id_obj.getSources(as_originals=True) for known_idurl in reversed(known_sources): if known_idurl not in _KnownIDURLs: _KnownIDURLs[known_idurl] = known_id_obj.getPublicKey() if _Debug: lg.out(_DebugLevel, ' new IDURL added: %r' % known_idurl) else: if _KnownIDURLs[known_idurl] != known_id_obj.getPublicKey(): _KnownIDURLs[known_idurl] = known_id_obj.getPublicKey() lg.warn('another user had same identity source: %r' % known_idurl) if one_pub_key not in _MergedIDURLs: _MergedIDURLs[one_pub_key] = {} if _Debug: lg.out(_DebugLevel, ' new Public Key added: %s...' % one_pub_key[-10:]) if one_revision in _MergedIDURLs[one_pub_key]: if _MergedIDURLs[one_pub_key][one_revision] != known_idurl: if _MergedIDURLs[one_pub_key][one_revision] not in known_sources: lg.warn('rewriting existing identity revision %d : %r -> %r' % ( one_revision, _MergedIDURLs[one_pub_key][one_revision], known_idurl)) _MergedIDURLs[one_pub_key][one_revision] = known_idurl else: _MergedIDURLs[one_pub_key][one_revision] = known_idurl if _Debug: lg.out(_DebugLevel, ' revision %d merged with other %d known items' % ( one_revision, len(_MergedIDURLs[one_pub_key]))) _Ready = True
def make_rating_dir(idurl): bpio._dir_make(rating_dir(idurl))