def extract_texts(reqList, searchFile):
    """modeled after ShowQueue.go_through_list()."""

    metaList = ryw_meta.get_meta_list(reqList, searchFile)
    metaList = ryw.sortmeta_chapter_number(metaList)

    totalCount = 0
    outputFile = open_output_text_file()
    if outputFile == None:
        return False

    numMatches = len(metaList)
    if numMatches <= 0:
        ryw.give_news("SelectTexts: no object selected.<BR>", logging.error)
        success = False
    else:
        success = True
        firstLine = True
        for meta in metaList:
            success, count = output_text(outputFile, meta, firstLine=firstLine)
            totalCount += count
            if not success:
                break
            if count != 0:
                firstLine = False

    close_output_file(outputFile)
    searchFile.done()

    ryw.give_news(str(totalCount) + " strings need to be translated.", logging.info)
    return success
    def initialize_with_meta_list(self, reqList, searchFile, reverseLists):
        """called by ChapterListForm() to initialize chapter list from
        the meta data.
        modeled after ShowQueue.go_through_list().
        also called by ChapterListFormHandle()."""

        success = True
        
        if not searchFile or not reverseLists:
            raise NameError('ChapterList.initialize_with_meta_list:' +
                            'bad searchFile or bad reverseLists.')

        metaList = ryw_meta.get_meta_list(reqList, searchFile)
        searchFile.done()

        metaList = ryw.sortmeta_chapter_number(metaList)

        ryw.db_print2('initialize_with_meta_list: done sorting.', 38)

        numMatches = len(metaList)

        if numMatches <= 0:
            ryw.give_news('ChapterList: the selection is empty.<br>',
                          logging.error)
            success = False
        else:
            self.chapterDict = {}
            self.itemList = []
            self.metaList = metaList

            for meta in metaList:
                objID = meta['id']
                version = meta['version']
                objstr = objID + '#' + str(version)
                self.itemList.append(objstr)

                title = ''
                if meta.has_key('title'):
                    title = meta['title']

                chapter = None
                if meta.has_key('chapter_number'):
                    chapter = meta['chapter_number']

                alias = None
                if meta.has_key('content_alias'):
                    alias = meta['content_alias']

                self.chapterDict[objstr] = [alias, title, chapter]

            ryw.db_print2('chapterDict is: ' + repr(self.chapterDict), 41)
        
        return success
    def re_sort_items(self):
        """10/24/08: called before displaying the chapter edit form.
        so that the edit form is sorted.
        called by make_form_string()"""

        self.patch_meta_list_with_chapters()
        self.metaList = ryw.sortmeta_chapter_number(self.metaList)

        itemList = []
        for meta in self.metaList:
            objID = meta['id']
            version = meta['version']
            objstr = objID + '#' + str(version)
            itemList.append(objstr)
            
        self.itemList = itemList
def go_through_list(reqList, callBackFunc = cancelFunc, cBackArg = None,
                    offResult = None,
                    cgiScript = '/cgi-bin/ShowQueue.py',
                    scriptConnectChar = '?',
                    searchFile = None,
                    reverseLists = None,
                    chapterList = None):
    """also called by DisplaySelection.py"""

    if not searchFile or not reverseLists:
        raise NameError('ShowQueue: bad searchFile or bad reverseLists')

    if not offResult:
        offResult = (True, True, 0)

    #
    # 
    # only get SearchFile if nothing is sent in?
    # 
    #success,searchFile = ryw.open_search_file(
    #    'ShowQueue:',
    #    os.path.join(RepositoryRoot, 'WWW', 'logs'),
    #    'upload.log',
    #    os.path.join(RepositoryRoot, 'SearchFile'),
    #    False)
    #if not success:
    #    return False


    metaList = ryw_meta.get_meta_list(reqList, searchFile)

    #
    # 10/24/08: from DisplaySelection, we want to patch the chapter
    # numbering using the chapter list.
    #
    if chapterList:
        chapterList.patch_meta_list_with_chapters(metaList=metaList)

    metaList = ryw.sortmeta_chapter_number(metaList)

    logging.debug('ShowQueue: printing sorted objects...')

    displayObject = ryw_view.DisplayObject(RepositoryRoot,
                                           calledByVillageSide = False,
                                           missingFileFunc = callBackFunc,
					   callBackArg = cBackArg,
                                           searchFile = searchFile,
                                           reverseLists = reverseLists)
    #displayObject = ryw_view.DisplayObject(RepositoryRoot,
    #                                       calledByVillageSide = False,
    #                                       missingFileFunc = TestReqFunc)

    offsuccess,showAll,offsetNum = offResult
    numMatches = len(metaList)
    success = True
    
    if numMatches <= 0:
        ryw.give_news('ShowQueue: no object to show.<BR>', logging.error)
        success = False
    elif showAll:
        print_num_selected(numMatches, 0, 0, showAll = True)
        displayObject.begin_print()
        for meta in metaList:
            displayObject.show_an_object_compact(meta)
        displayObject.end_print()
        print '<BR>'
    else:
        offsetNum,endIndex = compute_begin_end(offsetNum, numMatches)
        print_num_selected(numMatches, offsetNum, endIndex)
        print_next_button(cgiScript, scriptConnectChar,
                          endIndex, numMatches)
        displayObject.begin_print()
        for i in range(offsetNum,  endIndex + 1):
            displayObject.show_an_object_compact(metaList[i])
        displayObject.end_print()
        print_next_button(cgiScript, scriptConnectChar,
                          endIndex, numMatches,
			  addBlanks = True)

    searchFile.done()
    return success