Exemple #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)
Exemple #2
0
    def bt_server_register():
        message = ''
        #config = Scribe3Configuration()
        Logger.info('bt_server_register: Registering scribe')
        try:
            dd = dict(
                (k, v)
                for k, v in get_metadata(scribe_globals.CONFIG_DIR).items()
                if v)
            dd['books'] = '[]'
            tts = TTSServices(dd)
            success, tts_id = tts.register_tts(tts_id=dd['scanner'],
                                               metadata=dd)
            if success:
                #config.set('identifier', str(tts_id))
                push_event('tts-register', dd, 'tts', tts_id)
                Logger.info(
                    'bt_server_register: Registered scribe: {}'.format(tts_id))

            else:
                message =  'bt_server_register: Could not register this '\
                                'scribe with Archive.org or scribe already '\
                                'registered'
                Logger.info(message)
        except Exception:
            message = 'bt_server_register: Failed to register'
            Logger.exception(message)
        return message
Exemple #3
0
def check_metadata_registration(Logger):
    Logger.info('Check btserver registration: Begin.')
    metadata = get_metadata(scribe_globals.CONFIG_DIR)
    local_metadata = dict((k, v) for k, v in metadata.items() if v)
    tts = TTSServices(local_metadata)
    upd = None
    my_identifier = local_metadata.get('scanner')
    Logger.info('Loaded {} from scribe metadata'.format(my_identifier))
    try:
        upd = tts.is_metadata_updated(my_identifier, local_metadata)
    except Exception as e:
        Logger.exception('Error in check_metadata_registration')
    # if updated, tell metrics server
    Logger.info('Check btserver registration: Result = {}'.format(upd))
    if upd is not True:
        Logger.info('Metadata is not up to date, pushing to btserver')
        try:
            tts.update_metadata_tts(my_identifier, local_metadata)
            return True
        except Exception:
            Logger.exception('Failed to update metadata fields {} for {}'
                             .format(upd, local_metadata['identifier']))
            return False
    else:
        return True
Exemple #4
0
 def setup_book_info_panel(self):
     panel = self.ids.book_info_panel
     panel.scroll_y = 1.0
     cover_image = join(self.book['path'], 'thumbnails', '0001.jpg')
     if not exists(cover_image):
         cover_image = MISSING_IMAGE
     panel.cover_image = cover_image
     panel.claimer = self.get_claimer()
     panel.update_from_metadata(get_metadata(self.book['path']))
Exemple #5
0
 def get_book_metadata(self):
     md = get_metadata(self.book['path'])
     return {
         'identifier': self.book.get('identifier', None),
         'path': self.book['path'],
         'title': md.get('title', None),
         'creator': md.get('creator', md.get('author', None)),
         'language': md.get('language', None)
     }
 def reload_metadata(self):
     self.metadata = get_metadata(self.path)
     #self.notes = self.metadata['notes'] if 'notes' in self.metadata else None
     self.shiptracking_id = self.metadata[
         'shiptracking'] if 'shiptracking' in self.metadata else None
     self.boxid = self.metadata[
         'boxid'] if 'boxid' in self.metadata else None
     self.volume = self.metadata[
         'volume'] if 'volume' in self.metadata else None
     super(Book, self).reload_metadata()
Exemple #7
0
 def on_enter(self):
     # Get scan center metadata.xml from disk
     config = get_metadata(scribe_globals.SCANCENTER_METADATA_DIR)
     # Get all widgets
     widgets = [
         x for x in self.ids['_metadata'].children
         if isinstance(x, MetadataTextInput)
     ]
     # Populate
     for widget in widgets:
         val = config.get(widget.metadata_key)
         self.set_val(widget, val)
Exemple #8
0
def _prepare_metadata(book, item, Logger, override=False):
    md = get_metadata(book['path'])
    send_to_station_file = os.path.join(book['path'], 'send_to_station')
    if os.path.exists(send_to_station_file):
        md['repub_state'] = '40'
    else:
        md['repub_state'] = '10'
    md['mediatype'] = 'texts'

    for k, v in md.items():
        if ';' in v and k in scribe_globals.FLAT_MD_FIELDS:
            Logger.info('Detected a list-like flat field;'
                        'converting {} ({})to list.'.format(k, v))
            md[k] = v.split(';')

    try:
        collections_list = md['collection']
    except Exception:
        Logger.exception('upload_book: Could not find collection or '
                         'collection set specification in book '
                         'metadata.')
        collections_list = []

    scancenter_md = get_sc_metadata()

    # we assume operator is the one provided by the machine
    # but we honor what has been set upstream
    if 'operator' in md:
        scancenter_md['operator'] = md['operator']

    # same for language
    if 'language' in md:
        scancenter_md['language'] = md['language']

    filled_md = _fill_metadata(scancenter_md, collections_list, item, md,
                               Logger, override)

    # The old Scribe software uses author instead of creator, so we
    # do too, but we need to change this on upload
    if 'author' in filled_md:
        Logger.debug('upload_book: Converting author field to creator '
                     'before upload to cluster')
        filled_md['creator'] = md['author']
        del filled_md['author']

    if 'identifier' not in filled_md:
        filled_md['identifier'] = item.identifier

    if config.is_true('set_noindex'):
        filled_md['noindex'] = 'true'

    encoded_md = _clean_metadata(filled_md, Logger)
    return encoded_md
Exemple #9
0
def get_adjacent_scanners(show_all=False):
    try:
        sc = get_metadata(scribe_globals.CONFIG_DIR)['scanningcenter']
        session = get_ia_session()
        query = 'collection:iabooks-btserver AND scanningcenter:{}'.format(sc)
        if show_all:
            scanners = [x['identifier'] for x in session.search_items(query)]
        else:
            scanners = [
                x['identifier'] for x in session.search_items(query)
                if x['identifier'].startswith('fold')
            ]
        return sc, scanners
    except Exception as e:
        return False, e
Exemple #10
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()
Exemple #11
0
 def update_metadata(self):
     """Update scanner metadata
     """
     config = get_metadata(scribe_globals.SCANCENTER_METADATA_DIR)
     # Go trough all widgets
     # Since there are also "EmailTextInput" class instances,
     # let us see each widget has 'metadata_key' property
     for widget in self.ids['_metadata'].children:
         if hasattr(widget, 'metadata_key'):
             value = config.get(widget.metadata_key)
             if value is not None:
                 widget.text = text_type(value)
     # Easter egg
     if config.get('operator') == '*****@*****.**':
         rectangle = self.ids['_about_header'].canvas.before.children[1]
         rectangle.source = 'images/fidget.png'
Exemple #12
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()
Exemple #13
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
Exemple #14
0
 def on_menu_bar_option_select(self, menu, option):
     if option == menu.OPTION_UPLOAD:
         self.package_and_schedule_for_upload()
     elif option == menu.OPTION_FIRST_LEAF:
         leaf_number = self.find_first_non_reshoot_leaf_number()
         if leaf_number:
             self.open_book_at_leaf(leaf_number)
     elif option == menu.OPTION_PUBLIC_NOTES:
         metadata = get_metadata(self.book['path'])
         notes = metadata.get('notes', None) or ''
         popup = BookNotesPopup(title='Edit public book notes', notes=notes)
         popup.bind(on_submit=self.on_book_notes_submit)
         popup.open()
     elif option == menu.OPTION_INTERNAL_NOTES:
         internal_notes = self.scandata.get_internal_book_notes() or ''
         popup = BookNotesPopup(title='Edit internal book notes',
                                notes=internal_notes)
         popup.bind(on_submit=self.on_internal_book_notes_submit)
         popup.open()
Exemple #15
0
 def reload_metadata(self):
     self.metadata = get_metadata(self.path)
     self.title = self.metadata[
         'title'] if 'title' in self.metadata else None
     self.creator = self.metadata[
         'creator'] if 'creator' in self.metadata else None
     self.operator = self.metadata[
         'operator'] if 'operator' in self.metadata else None
     self.scanner = self.metadata[
         'scanner'] if 'scanner' in self.metadata else None
     self.scanningcenter = self.metadata[
         'scanningcenter'] if 'scanningcenter' in self.metadata else None
     self.exists = os.path.exists(self.path)
     self.identifier = new_get_identifier(self)
     self.date_last_updated = self.load_last_modified_from_disk(
         including_move_along=True)
     self.date_last_modified = self.load_last_modified_from_disk()
     self.date_created = self.load_date_created_from_disk()
     if self.notify:
         self.notify('reloaded_metadata')
Exemple #16
0
 def _update_from_metadata(self):
     ''' this updates the values of certain self fields
     listed in `augmented_fields`, with the values fetched from
     reading metadata.xml of that book. We shouldn't be doing this
     here, instead relying on all the right information being passed
     to the constructor, which will come when we can pass more structured
     Book objects (2.0-Release branch)
     '''
     try:
         self.metadata = get_metadata(self.book_path)
     except Exception:
         Logger.exception(
             'Failed to get book metadata from path: {}'.format(
                 self.book_path))
         self.metadata = None
     augmented_fields = ['isbn', 'shiptracking']
     if self.metadata:
         for field in augmented_fields:
             if field in self.metadata:
                 setattr(self, field,
                         self._book_value_to_string(self.metadata, field))
Exemple #17
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)
Exemple #18
0
 def _load_metadata(self):
     self.dispatch_progress('Loading metadata')
     if 'metadata.xml' in self.directory_list[2]:
         self.metadata = get_metadata(self.source_path)
     else:
         self.metadata = {}
Exemple #19
0
 def _safe_load_metadata(self):
     # TODO: Validate downloaded metadata
     try:
         return get_metadata(self.book_path)
     except Exception:
         return None
def get_scanner_property(property):
    return get_metadata(scribe_globals.CONFIG_DIR).get(property, None)
Exemple #21
0
 def _get_scribe_app_metadata(self):
     self.dispatch_progress('Getting Scribe app metadata')
     metadata = get_metadata(scribe_globals.CONFIG_DIR)
     local_metadata = \
         dict((k, v) for k, v in metadata.items() if v)
     self._payload['local_metadata'] = local_metadata
Exemple #22
0
    def __init__(self, init_dict, callback=None, delete_callback=None):
        print("[Item::init()] Creating item object from ->", init_dict)
        self.GSM = FysomGlobal(
            cfg=self.state_machine,
            state_field='status',
        )

        self.constructor_args = init_dict
        self.uuid = init_dict['uuid']
        self.path = init_dict[
            'path'] if 'path' in init_dict else self.build_path()
        self.exists = os.path.exists(self.path)

        self.TYPE_FILE = os.path.expanduser(os.path.join(self.path, 'type'))
        self.STATUS_FILE = os.path.expanduser(os.path.join(
            self.path, 'status'))
        self.STATUS_HISTORY_FILE = os.path.expanduser(
            os.path.join(self.path, 'status_history'))
        if not self.exists:
            self.ensure_path()

        self._set_type()

        self.logger = self.get_logger()
        self.status = self._resolve_status(init_dict)

        self.MINIMAL_METADATA_MANIFEST = [
            'title', 'creator', 'operator', 'scanningcenter', 'scanner'
        ]
        self.metadata = get_metadata(self.path)
        if len(self.metadata) == 0:
            self.create_initial_metaxml()

        self.identifier = new_get_identifier(self)
        self.title = init_dict[
            'title'] if 'title' in init_dict else self.metadata[
                'title'] if 'title' in self.metadata else None
        self.creator = init_dict[
            'creator'] if 'creator' in init_dict else self.metadata[
                'creator'] if 'creator' in self.metadata else None

        self.date_last_updated = init_dict['date'] if 'date' in init_dict \
            else self.load_last_modified_from_disk(including_move_along=True)
        self.date_last_modified = init_dict['date_last_modified'] if 'date_last_modified' in init_dict \
            else self.load_last_modified_from_disk()
        self.date_created = init_dict['date_created'] if 'date_created' in init_dict \
            else self.load_date_created_from_disk()
        self.operator = init_dict[
            'operator'] if 'operator' in init_dict else self.metadata[
                'operator'] if 'operator' in self.metadata else None
        self.scanner = init_dict[
            'scanner'] if 'scanner' in init_dict else self.metadata[
                'scanner'] if 'scanner' in self.metadata else None
        self.scanningcenter = init_dict[
            'scanningcenter'] if 'scanningcenter' in init_dict else self.metadata[
                'scanningcenter'] if 'scanningcenter' in self.metadata else None

        self.error = init_dict['error'] if 'error' in init_dict else None
        self.worker_log = ''
        self.msg = ''

        self.last_activity = ''

        self.force_upload = False
        self.force_delete = False

        self.delete_callback = delete_callback
        self.natural_callback = callback

        callbacks = self.build_callbacks()
        self.GSM._callbacks = callbacks

        self.worker_lock = threading.RLock()

        super(Scribe3Item, self).__init__()
Exemple #23
0
 def _load_metadata_from_disk(self):
     if self.book_path and exists(self.book_path):
         self._set_metadata(get_metadata(self.book_path))
     else:
         self._set_metadata(None)
Exemple #24
0
def get_scanner_name():
    raw_md = get_metadata(scribe_globals.CONFIG_DIR)
    metadata = dict((k, v) for k, v in raw_md.items() if v)
    ret = metadata.get('scanner')
    return ret if ret else socket.gethostname()
Exemple #25
0
def get_scanner_item(Logger=None):
    identifier = get_metadata(scribe_globals.CONFIG_DIR)['scanner']
    session = get_ia_session()
    scanner_item = session.get_item(identifier)
    return scanner_item