Пример #1
0
def load_all():
    with sqlite3(_db_path) as db:
        db.row_factory = sqlite3_Row
        for row in db.execute('SELECT * FROM devices'):
            row = dict(row)
            yield _Device(**row)
    global _last_changed
    _last_changed = os.path.getmtime(_db_path)
Пример #2
0
Файл: db.py Проект: MSylvia/KSP
def load_all():
	with sqlite3(_db_path) as db:
		db.row_factory = sqlite3_Row
		for row in db.execute('SELECT * FROM devices'):
			row = dict(row)
			yield _Device(**row)
	global _last_changed
	_last_changed = os.path.getmtime(_db_path)
Пример #3
0
def detect(ip, cookie=None, kind=None, serial=None):
    """
	guess the device that made a request
	if no matching device exists in our database, one may be created on the spot
	"""
    _check_for_changes()
    found = _devices.get(serial) if serial else None
    if not found:
        for d in _devices.values():
            # logging.debug("matching '%s' vs '%s'", cookie, d.last_cookie)
            if cookie and d.last_cookie:
                if cookie[:64] == d.last_cookie:
                    found = d
                    break
                continue
            if kind and d.kind:
                if kind.partition('-')[0] != d.kind.partition('-')[0]:
                    continue
            if ip == d.last_ip:
                # very flimsy, especially when the request is port-forwarded through a router
                logging.warn("matched device by ip: %s => %s", ip, d)
                found = d
                break

    if found:
        _update(found, ip=ip, cookie=cookie, kind=kind)
        return found

    # create new device, may be provisional
    device = _Device(serial=serial,
                     kind=kind,
                     last_ip=ip,
                     last_cookie=cookie[:64] if cookie else None)
    if device.is_provisional():
        if not serial or not device.load_context(serial):
            return device
    logging.warn("registered Kindle device %s", device)
    _devices[device.serial] = device
    _db.insert(device)
    return device
Пример #4
0
def detect(ip, cookie = None, kind = None, serial = None):
	"""
	guess the device that made a request
	if no matching device exists in our database, one may be created on the spot
	"""
	_check_for_changes()
	found = _devices.get(serial) if serial else None
	if not found:
		for d in _devices.values():
			# logging.debug("matching '%s' vs '%s'", cookie, d.last_cookie)
			if cookie and d.last_cookie:
				if cookie[:64] == d.last_cookie:
					found = d
					break
				continue
			if kind and d.kind:
				if kind.partition('-')[0] != d.kind.partition('-')[0]:
					continue
			if ip == d.last_ip:
				# very flimsy, especially when the request is port-forwarded through a router
				logging.warn("matched device by ip: %s => %s", ip, d)
				found = d
				break

	if found:
		_update(found, ip = ip, cookie = cookie, kind = kind)
		return found

	# create new device, may be provisional
	device = _Device(serial = serial, kind = kind, last_ip = ip, last_cookie = cookie[:64] if cookie else None)
	if device.is_provisional():
		if not serial or not device.load_context(serial):
			return device
	logging.warn("registered Kindle device %s", device)
	_devices[device.serial] = device
	_db.insert(device)
	return device
Пример #5
0
Файл: db.py Проект: akleiw/KSP
def load_all():
	with sqlite3(_db_path) as db:
		db.row_factory = sqlite3_Row
		for row in db.execute('SELECT * FROM devices'):
			row = dict(row)
			yield _Device(**row)