Beispiel #1
0
 def session_key(self):
     "Returns a session key that can later be passed to from_session_key() to retrieve this user."
     key = common.random_hex_string()
     mutex = common.mutex("sessions.lock")
     mutex.get()
     sessions = shelve.open(sessions_file)
     sessions[key] = self.username
     sessions.close()
     mutex.drop()
     return key
Beispiel #2
0
    def save(self, must_not_exist=0):
        mutex = common.mutex("users.lock")
        mutex.get()
        store = shelve.open(users_file)

        if must_not_exist and store.has_key(self.username):
            store.close()
            raise AlreadyExistsException()

        store[self.username] = self
        store.close()
        mutex.drop()
Beispiel #3
0
def get(name, collater, connection):
	mutex = common.mutex('metadata.lock')
	mutex.get()

	meta = shelve.open(metadata_file)

        if meta.has_key(name):
            current = meta[name]
        else:
            current = metadata()

        current.consider(collater, connection)

        meta[name] = current
        meta.close()
        mutex.drop()

        return current
Beispiel #4
0
def index(name, rgtp_server):
	"""Returns an index for the RGTP server |name| (where
	|rgtp_server| is an object representing that server).
	If possible, uses and updates the cache on backing store."""
	
	mutex = common.mutex('indexes.lock')

	mutex.get()
	indexes = shelve.open(indexes_file)

	current = None

	if indexes.has_key(name):
		# AND the datestamp is recent
		try:
			current = indexes[name]

			if current.version<2:
				# too old
				# FIXME: we should get the version to check against
				# from the rgtp module, not hard-code it.
				current = None
			else:
				current.eat(rgtp_server.index(current.sequences()['all']+1))
		except:
			# didn't work; just reload
			current = None

	if not current:
		current = rgtp.interpreted_index()
		current.eat(rgtp_server.index())

	indexes[name] = current
	indexes.close()
	mutex.drop()

	return current