コード例 #1
0
ファイル: __init__.py プロジェクト: akleiw/KSP
				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

def save_all():
	_db.update_all(_devices.values())


### module initialization
_devices = { d.serial: d for d in _db.load_all() }
コード例 #2
0
ファイル: __init__.py プロジェクト: MSylvia/KSP
def _check_for_changes():
	if _db.needs_reload():
		logging.warn("Devices database changed on-disk, reloading")
		global _devices
		_devices = { d.serial: d for d in _db.load_all() }
コード例 #3
0
ファイル: device-manager.py プロジェクト: nomada2/KSP
if __name__ == '__main__':
    logging.basicConfig(format="%(levelname)-8s %(message)s", level='INFO')
    logging.getLogger()
    logging.captureWarnings(True)

    args = _args()
    sys.path.append(abspath(args.etc_path))

    import config
    config.database_path = abspath(args.db_path)

    # add the src/ folder to the import path
    sys.path.append(abspath('src'))
    import devices.db as _db

    devices = {d.serial: d for d in _db.load_all()}

    if args.device_id:
        d = devices.get(args.device_id)
        if not d:
            for k, v in devices.items():
                if k.startswith(args.device_id):
                    d = v
                    break
    else:
        d = None

    if args.device_id and not d:
        logging.warn("Device %s not found", args.device_id)
    elif args.delete:
        if not args.device_id:
コード例 #4
0
def _check_for_changes():
    if _db.needs_reload():
        logging.warn("Devices database changed on-disk, reloading")
        global _devices
        _devices = {d.serial: d for d in _db.load_all()}