예제 #1
0
def show_one_server_object(meta, searchFile):
    """like WebUpload_ryw.show_one_server_object() except that
    the searchFile is passed in."""
    
    print "<BR>"
    print Browse.script_str()
    #displayObject = ryw_view.DisplayObject(RepositoryRoot,
    #                                       calledByVillageSide = False,
    #                                       missingFileFunc = None)

    success,reverseLists = ReverseLists.open_reverse_lists(
        'EditObject:', '', '',
        os.path.join(RepositoryRoot, 'ReverseLists'), True,
        searchFile = searchFile,
        repositoryRoot = RepositoryRoot)
    if not (success and reverseLists):
        ryw.give_bad_news('EditObject: failed to open ReverseLists.',
                          logging.critical)
        if reverseLists:
            reverseLists.done()
        return False

    displayObject = ryw_view.DisplayObject(
        RepositoryRoot, calledByVillageSide = False,
        missingFileFunc = Browse.reqDownloadFunc,
        searchFile = searchFile,
        reverseLists = reverseLists)
    
    displayObject.begin_print()
    displayObject.show_an_object_compact(meta)
    displayObject.end_print()
    reverseLists.done()
def copy_reverse_lists(repDir):
    ryw.give_news2('copying reverse lists... &nbsp;&nbsp;', logging.info)
    logging.debug('copy_reverse_lists: ' + repDir)

    reverseListsFile = os.path.join(RepositoryRoot, 'ReverseLists')
    if not ryw.is_valid_file(reverseListsFile, 'copy_reverse_lists:'):
        ryw.give_news2('not found: ' + reverseListsFile + '<BR>',
                       logging.info)
        return True

    success,reverseLists = ReverseLists.open_reverse_lists(
        'AddRobotWriteRequests.copy_reverse_lists:',
        '', '', reverseListsFile, False,
        allowNullSearchFile = True)
    if not success:
        return False

    dst = os.path.join(repDir, 'ReverseLists')
    
    try:
        shutil.copyfile(reverseListsFile, dst)
    except:
        ryw.give_bad_news('copy_reverse_lists failed: ' +
                          reverseListsFile + ' ' + dst, logging.critical)
        if reverseLists:
            reverseLists.done()
        return False

    if reverseLists:
        reverseLists.done()
    
    logging.debug('copy_reverse_lists: ' + reverseListsFile + ' ' + dst)
    ryw.give_news2('done.<BR>', logging.info)
    return True    
예제 #3
0
def process_reverse_lists(objID, version, meta, searchFile):
    success,reverseLists = ReverseLists.open_reverse_lists(
        'DeleteObject:', '', '',
        os.path.join(RepositoryRoot, 'ReverseLists'), True,
        searchFile = searchFile, repositoryRoot = RepositoryRoot)
    if success and reverseLists:
        reverseLists.delete_object(objID, version, RepositoryRoot, meta)
        reverseLists.done()
    else:
        ryw.give_bad_news('process_reverse_lists: failed to open '+
                          'ReverseLists file.', logging.critical)
def main():
    init_log()
    ryw_view.print_header_logo()
    print '<TITLE>Test ReverseLists</TITLE>'

    success,reverseLists = ReverseLists.open_reverse_lists(
        'TestReverseLists:',
        os.path.join(RepositoryRoot, 'WWW', 'logs'),
        'upload.log',
        os.path.join(RepositoryRoot, 'ReverseLists'),
        False,
        allowNullSearchFile = True)
    if success:
        reverseLists.printme()
        reverseLists.done()
    ryw_view.print_footer()
예제 #5
0
def main(logDir, logFile, searchFile, scriptName, resources = None):
    """main function processing search request."""

    # initialization.
    name = print_header()
    form = cgi.FieldStorage()
    setup_logging(logDir, logFile)

    ## cgi.print_form(form)

    ## parse the form to get: query, sorting information, start_index
    ## to know which subset of matches/results to return,
    ## search_attributes for the next_page_button
    query, sort_tuple, start_index, search_attributes, error_message = \
           parse_form(form)
    if query is None:
	print '<P> ERROR while parsing form and constructing ' + \
              'search query:', error_message
	sys.exit(1)

    ## print '<HR>Query:', query

    ## read index file to get the list of dictionaries:
    ## one dictionary for each version of each object, contains its meta-data

    #
    # used to open search file without read.
    # because Sobti is doing the read by himself below.
    # I have to change this because the SearchFile will be passed
    # onto the ReverseLists module for more later lookups.
    # this makes it necessary to do a real SearchFile open.
    #
    #success,searchFileLock = ryw.open_search_file(
    #    'Search:', logDir, logFile, searchFile, False, skipRead = True)
    success,searchFileLock = ryw.open_search_file(
        'Search:', logDir, logFile, searchFile, False, skipRead = False)
    if not success:
        ryw.give_bad_news('Search: failed to acquire search file lock: ' +
                          searchFile, logging.critical)
        ryw_upload.quick_exit(1)
    #else:
        #
        # mis-named: it's really not a searchFileLock, but searchFile itself.
        #
        #displayObject.set_search_file(searchFileLock)
        

    #
    # this is when Sobti used to do his own read, now replaced by mine.
    #
    #metas, error_message = read_index_file_to_get_metas(searchFile)
    metas = searchFileLock.convert_to_sobti_list()
    if metas is None:
	print '<P> ERROR while reading the index file to get ' + \
              'the meta-data dictionaries:', error_message
        searchFileLock.done()
        ryw_upload.quick_exit(1)

    ## build a list of metas that satisfy the given query
    matches = []
    for meta in metas:
        if not ryw_view.should_show_object(meta, resources):
            continue
	if cnf_match.matches_cnf(meta, query):
            matches.append(meta)
            ryw.db_print2('Search:main() ' + repr(meta), 53)

    num_matches = len(matches)

    ## sort the matches by the given sort tuple
    matches, error_message = sort_matches(matches, sort_tuple)
    if matches is None:
	print '<P> ERROR while sorting matches:', error_message
        searchFileLock.done()
        ryw_upload.quick_exit(1)


    #
    # save all current search results in a file for
    # possible inclusion in the current selection.
    #
    matchAllName = save_matches(matches)
    

    ## Return the start_index..(start_index + N) entries from the top
    if num_matches == 0 or start_index >= num_matches:
	num_items = 0
    else:
	start_index = max(0, start_index)
        assert start_index < num_matches

	end_index = start_index + NUM_OBJECTS_PER_PAGE - 1
	end_index = max(0, end_index)
	end_index = min(num_matches - 1, end_index)

	if not (0 <= start_index <= end_index < num_matches):
            print '<P> ASSERT ERROR: start_index, end_index, ' + \
                  'num_matches', start_index, end_index, num_matches
            searchFileLock.done()
            ryw_upload.quick_exit(1)

	num_items = end_index - start_index + 1

    ## num_items is the number of items that will actually be displayed
    ## num_items <= num_matches
    if num_items == 0:
	print '<P><H3>No objects to display</H3>'
        searchFileLock.done()
        ryw_upload.quick_exit(1)
    else:
	#print '<P><H3>%d objects satisfy the search criteria, ' + \
        #      'displaying %d of them</H3>' % (num_matches, num_items)
        print """
<BR><B><FONT SIZE=2>%d
object(s) satisfy the search criteria.</FONT></B>""" % \
              (num_matches)
        print """
<BR><B><FONT SIZE=2>displaying matches %d - %d.</FONT></B><BR>""" % \
              (start_index + 1, start_index + num_items)

        print_next_page_button1(search_attributes, end_index + 1, scriptName,
                                num_matches)

        shownMatches = []
        
        success,reverseLists = ReverseLists.open_reverse_lists(
            'Search:', '', '',
            os.path.join(RepositoryRoot, 'ReverseLists'), True,
            searchFile = searchFileLock,
            repositoryRoot = RepositoryRoot)
        if not (success and reverseLists):
            ryw.give_bad_news('Search.main: failed to open ReverseLists.',
                              logging.critical)
            if reverseLists:
                reverseLists.done()
            return False

        displayObject = ryw_view.DisplayObject(
            RepositoryRoot, calledByVillageSide = False,
            missingFileFunc=Browse.reqDownloadFunc,
            searchFile = searchFileLock,
            reverseLists = reverseLists)
        
        displayObject.begin_print()
	for i in range(start_index, end_index + 1):
            #display_object(matches[i])
            displayObject.show_an_object_compact(matches[i])
            shownMatches.append(matches[i])
        displayObject.end_print()
        reverseLists.done()

        #
        # save search results on this page in a file for
        # possible inclusion in the current selection.
        #
        matchThisPageName = save_matches(shownMatches)

        print_selection_links(matchAllName, matchThisPageName)
        
    	## Include a next-page button
	print_next_page_button2(search_attributes, end_index + 1, scriptName,
                                num_matches)

    searchFileLock.done()
    ryw_view.print_footer()