Esempio n. 1
0
 def set_app_operator(self, user):
     config = get_metadata(SCANCENTER_METADATA_DIR)
     config['operator'] = user
     set_metadata(config, SCANCENTER_METADATA_DIR)
     self._config = get_metadata(SCANCENTER_METADATA_DIR)
     runtime_config = Scribe3Configuration()
     runtime_config.set('operator', user)
Esempio n. 2
0
 def create_initial_metaxml(self):
     '''
     Create initial metadata.xml file when book is created newly and not exist metadata.xml file.
         <collection>booksgrouptest</collection>
         <contributor>Internet Archive</contributor>
         <sponsor>Internet Archive</sponsor>
     
     '''
     trial_md = {
         'collection': 'booksgrouptest',
         'contributor': 'Internet Archive',
         'sponsor': 'Internet Archive'
     }
     set_metadata(trial_md, self.path)
Esempio n. 3
0
 def on_book_notes_submit(self, popup, notes):
     metadata = get_metadata(self.book['path'])
     metadata_notes = metadata.get('notes', None) or ''
     notes = notes.strip()
     if metadata_notes != notes:
         if notes:
             metadata['notes'] = notes
             message = 'Saved public book notes: %s' \
                       % ('\n%s' % notes if '\n' in notes else notes)
         else:
             metadata.pop('notes', None)
             message = 'Removed public book notes'
         set_metadata(metadata, self.book['path'])
         Logger.info('ReScribeScreen: %s' % message)
         self.book_obj.reload_metadata()
Esempio n. 4
0
 def initialze_metaxml(self):
     '''
     The typical MD write path goes through the MD panel,
     which is responsible for performing all the various checks on values prior to dumping to xml.
     This is deliberate, so that the MD panel is the effective chokepoint for all MD edits.
     This object family mostly operates as a lightweigh read-only wrapper. Whenever the metadata is updated
     a call to reload_metadata() is issued. However, in some cases (like in extensions) we may want to offer
     the ability to create a metadata.xml without jumping through more hoops. This is what this function is for.
     '''
     current_md = get_metadata(self.path)
     if current_md:
         raise Exception('Metadata has already been initialized')
     md = {}
     for key in self.MINIMAL_METADATA_MANIFEST:
         md[key] = getattr(self, key)
     set_metadata(md, self.path)
     self.reload_metadata()
Esempio n. 5
0
def _generate_metasource(book, Logger):
    # Upload a metasource.xml
    metasource_file_location = ''
    metasource = get_metadata(book['path'], 'metasource.xml')
    # if there is a metasource file present, add upload-time fields
    if metasource != {}:
        metasource['textid'] = book['identifier']
        metasource['userid'] = _get_email()
        metasource['date'] = datetime.now().strftime('%Y%m%d%H%M%S')
        set_metadata(metasource, book['path'], 'metasource.xml', 'metasource')
        metasource_file_location = join(book['path'], 'metasource.xml')
        metasource_file_upload_name = \
            book['identifier'] + '_metasource.xml'
        Logger.debug(
            'Written metasource file at {}'.format(metasource_file_location))
        return metasource_file_location, metasource_file_upload_name
    else:
        return None, None
Esempio n. 6
0
 def save_metadata(self):
     path = self.book_path
     new_book = not exists(path)
     if self._metadata and path:
         ensure_book_directory(path)
         if 'user_identifier' in self._metadata:
             self._set_identifier(self._metadata['user_identifier'])
             del (self._metadata['user_identifier'])
         if 'ppi' in self._metadata:
             self.set_ppi(self._metadata['ppi'])
             del (self._metadata['ppi'])
         if self.book_obj.is_preloaded():
             if 'collection' in self._metadata:
                 del (self._metadata['collection'])
             if 'collection_set' in self._metadata:
                 del (self._metadata['collection_set'])
         set_metadata(self._metadata, path)
         self.dispatch(self.EVENT_METADATA_SAVED)
Esempio n. 7
0
 def save_metadata(self):
     # Get the metadata from the default location
     # TODO: Try catch, dependency on figuring out what the best course of
     # action would be
     config = get_metadata(scribe_globals.SCANCENTER_METADATA_DIR)
     config.pop('collection', None)
     # Make a copy of it
     new_config = copy.deepcopy(config)
     # For each of them, get the value in the textbox and assign it to the
     # new copy of the dict
     for widget in self.ids['_metadata'].children:
         if isinstance(
                 widget,
             (MetadataTextInput, EmailTextInput, ScannerTextInput)):
             val = self.get_val(widget)
             new_config[widget.metadata_key] = val
     Logger.debug(
         'MetadataScreen: Read from widget: {0}'.format(new_config))
     # If the two dicts are different, set the new one as default
     if config != new_config:
         set_metadata(new_config, scribe_globals.SCANCENTER_METADATA_DIR)
Esempio n. 8
0
 def _write_metdata(self):
     self.dispatch_progress('Saving metadata')
     set_metadata(self.metadata, self.book.path)
Esempio n. 9
0
    def _handle_marc_response(self):
        progress = self.dispatch_progress
        progress('Handling MARC data')
        response = self._marc_response
        book_path = self.book.path
        if len(response) > 0 and response['sts'] == 'OK':
            progress('Found MARC data for this book. Writing MARCXML')
            with open(join(book_path, 'marc.xml'), 'w+') as fd:
                fd.write(self._marc_response['marc_xml'])
            progress('Writing MARC binary')
            with open(join(book_path, 'marc.bin'), 'wb+') as fd:
                base64_encoded_marc = self._marc_response['marc_binary']
                decoded_marc = base64.b64decode(base64_encoded_marc)
                fd.write(decoded_marc)
            progress('Extracting metadata')
            self.metadata = self._marc_response['extracted_metadata'][
                'metadata']
            progress('Mangling metadata')
            self.metadata = md = response['extracted_metadata']['metadata']
            for key in list(md.keys()):
                if self.metadata[key] in ['', None]:
                    self.metadata.pop(key)
            for key, value in self.metadata.items():
                if type(value) is dict:
                    dict_as_list = list(value.values())
                    self.metadata[key] = dict_as_list
            if self.volume:
                self.metadata['volume'] = self.volume
            if self.extra:
                for field in ['boxid', 'old_pallet']:
                    value = [
                        x['value'] for x in self.extra if x['key'] == field
                    ][0]
                    self.metadata[field] = value
            self.metadata['scribe3_search_id'] = '{}'.format(self.search_id)
            self.metadata['scribe3_search_catalog'] = '{}'.format(
                self.payload.get('scribe3_search_catalog'))
            # These rely on upstream OL specs and we can't trust them 100%
            try:
                if self.payload.get('olid', None):
                    self.metadata['openlibrary_edition'] = '{}'.format(
                        self.payload.get('olid'))
                self.metadata['openlibrary_work'] = '{}'.format(
                    self.payload['ol_data']['details']['works'][0]['key'])
            except Exception as e:
                print(
                    'MetadataViaOpenlibraryTask: failed to retrieve ol data with error {}'
                    .format(e))
                pass
        else:
            self.marc_download_failed = True
            self.metadata = {}
            self.metadata['scribe3_search_id'] = '{}'.format(self.search_id)
            self.metadata['scribe3_search_catalog'] = '{}'.format(
                self.payload.get('scribe3_search_catalog'))

            if self.extra:
                for field in ['boxid', 'old_pallet']:
                    value = [
                        x['value'] for x in self.extra if x['key'] == field
                    ][0]
                    self.metadata[field] = value

            if self.volume:
                self.metadata['volume'] = self.volume

            with open(join(book_path, scribe_globals.ORIGINAL_ISBN_FILENAME),
                      'w+') as fd:
                fd.write(self.search_id)

        self.metadata['operator'] = self.book.operator
        self.metadata['scanningcenter'] = self.book.scanningcenter
        progress('Saving metadata')
        set_metadata(self.metadata, book_path)
Esempio n. 10
0
 def _handle_marc_response(self):
     progress = self.dispatch_progress
     response = self._marc_response
     book_path = self.book_path
     if response['sts'] == 'OK':
         progress('Found MARC data for this book. Writing MARCXML')
         with open(join(book_path, 'marc.xml'), 'w+') as fd:
             fd.write(response['marc_xml'].encode('utf-8'))
         progress('Writing MARC binary')
         with open(join(book_path, 'marc.bin'), 'wb+') as fd:
             marcbin = bytes(response['marc_binary'].encode('utf-8'))
             fd.write(marcbin)
         self.metadata = md = response['extracted_metadata']['metadata']
         for key in list(md.keys()):
             if self.metadata[key] in ['', None]:
                 self.metadata.pop(key)
         for key, value in self.metadata.items():
             if type(value) is dict:
                 dict_as_list = list(value.values())
                 self.metadata[key] = dict_as_list
         if 'isbn' in self.metadata:
             if self.metadata['isbn'] in [None, 'None']:
                 self.metadata['isbn'] = '{}'.format(self.isbn)
             elif type(self.metadata['isbn']) == list:
                 if self.isbn not in self.metadata['isbn']:
                     self.metadata['isbn'].append(self.isbn)
             elif type(self.metadata['isbn']) == str:
                 self.metadata['isbn'] = [self.metadata['isbn'], self.isbn]
         else:
             self.metadata['isbn'] = '{}'.format(self.isbn)
         if self.volume:
             self.metadata['volume'] = self.volume
         if self.extra:
             for field in ['boxid', 'old_pallet']:
                 value = [
                     x['value'] for x in self.extra if x['key'] == field
                 ][0]
                 self.metadata[field] = value
         progress('Saving metadata')
         # TODO: Regression: Only metadata from form should be saved?
         # Check CaptureScreen.download_and_save_marc method
         set_metadata(self.metadata, book_path)
         progress('Creating new identifier')
         self.identifier = identifier = make_identifier(
             title=self.metadata.get('title', None) or 'unset',
             volume=self.metadata.get('volume', None) or '00',
             creator=get_string_value_if_list(self.metadata, 'creator')
             or 'unset')
         progress('Setting identifier to {}'.format(identifier))
         with open(join(book_path, 'identifier.txt'), 'w') as fd:
             fd.write(identifier)
     else:
         self.marc_download_failed = True
         self.identifier = identifier = 'isbn_' + self.isbn
         if self.volume and self.volume != '0':
             self.identifier = identifier = 'isbn_{}_{}'.format(
                 self.isbn, self.volume)
         progress('No MARC record found for this book. '
                  'Setting identifier to {}'.format(identifier))
         with open(join(book_path, 'identifier.txt'), 'w+') as fd:
             fd.write(identifier)
         with open(join(book_path, scribe_globals.ORIGINAL_ISBN_FILENAME),
                   'w+') as fd:
             fd.write(self.isbn)
Esempio n. 11
0
 def _write_metadata(self):
     self.dispatch_progress('Writing metadata')
     set_metadata(self.metadata, self.book_obj.path)
     self.book_obj.reload_metadata()
     self.book_obj.do_create_metadata()