def renewAlephRecords(wfStateInfo): logger.info("renewAlephRecords") print "renew Aleph Records" originalfile = wfStateInfo.object with api.env.adopt_user(username="******"): if isbn_validator.is_valid_isbn(originalfile.isbn): getAdapter(originalfile, IAMQPSender, name="renew-aleph-records").send() getAdapter(originalfile, IAMQPSender, name="renew-aleph-records-by-sysnumber").send() getAdapter(originalfile, IAMQPSender, name="renew-aleph-records-by-icz-sysnumber").send()
def _isbn_pairing(items): """ Pair `items` with same ISBN into `DataPair` objects. Args: items (list): list of items, which will be searched. Returns: list: list with paired items. Paired items are removed, `DataPair` is \ added instead. """ NameWrapper = namedtuple("NameWrapper", ["name", "obj"]) metas = map( lambda x: NameWrapper(_just_name(x.filename), x), filter(lambda x: isinstance(x, MetadataFile), items) ) ebooks = map( lambda x: NameWrapper(_just_name(x.filename), x), filter(lambda x: isinstance(x, EbookFile), items) ) # simple pairing mechanism, which shouldn't be O^2 complex, but something # slightly better metas = sorted(metas, key=lambda x: x.name) ebooks = sorted(ebooks, key=lambda x: x.name, reverse=True) while metas: meta = metas.pop() if not isbn_validator.is_valid_isbn(meta.name): continue if not ebooks: break ebook_index = _index(ebooks, meta.name, key=lambda x: x.name) if ebook_index >= 0: logger.debug( "Pairing '%s' and '%s'." % ( meta.obj.filename, ebooks[ebook_index].obj.filename ) ) items.append( DataPair( metadata_file=meta.obj, ebook_file=ebooks[ebook_index].obj ) ) items.remove(meta.obj) items.remove(ebooks[ebook_index].obj) ebooks = ebooks[ebook_index+1:] return items
def changesFromAlephRecord(self,record): changes = [] if record.isbn != self.context.isbn and isbn_validator.is_valid_isbn(record.isbn): changes.append(ObjSetterApply(self.context, 'isbn', record.isbn)) if record.nazev != self.epublication.title: changes.append(ObjSetterApply(self.epublication, 'title', record.nazev)) if record.podnazev != self.epublication.podnazev: changes.append(ObjSetterApply(self.epublication, 'podnazev', record.podnazev)) if record.nazev_casti != self.epublication.nazev_casti: changes.append(ObjSetterApply(self.epublication, 'nazev_casti', record.nazev_casti)) if record.rok_vydani != self.epublication.rok_vydani: changes.append(ObjSetterApply(self.epublication, 'rok_vydani', record.rok_vydani)) return changes
def get_epublication(self): """ Returns: EPublication: Structure when the object :meth:`is_valid`. Raises: MetaParsingException: When the object is not valid. """ if not self.is_valid(): bad_fields = filter(lambda x: not x.is_valid(), self.fields) bad_fields = map( lambda x: "Keyword '%s' (%s) not found." % (x.keyword, x.descr), bad_fields ) raise MetaParsingException( "Missing field(s):\n\t" + "\n\t".join(bad_fields) ) relevant_fields = self.fields relevant_fields += filter(lambda x: x.is_valid(), self.optional) epub_dict = dict(map(lambda x: (x.epub, x.value), relevant_fields)) # make sure, that all fields present in EPublication has values also # in epub_dict for epublication_part in EPublication._fields: if epublication_part not in epub_dict: epub_dict[epublication_part] = None if not is_valid_isbn(epub_dict["ISBN"]): raise MetaParsingException( "ISBN '%s' is not valid!" % epub_dict["ISBN"] ) return EPublication(**epub_dict)
def is_valid_isbn(isbn): return isbn_validator.is_valid_isbn(isbn)
def test_is_valid_isbn(): assert isbn_validator.is_valid_isbn("80-85892-15-4") assert isbn_validator.is_valid_isbn("80-86056-31-7") assert isbn_validator.is_valid_isbn("80-251-0225-4") assert isbn_validator.is_valid_isbn("978-80-86056-31-9") assert isbn_validator.is_valid_isbn("978-80-904248-2-1") assert not isbn_validator.is_valid_isbn("978-80-86056-31-5") assert not isbn_validator.is_valid_isbn("978-80-904248-2-7") assert not isbn_validator.is_valid_isbn("978-80-934248-2-7") assert not isbn_validator.is_valid_isbn("978-80-9345644248-2-7") assert not isbn_validator.is_valid_isbn("978-80-9") assert not isbn_validator.is_valid_isbn("80-251-0225-x") assert not isbn_validator.is_valid_isbn("80-85892-25-4") assert not isbn_validator.is_valid_isbn("80-85892-25-416456") assert not isbn_validator.is_valid_isbn("80-8589")