Пример #1
0
def _add_item(x_items,
              action,
              item_type,
              key='NONE',
              text=None,
              priority=600,
              sequence=0,
              url=None,
              body=None,
              **kwargs):
    item = qxml.add_child(x_items, 'item')
    item.setAttribute('action', str(action))
    item.setAttribute('is_incremental', 'false')
    item.setAttribute('key', str(key))
    item.setAttribute('priority', str(priority))
    item.setAttribute('sequence', str(sequence))
    item.setAttribute('type', str(item_type))
    if url:
        item.setAttribute('url', url)
    if body:
        qxml.set_text(item, body)
    else:
        for k, v in kwargs.items():
            qxml.add_child(item, k, str(v))
    return item
Пример #2
0
def _process_xml(request, doc, device):
    x_response = qxml.get_child(doc, 'response')
    x_items = qxml.get_child(x_response, 'items')
    if not x_items:
        return False

    was_updated = False

    # rewrite urls
    for x_item in qxml.list_children(x_items, 'item'):
        was_updated |= _filter_item(request, x_items, x_item)

    was_updated |= _consume_action_queue(request, device, x_items)
    was_updated |= _update_annotations(device, x_items)

    if features.download_updated_books:
        for book in calibre.books().values():
            if book.needs_update_on(device) and book.cde_content_type in (
                    'EBOK', ):  # PDOC updates are not supported ATM
                logging.warn(
                    "book %s updated in library, telling device %s to download it again",
                    book, device)
                _add_item(x_items,
                          'GET',
                          book.cde_content_type,
                          key=book.asin,
                          title=book.title,
                          forced=True)
                was_updated = True

    if was_updated:
        x_total_count = qxml.get_child(x_response, 'total_count')
        qxml.set_text(x_total_count, len(x_items.childNodes))

    return was_updated
Пример #3
0
def _process_xml(doc, device, reason):
	x_response = qxml.get_child(doc, 'response')
	x_items = qxml.get_child(x_response, 'items')
	if not x_items:
		return False

	was_updated = False

	# rewrite urls
	for x_item in qxml.list_children(x_items, 'item'):
		was_updated |= _filter_item(x_items, x_item)

	was_updated |= _consume_action_queue(device, x_items)
	was_updated |= _update_annotations(device, x_items)

	if features.download_updated_books:
		for book in calibre.books().values():
			if book.needs_update_on(device) and book.cde_content_type in ('EBOK', ): # PDOC updates are not supported ATM
				logging.warn("book %s updated in library, telling device %s to download it again", book, device)
				_add_item(x_items, 'GET', book.cde_content_type, key = book.asin, title = book.title, forced = True)
				was_updated = True

	if was_updated:
		x_total_count = qxml.get_child(x_response, 'total_count')
		qxml.set_text(x_total_count, len(x_items.childNodes))

	return was_updated
Пример #4
0
def _add_item(x_items, action, item_type, key = 'NONE', text = None, priority = 600, sequence = 0, url = None, body = None, **kwargs):
	item = qxml.add_child(x_items, 'item')
	item.setAttribute('action', str(action))
	item.setAttribute('is_incremental', 'false')
	item.setAttribute('key', str(key))
	item.setAttribute('priority', str(priority))
	item.setAttribute('sequence', str(sequence))
	item.setAttribute('type', str(item_type))
	if url:
		item.setAttribute('url', url)
	if body:
		qxml.set_text(item, body)
	else:
		for k, v in kwargs.items():
			qxml.add_child(item, k, str(v))
	return item
Пример #5
0
def _process_xml(doc, device, reason):
	x_response = qxml.get_child(doc, 'response')
	x_items = qxml.get_child(x_response, 'items')
	if not x_items:
		return False

	was_updated = False

	# rewrite urls
	for x_item in qxml.list_children(x_items, 'item'):
		was_updated |= _filter_item(x_items, x_item)

	if features.download_updated_books:
		for book in calibre.books().values():
			if book.needs_update_on(device) and book.cde_content_type in ('EBOK', ): # PDOC updates are not supported ATM
				logging.warn("book %s updated in library, telling device %s to download it again", book, device)
				# <item action="GET" is_incremental="false" key="asin" priority="600" sequence="0" type="EBOK">title</item>
				_add_item(x_items, 'GET', book.cde_content_type, key = book.asin, text = book.title, forced = True) # book.title)
				was_updated = True

	while device.actions_queue:
		action = device.actions_queue.pop()
		# logging.debug("checking action %s", action)
		if list(qxml.filter(x_items, 'item', action = action[0], type = action[1])):
			# logging.debug("action %s already found in %s, skipping", action, x_items)
			continue
		if action == ('SET', 'SCFG'):
			_add_item(x_items, 'SET', 'SCFG', text = _servers_config(device), key = 'KSP.set.scfg', priority = 100)
			was_updated = True
		elif action == ('UPLOAD', 'SNAP'):
			_add_item(x_items, 'UPLOAD', 'SNAP', key = 'KSP.upload.snap', priority = 1000, url = config.server_url + 'FionaCDEServiceEngine/UploadSnapshot')
			was_updated = True
		# elif action == ('GET', 'NAMS'):
		# 	_add_item(x_items, 'GET', 'NAMS', key = 'NameChange' if device.is_kindle() else 'AliasChange')
		# 	was_updated = True
		elif action == ('UPLOAD', 'SCFG'):
			_add_item(x_items, 'UPLOAD', 'SCFG', key = 'KSP.upload.scfg', priority = 50, url = config.server_url + 'ksp/scfg')
			was_updated = True
		else:
			logging.warn("unknown action %s", action)

	if was_updated:
		x_total_count = qxml.get_child(x_response, 'total_count')
		qxml.set_text(x_total_count, len(x_items.childNodes))

	return was_updated
Пример #6
0
def _add_item(x_items, action, item_type, key = 'NONE', text = None, priority = 600, url = None, forced = False):
	item = qxml.add_child(x_items, 'item')
	item.setAttribute('action', str(action))
	item.setAttribute('is_incremental', 'false')
	item.setAttribute('key', str(key))
	item.setAttribute('priority', str(priority))
	item.setAttribute('sequence', '0')
	item.setAttribute('type', str(item_type))
	if url:
		item.setAttribute('url', url)
	if text:
		if forced:
			qxml.add_child(item, 'title', text)
			qxml.add_child(item, 'forced', 'true')
		else:
			qxml.set_text(item, text)
	return item