Ejemplo n.º 1
0
    def do_run(self, _db=None, cmd_args=None, output=sys.stdout):
        _db = _db or self._db
        args = self.parse_command_line(self._db, cmd_args=cmd_args)

        default_library = Library.default(_db)
        adobe_integration = ExternalIntegration.lookup(
            _db, ExternalIntegration.ADOBE_VENDOR_ID,
            ExternalIntegration.DRM_GOAL, library=default_library
        )
        if not adobe_integration:
            output.write(
                "Could not find an Adobe Vendor ID integration for default library %s.\n" %
                default_library.short_name
            )
            return

        setting = adobe_integration.setting(
            AuthdataUtility.OTHER_LIBRARIES_KEY
        )
        other_libraries = setting.json_value

        chosen_website = args.website_url
        if not chosen_website:
            for website in other_libraries.keys():
                self.explain(output, other_libraries, website)
            return

        if (not args.short_name and not args.secret):
            self.explain(output, other_libraries, chosen_website)
            return

        if not args.short_name or not args.secret:
            output.write("To configure a library you must provide both --short_name and --secret.\n")
            return

        # All three arguments are specified. Set or modify the library's
        # SCT configuration.
        if chosen_website in other_libraries:
            what = "change"
        else:
            what = "set"
        output.write(
            "About to %s the Short Client Token configuration for %s.\n" % (
                what, chosen_website
            )
        )
        if chosen_website in other_libraries:
            output.write("Old configuration:\n")
            short_name, secret = other_libraries[chosen_website]
            self.explain(output, other_libraries, chosen_website)
        other_libraries[chosen_website] = [args.short_name, args.secret]
        
        output.write("New configuration:\n")
        self.explain(output, other_libraries, chosen_website)
        setting.value = json.dumps(other_libraries)
        self._db.commit()
Ejemplo n.º 2
0
    def library_for_request(self, library_short_name):
        """Look up the library the user is trying to access.

        Since this is called on pretty much every request, it's also
        an appropriate time to check whether the site configuration
        has been changed and needs to be updated.
        """
        self.manager.reload_settings_if_changed()

        if library_short_name:
            library = Library.lookup(self._db, short_name=library_short_name)
        else:
            library = Library.default(self._db)

        if not library:
            return LIBRARY_NOT_FOUND
        flask.request.library = library
        return library
Ejemplo n.º 3
0
    def items_that_need_coverage(self, identifiers=None, **kwargs):
        qu = super(BibblioCoverageProvider, self).items_that_need_coverage(
                identifiers=identifiers, **kwargs)

        data_sources = [DataSource.lookup(self._db, ds)
                        for ds in self.INSTANT_CLASSICS_SOURCES]

        # Get any identifiers with uncovered editions in the targeted
        # CustomList and an associated Work to be recommended.
        edition_entry = aliased(CustomListEntry)
        edition_list = aliased(CustomList)
        qu = qu.join(Work.presentation_edition)\
                .outerjoin(Work.custom_list_entries)\
                .outerjoin(CustomListEntry.customlist)\
                .outerjoin(edition_entry, Edition.custom_list_entries)\
                .outerjoin(edition_list, edition_entry.customlist)\
                .join(Work.license_pools)\
                .filter(
                    or_(
                        CustomList.id==self.custom_list.id,
                        edition_list.id==self.custom_list.id
                    )
                )\
                .options(eagerload(Work.presentation_edition)).distinct()

        library = Library.default(self._db)
        qu = library.restrict_to_ready_deliverable_works(qu, Work)
        qu = qu.filter(LicensePool.superceded==False)

        if not self.fiction:
            # Only get nonfiction. This is the default setting.
            qu = qu.filter(Work.fiction==False)
        else:
            qu = qu.filter(or_(Work.fiction==True, Work.fiction==None))

        if self.languages:
            # We only want a particular language.
            qu = qu.filter(Edition.language.in_(self.languages))

        return qu
        OPDSImportScript(importer_class, data_source_name, _db=_db)

    # Create a StandardEbooks Collection.
    OPDSImportScript(object(), DataSource.STANDARD_EBOOKS, _db=_db,
        collection_data=dict(url=u'https://standardebooks.org/opds/all'))

    # Create a Gutenberg Collection.
    gutenberg, is_new = Collection.by_name_and_protocol(
        _db, DataSource.GUTENBERG, ExternalIntegration.GUTENBERG
    )
    if not gutenberg.data_source:
        gutenberg.external_integration.set_setting(
            Collection.DATA_SOURCE_NAME_SETTING, DataSource.GUTENBERG
        )
    if is_new:
        library = Library.default(_db)
        gutenberg.libraries.append(library)
        logging.info('CREATED Collection for %s: %r' % (
            DataSource.GUTENBERG, gutenberg))

    _db.commit()

    # Alright, all the Collections have been created. Let's update the
    # LicensePools now.
    base_query = _db.query(LicensePool).filter(LicensePool.collection_id==None)

    single_collection_sources = [
        DataSource.PLYMPTON, DataSource.ELIB, DataSource.UNGLUE_IT,
        DataSource.STANDARD_EBOOKS, DataSource.GUTENBERG
    ]
    for data_source_name in single_collection_sources:
    for provider in auth_conf.get('providers'):
        integration = make_patron_auth_integration(_db, provider)
        module = provider.get('module')
        if module == 'api.millenium_patron':
            convert_millenium(_db, integration, provider)
        elif module == 'api.firstbook':
            convert_firstbook(_db, integration, provider)
        elif module == 'api.clever':
            convert_clever(_db, integration, provider)
        elif module == 'api.sip':
            convert_sip(_db, integration, provider)
        else:
            log.warn(
                "I don't know how to convert a provider of type %s. Conversion is probably incomplete."
                % module)
        integrations.append(integration)

    # Add each integration to each library.
    library = Library.default(_db)
    for library in _db.query(Library):
        for integration in integrations:
            if integration not in library.integrations:
                library.integrations.append(integration)

    print "Sitewide bearer token signing secret: %s" % secret_setting.value
    for library in _db.query(Library):
        print "\n".join(library.explain(include_secrets=True))
finally:
    _db.commit()
    _db.close()