def copy_reverse_lists(repDir):
    ryw.give_news2('copying reverse lists...   ', 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    
Пример #2
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()
Пример #3
0
def show_one_server_object(meta):

    success, searchFile, reverseLists = ReverseLists.open_searchfile_reverselists(
        "WebUpload_ryw.show_one_server_object:"
    )
    if not success:
        return None

    print Browse.script_str()

    # displayObject = ryw_view.DisplayObject(RepositoryRoot,
    #                                       calledByVillageSide = False,
    #                                       missingFileFunc = None)
    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()
    return searchFile
Пример #4
0
def main():
    name = init_log()
    ryw_view.print_header_logo()
    print '<TITLE>Browsing Selection</TITLE>'

    offsetResult = get_offset()
    success,isAll,offsetNum = offsetResult
    if not success:
        DisplaySelection.exit_now(1)
    
    print_header(name)
    rfpath = os.path.join(RepositoryRoot, 'QUEUES', name)
    reqList = read_list(rfpath)
    if not reqList:
        ryw.give_news('no object selected.', logging.info)
        DisplaySelection.exit_now(0)


    success,searchFile,reverseLists = \
        ReverseLists.open_searchfile_reverselists(
        'ShowQueue.main:')

    if not success:
        DisplaySelection.exit_now(0)

    if go_through_list(reqList, offResult = offsetResult,
                       searchFile = searchFile, reverseLists = reverseLists):
        print_buttons(name)
        
    ryw_view.print_footer()
    searchFile.done()
    reverseLists.done()
Пример #5
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():
    ryw.check_logging(os.path.join(RepositoryRoot, 'WWW', 'logs'),
                      'upload.log')
    logging.debug('CurrSelAddedToThisSel: entered...')
    ryw_view.print_header_logo()


    success,objID,version = ryw.get_obj_str()
    if not success:
        ryw.give_bad_news('CurrSelToThisSel: failed to get objstr.',
                          logging.critical)
        DisplaySelection.exit_now(1)
    
    success,searchFile,reverseLists = \
        ReverseLists.open_searchfile_reverselists('CurrSelAddedToThisSel:')
    if not success:
        ryw.give_bad_news('CurrSelAddedToThisSel: ' +
                          'open_searchfile_reverselists failed.',
                          logging.critical)
        DisplaySelection.exit_now(1)
    

    rfpath = DisplaySelection.get_file_path(
        objID, version, searchFile = searchFile)
    if not rfpath:
        ryw.give_bad_news(
            'CurrSelAddedToThisSel: no selection file name found.',
            logging.error)
        DisplaySelection.exit_now(1)

    queueName = DeleteRepReq.get_queue_name()
    if not queueName:
        ryw.give_bad_news(
            'CurrSelToThisSel: failed to get current selection file name.',
            logging.error)
        DisplaySelection.exit_now(1)

    queueSel = ProcessDownloadReq.get_reqs(queueName)
    savedSel = ProcessDownloadReq.get_reqs(rfpath)
    newContainees = list(queueSel)

    AddSearchAll.union_and_write(savedSel, queueSel, rfpath)
    ryw.give_news('You may want to reload the page containing '+
                  'this selection.', logging.info)


    success = reverseLists.add(objID+'#'+str(version), newContainees)
    if not success:
        ryw.give_bad_news('CurrSelAddedToThisSel: reverseLists.add failed.',
                          logging.critical)

    reverseLists.done()
    searchFile.done()
    DisplaySelection.exit_now(0)
Пример #7
0
def main():
    ryw.check_logging(os.path.join(RepositoryRoot, 'WWW', 'logs'),
                      'upload.log')
    logging.debug('DeleteFromSel: entered...')
    ProcessDownloadReq.print_header()

    #ProcessDownloadReq.delete_request(queue)

    form = cgi.FieldStorage()
    if (not form.has_key('objstr')) or (not form.has_key('selobj')):
        ryw.give_bad_news('DeleteFromSel.py: lacking arguments.',
                          logging.critical)
        DisplaySelection.exit_now(1)
        
    objstr = form.getfirst('objstr', '')
    selobj = form.getfirst('selobj', '')

    if (not objstr) or (not selobj):
        ryw.give_bad_news('DeleteFromSel.py: null arguments.',
                          logging.critical)
        DisplaySelection.exit_now(1)

    #ryw.give_news('DeleteFromSel.py: ' + objstr, logging.info)
    #ryw.give_news('DeleteFromSel.py: ' + selobj, logging.info)


    success,searchFile,reverseLists = \
        ReverseLists.open_searchfile_reverselists('DeleteFromSel:')
    if not success:
        ryw.give_bad_news(
            'DeleteFromSel: open_searchfile_reverselists failed.',
            logging.critical)
        DisplaySelection.exit_now(1)


    objID,version = selobj.split('#')
    version = int(version)
    rfpath = DisplaySelection.get_file_path(objID, version,
                                            searchFile=searchFile)
    if not rfpath:
        DisplaySelection.exit_now(1)

    success = ProcessDownloadReq.do_delete(rfpath, objstr)

    if success:
        sys.stdout.write("True")
    else:
        print "Failed to delete from selection."

    reverseLists.remove_obsolete_containers(objstr, [selobj])
    reverseLists.done()
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()
def go_through_object_store(objectStoreRoot, reverseLists):

    ryw.give_news2('go_through_object_store: entered...<BR>', logging.info)

    searchFile = reverseLists.searchFile
    for objID,version in objectstore.objectversioniterator(objectStoreRoot):

        objstr = objID + '#' + str(version)
        ryw.db_print2('examining ' + objstr + '...<BR>', 7)

        success,meta = searchFile.get_meta(objID, version)
        if not success or not meta:
            ryw.give_bad_news('go_through_object_store: get_meta2 failed: ' +
                               objstr, logging.warning)
            continue

        isList = meta.has_key('sys_attrs') and 'isList' in meta['sys_attrs']
        if not isList:
            ryw.db_print2('go_through_object_store: not a list object: ' +
                         objstr + '<BR>', 6)
            ryw.give_news2(' . ', logging.info)
            continue
        ryw.db_print2('go_through_object_sotre: found a list.<BR>', 6)

        containees = ReverseLists.read_container_file(
            objID, version, searchFile, RepositoryRoot)
        ryw.db_print2('go_through_object_store: containees are: ' +
                      repr(containees) + '<BR>', 7)
        if not reverseLists.add(objstr, containees):
            ryw.give_bad_news('go_through_object_store: ReverseLists.add ' +
                              'failed: ' + objstr, logging.error)
        else:
            ryw.db_print2('go_through_object_store: successfully added.<BR>',
                          7)
            alias = 'unnamed'
            if meta.has_key('content_alias'):
                alias = meta['content_alias']
            ryw.give_news2(objstr + ' ' + alias + ', ', logging.info)

    ryw.give_news2('<BR>done.', logging.info)
Пример #10
0
def main():
    """modeled after ShowQueue.py."""

    name = ShowQueue.init_log()
    ryw_view.print_header_logo()
    print "<TITLE>Prepare for Automated Hindi Translation</TITLE>"

    rfpath = os.path.join(RepositoryRoot, "QUEUES", name)
    reqList = ShowQueue.read_list(rfpath)
    if not reqList:
        ryw.give_news("SelectText.py: no object selected.", logging.info)
        DisplaySelection.exit_now(0)

    success, searchFile, reverseLists = ReverseLists.open_searchfile_reverselists("SelectTexts.main:")

    if not success:
        DisplaySelection.exit_now(0)

    extract_texts(reqList, searchFile)

    ryw.give_news("done.", logging.info)
    ryw_view.print_footer()
    searchFile.done()
    reverseLists.done()
def main():
    init_log()
    ryw_view.print_header_logo()
    print '<TITLE>Rebuild ReverseLists</TITLE>'

    success,newReverseListsFile,objectStoreRoot = decide_path()
    if not success:
        sys.exit(1)

    success,searchFile,reverseLists = \
        ReverseLists.open_searchfile_reverselists(
            'RebuildReverseLists:',
            newReverseListsFileName = newReverseListsFile)
    if not success:
        sys.exit(1)
    else:
        ryw.give_news2('<BR>new ReverseLists generated at: ' +
                       newReverseListsFile + '<BR>', logging.info)

    go_through_object_store(objectStoreRoot, reverseLists)

    if reverseLists:
        reverseLists.done()
    ryw_view.print_footer()
Пример #12
0
def main():
    """main function processing upload."""

    # initialization.
    name = WebUpload_ryw.print_header()
    form = cgi.FieldStorage()
    WebUpload_ryw.setup_logging()

    if not ryw_upload.check_required_fields(form, checkFile = False):
        ryw_upload.quick_exit(1)


    localExcerptResult = ryw_upload.check_local_file(
        form, fieldName = "local_excerpt_filename")

    # check aux file uploads: thumbnails, exerpts...
    success,auxExists,aux = ryw_upload.check_aux_file_uploads(
        form, localExcerptStuff = localExcerptResult)
    if not success:
        ryw_upload.quick_exit(1)

    tmpdir = WebUpload_ryw.attempt_make_tmpdir()
    if not tmpdir:
        ryw_upload.quick_exit(1)

    success,auxDir,auxInfo = ryw_upload.read_aux_files(
        form, aux, tmpdir, auxExists,
        localExcerptStuff = localExcerptResult)
    if not success:
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)

    bytes,name = ryw_upload.copy_queue_file(tmpdir, name)
    if bytes == 0:
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)
    kB = math.ceil(bytes / 1024.0)
    filename = name
        

    #
    # the rest of this stuff copied straight from WebUpload_ryw.py
    # not nice, but hey.
    #
    meta = ryw_upload.try_process_attributes(name, form, filename, kB, bytes)
    if not meta:
        ryw_upload.cleanup_and_exit(tmpdir, None, None, 1)
    ryw_upload.add_set_attrs(meta, 'sys_attrs', 'isList')

    meta = ryw_upload.add_aux_attributes(meta, auxInfo)

    success,metafile = ryw_upload.write_tmp_metafile(meta, tmpdir)
    if not success:
        ryw_upload.cleanup_and_exit(tmpdir, metafile, None, 1)
    
    nameToUpload,extractDir = ryw_upload.try_unzip_file(
        form, tmpdir, filename, kB)
    if not nameToUpload:
        ryw_upload.cleanup_and_exit(tmpdir, metafile, extractDir, 1)

    ryw.give_news2('<BR>Storing the list in the repository...',
                   logging.info)
    if not WebUpload_ryw.try_upload_object(meta, nameToUpload, auxDir):
        ryw_upload.cleanup_and_exit(tmpdir, metafile, extractDir, 1)

    #ryw_view.show_server_object(meta)
    searchFile = WebUpload_ryw.show_one_server_object(meta)
    #
    # Ok to do this stuff after the display, because there's no
    # way the newly added selection could be a containee of someone else.
    #
    ReverseLists.add_queue(meta, searchFile, RepositoryRoot)
    searchFile.done()

    ryw_upload.cleanup_and_exit(tmpdir, metafile, extractDir, 0)
def main():
    """modeled after ChapterListForm.py.
    This is for displaying a form that allows editing the chapter list."""

    name = ShowQueue.init_log()
    ryw_view.print_header_logo()
    print '<TITLE>Processing the Chapter List</TITLE>'

    ryw.db_print2('<BR>ChapterListFormHandle.py: entered... <BR>', 39)

    form = cgi.FieldStorage()

    success,objID,version = ryw.get_obj_str(form = form)
    if not success:
        ryw.give_bad_news('ChapterListFormHandle: failed to get objstr.',
                          logging.critical)
        DisplaySelection.exit_now(1)

    ryw.db_print2('ChapterListFormHandle: objstr is: ' +
                  objID + '#' + str(version), 40)

    chapterList = ChapterList.ChapterList(objID + '#' + str(version))
    success,formEntries = chapterList.process_form(form)
    
    if not success:
        ryw.give_bad_news('ChapterListFormHandle: process_form() failed.',
                          logging.error)
        DisplaySelection.exit_now(1)
    
    success,searchFile,reverseLists = \
        ReverseLists.open_searchfile_reverselists(
        'DisplaySelection.main:')
    if not success:
        DisplaySelection.exit_now(1)

    success = DisplaySelection.print_title(objID, version, name, searchFile)
    if not success:
        DisplaySelection.exit_now(1)

    ryw.db_print2('<BR>ChapterListFormHandle.py entered.<BR>', 41)

    nameTriple = DisplaySelection.get_file_paths2(
        objID, version, searchFile = searchFile)
    if not nameTriple:
        DisplaySelection.exit_now(1)
    rfpath,chapterListPath,chapterListFullName = nameTriple
    if not rfpath:
        DisplaySelection.exit_now(1)

    ryw.db_print2('ChapterListFormHandle: chapter list file is: ' +
                  chapterListFullName, 41)

    reqList = ShowQueue.read_list(rfpath)
    if not reqList:
        ryw.give_news('This selection is empty.<BR>', logging.info)
        print '<BR>'
        print_links(objID, version, name)
        DisplaySelection.exit_now(0)

    ryw.db_print2('ChapterListForm.py: gotten selection list.', 41)

    success = chapterList.initialize_with_meta_list(
        reqList, searchFile, reverseLists)

    if not success:
        ryw.give_bad_news('ChapterListFormHandle: ' +
                          'initialize_with_meta_list failed.',
                          logging.error)
        DisplaySelection.exit_now(1)

    chapterList.compare_form_entries_against_meta()
    if not chapterList.write_file(chapterListFullName):
        ryw.give_bad_news('ChapterListFormHandle: write_file() failed.',
                          logging.error)
        DisplaySelection.exit_now(1)

    ryw.give_news('chapter list saved.', logging.info)
                              
    ryw_view.print_footer()

    reverseLists.done()
    searchFile.done()
Пример #14
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()
Пример #15
0
def process_disk_from_peer_repository(dir_name, diskRoot, overwrite=False):

    objectroot = os.path.join(dir_name, 'objects')
    if not os.path.exists(objectroot):
        logging.info(
            'process_disk_from_peer_repository: no objects directory.' +
            objectroot)
        return True
    
    ## Process all incoming objects

    local_object_root = get_local_object_store_root()
    if local_object_root is None:
        return False

    mapDict = ryw_philips.get_map(diskRoot)
    searchFile = None

    for objectId,version in objectstore.objectversioniterator(objectroot):

        ryw.give_news3('----------', logging.info)

        if mapDict == None:
            ryw.give_bad_news(
                'process_disk_from_peer_repository: failed to read map file: '+
                diskRoot, logging.error)
            return False

        #
        # We used to just skip objects already present.
        # now we want to do something.
        #
        #if object_version_is_present(local_object_root, objectId, version):
        #    ## object already present
        #    continue
        objectFound = object_version_is_present(local_object_root,
                                                objectId,
                                                version)

        paths = objectstore.name_version_to_paths_aux(objectroot,
                                                      objectId, version)

        itemName = objectId + '#' + str(version)

        obdata = get_data_name_mirror(paths[0], diskRoot, mapDict, itemName)
        if not obdata:
            continue

        success,isStub = is_data_stub(obdata)
        if not success:
            continue

        metadata = get_metadata_mirror(paths[1])
        if not metadata:
            continue

        auxdir = get_aux_name_mirror(paths[2], diskRoot, mapDict, itemName)

        if isStub and not objectFound:
            #ryw.give_bad_news(
            #    'ProcessDiscs: is a stub but not found in database: '+
            #    itemName, logging.error)
            ryw.give_news3(
                'ProcessDiscs error: is a stub but not found in database: '+
                itemName, logging.error)
            continue
        
        if isStub:
            success,searchFile = deal_with_stub(
                local_object_root, objectId, version, metadata,
                obdata, auxdir, searchFile = searchFile)
            if success:
                ryw.give_news3(
                    'ProcessDiscs success: meta data processed.',
                    logging.info)
            continue

        if objectFound:
            #ryw.give_bad_news(
            #    'ProcessDiscs: not a stub but found in the database: '+
            #    itemName, logging.error)
            ryw.give_news3(
                'ProcessDiscs: not a stub but found in the database: '+
                itemName, logging.error)

            if not overwrite:
                ryw.give_news3('processing skipped.', logging.error)
                continue
            
            #
            # I might want to delete the old version here.
            # using the code from DelObject, should be simple.
            #
            ryw.give_news3('deleting it...', logging.error)

            #
            # at one point, I thought I wanted to be clever and
            # tried to reuse searchFile below.  But the trouble is
            # that the UploadObject.uploadobject() call below will
            # change the SearchFile beneath me, and if I reuse
            # the searchFile here, I end up flushing the incorrectly
            # cached version back to disk. I actually would have
            # expected a deadlock when UploadObject.uploadobject()
            # tries to lock again but the deadlock somehow
            # didn't happen...
            #
            success,searchFile = DeleteObject.do_delete(
                objectId, version, searchFile=None)
            if not success:
                ryw.give_bad_news(
                    'ProcessDiscs: DeleteObject failed: ' +
                    objectId + '#' + str(version), logging.error)
                continue
            else:
                ryw.db_print('process_disk_from_peer_repository: ' +
                             'do_delete succeeded.', 18)
                
            #
            # falls through to continue onto adding the object.
            #
            
        if not UploadObject.uploadobject(metadata, obdata, auxdir,
                                         hasVersion = True):
            ryw.give_bad_news(
                'process_disk_from_peer_repository: ' +
                'UploadObject.uploadobject failed: '+
                repr(metadata) + ' ' + obdata, logging.critical)
            continue
        else:
            ryw.give_news3('ProcessDiscs success: new data uploaded.',
                           logging.info)
            continue

    incomingReverseLists = os.path.join(dir_name, 'ReverseLists')
    existingReverseLists = os.path.join(RepositoryRoot, 'ReverseLists')

    ReverseLists.merge_incoming(
        existingReverseLists, incomingReverseLists, RepositoryRoot,
        searchFile = searchFile)

    if searchFile:
        searchFile.done()
    return True
def main():

    name = ShowQueue.init_log()
    ryw_view.print_header_logo()
    print '<TITLE>Browsing Saved Selection</TITLE>'

    success,objID,version = ryw.get_obj_str()
    if not success:
        ryw.give_bad_news('DisplaySelection: failed to get objstr.',
                          logging.critical)
        exit_now(1)

    offsetResult = ShowQueue.get_offset()
    success,isAll,offsetNum = offsetResult
    if not success:
        exit_now(1)

    success,searchFile,reverseLists = \
        ReverseLists.open_searchfile_reverselists(
        'DisplaySelection.main:')
    if not success:
        sys.exit(1)

    success = print_title(objID, version, name, searchFile)
    if not success:
        exit_now(1)

    nameTriple = get_file_paths2(objID, version, searchFile = searchFile)
    if not nameTriple:
        exit_now(1)
    rfpath,chapterListPath,chapterFullName = nameTriple
    if not rfpath:
        exit_now(1)

    reqList = ShowQueue.read_list(rfpath)
    if not reqList:
        ryw.give_news('This selection is empty.<BR>', logging.info)
        print '<BR>'
        print_links(objID, version, name)
        exit_now(0)

    #
    # do this before displaying so that the ReverseLists is
    # properly reflected before we hit the display code.
    #
    result = reverseLists.add(objID + '#' + str(version), reqList)

    #
    # process the chapter list. 10/24/08.
    #
    success,chapterList = ChapterList.create_and_initialize(
        objID + '#' + str(version),
        reqList, searchFile, reverseLists,
        chapterFullName)
    if not success:
        ryw.give_bad_news('ChapterList.create_and_initialize failed: ' +
                          objID + '#' + str(version), logging.error)
        exit_now(1)

    scriptName = '/cgi-bin/DisplaySelection.py?objstr=' + \
                 objID + '%23' + str(version)
    
    success = \
            ShowQueue.go_through_list(reqList,
                                      callBackFunc = delOneSelFunc, 
                                      cBackArg = objID + '#' + str(version),
                                      offResult = offsetResult,
                                      cgiScript = scriptName,
                                      scriptConnectChar = '&',
                                      searchFile = searchFile,
                                      reverseLists = reverseLists,
                                      chapterList = chapterList)

    if success:
        print_links(objID, version, name)
        
    ryw_view.print_footer()

    reverseLists.done()
    searchFile.done()
def main():
    """modeled after DisplaySelection.py.
    This is for displaying a form that allows editing the chapter list."""

    name = ShowQueue.init_log()
    ryw_view.print_header_logo()
    print '<TITLE>Edit the Chapter List</TITLE>'

    success,objID,version = ryw.get_obj_str()
    if not success:
        ryw.give_bad_news('ChapterListForm: failed to get objstr.',
                          logging.critical)
        DisplaySelection.exit_now(1)

    success,searchFile,reverseLists = \
        ReverseLists.open_searchfile_reverselists(
        'DisplaySelection.main:')
    if not success:
        DisplaySelection.exit_now(1)

    print '<BR><B>Edit chapter names for this selection:</B><BR><BR>'

    success = DisplaySelection.print_title(objID, version, name, searchFile)
    if not success:
        DisplaySelection.exit_now(1)

    ryw.db_print2('<BR>ChapterListForm.py entered.<BR>', 38)
    
    nameTriple = DisplaySelection.get_file_paths2(
        objID, version, searchFile = searchFile)
    if not nameTriple:
        DisplaySelection.exit_now(1)
    rfpath,chapterListPath,chapterFullName = nameTriple
    if not rfpath:
        DisplaySelection.exit_now(1)

    reqList = ShowQueue.read_list(rfpath)
    if not reqList:
        ryw.give_news('This selection is empty.<BR>', logging.info)
        print '<BR>'
        print_links(objID, version, name)
        DisplaySelection.exit_now(0)

    ryw.db_print2('ChapterListForm.py: gotten selection list.', 38)

    success,chapterList = ChapterList.create_and_initialize(
        objID + '#' + str(version),
        reqList, searchFile, reverseLists,
        chapterFullName)
    if not success:
        ryw.give_bad_news('ChapterList.create_and_initialize failed: ' +
                          objID + '#' + str(version), logging.error)
        DisplaySelection.exit_now(1)

    page = chapterList.make_form_string()
    print page
    
    ryw_view.print_footer()

    reverseLists.done()
    searchFile.done()
Пример #18
0
	def generate(self):
            """Main Browse View function."""
            ryw.print_header()
            self.print_initialHTML()
            form = cgi.FieldStorage()
            #	setup_logging()

            viewroot = form.getfirst('viewroot', '')
            if not viewroot:
                ryw.give_bad_news('viewroot not found',logging.error)
                sys.exit(1)

            ryw.db_print2('Browse.generate: viewroot is: ' + viewroot, 61)
                          
            if viewroot[-1] == os.sep:
	       	viewroot = viewroot[:-1]

            relpath = form.getfirst('relpath', os.sep)
            ryw.db_print2('Browse.generate: relpath1: ' + relpath, 61)
            relpath = ryw_bizarro.fix_browse_rel_path(relpath)
            ryw.db_print2('Browse.generate: relpath2: ' + relpath, 61)
            
            if relpath[0] != os.sep:
	       	relpath = os.sep + relpath
            if relpath[-1] != os.sep:
	       	relpath = relpath + os.sep

            ryw.db_print2('Browse.generate: relpath3: ' + relpath, 61)
            path = viewroot + relpath

            self.viewroot = viewroot
            self.relpath = relpath

            # path must be a directory

            if not os.path.exists(path):
	       	ryw.give_news('path no longer exists: ' + path,
	       		      logging.warning)
	       	sys.exit(1)
            ll = os.listdir(path)

            #success,searchFile = ryw.open_search_file(
            #    self.scriptName + ':', self.logDir, self.logFile,
            #    self.searchFile, False)
            #if not success:
            #    sys.exit(1)

            count=0

            title = relpath[1:-1]
            title = title.replace("\\"," &raquo; ")
            #print "<H2>The Digital StudyHall</H2>"
            ryw_view.print_logo()
            if title != "":
	       	print "<H3> content repository: %s </H3>" % (title,)
            else:
                print "<H3> content repository: </H3>"

            print "<TABLE border=0 width=100%><TR>"
            for i in ll:
                if not os.path.isfile(path+i):
                    print '<td width=20%%><A HREF="%s?viewroot=%s&relpath=%s%s"><img src="/icons/folder.gif" border=0><br>%s</A></td>' % (self.scriptName,viewroot,relpath,i,i)
                    count += 1
                    if (count == 5):
                        print "</TR><TR>"
                        count = 0
            while (count < 5):
	       	print "<td width=20%>&nbsp;</td>"
	       	count += 1
            print "</TR></TABLE>"
				      
				
            metalist = []

            for i in ll:
            
	       	if os.path.isfile(path + i):
                    # get its metadata from server and add option
                    # for 'add to downloadqueue'
                    f = open(path + i)
                    line = f.readline()
                    f.close()
                    if line[-1] == '\n':
                        line = line[:-1]
                    objname, version = line.split('#')
                    version = int(version)

                    #success,d = searchFile.get_meta(objname,
                    #				       version)
                    success,d = ryw.get_meta(self.absObjStoreRoot,
                                             objname,
                                             version)
                    if not success:
                        logging.warning(
                            self.scriptName + ': get_meta failed: ' +
                            objname + ' ' + str(version))
                        continue
			  
                    metalist.append(d)


            metalist = ryw.sortmeta(metalist)

            success,searchFile,reverseLists = \
                ReverseLists.open_searchfile_reverselists(
                    'Browse.generate:')
            if not success:
                sys.exit(1)

            displayObject = ryw_view.DisplayObject(
                self.Root, calledByVillageSide = self.calledByVillageSide,
                missingFileFunc = reqDownloadFunc,
                searchFile = searchFile,
                reverseLists = reverseLists)

            displayObject.begin_print()
            for i in metalist:
                #self.generate_row(d)
                displayObject.show_an_object_compact(i)
		      
            displayObject.end_print()
            self.print_footer()
            searchFile.done()
            reverseLists.done()
def main():

    name = ShowQueue.init_log('DisplayVersions')
    ryw_view.print_header_logo()
    print '<TITLE>Display All Versions</TITLE>'

    form = cgi.FieldStorage()
    objID = form.getfirst('objid', '')

    if not objID:
        ryw.give_bad_news(
            'DisplayVersions: no objID given.', logging.error)
        exit_now(1)
    else:
        ryw.db_print_info_browser('DisplayVersions: objID = ' + objID, 32)

    success,searchFile,reverseLists = \
        ReverseLists.open_searchfile_reverselists(
        'DisplaySelection.main:')
    if not success:
        exit_now(1)

    print_title()

    success,allVersions = searchFile.get_all_version_meta(objID)
    if not success:
        ryw.give_bad_news(
            'DisplayVersion: searchFile.get_all_version_meta failed: ' +
            objID, logging.error)
        exit_now(1)    

    numVers = len(allVersions)

    if numVers < 1:
        ryw.give_bad_news(
            'DisplayVersions: no version found.', logging.error)
        exit_now(1)
    
    metaList = allVersions.values()
    ryw.db_print_info_browser('DisplayVersions: ' + repr(metaList), 32)
    metaList = ryw.sortmeta(metaList)

    displayObject = ryw_view.DisplayObject(
        RepositoryRoot,
        calledByVillageSide = False,
        missingFileFunc = Browse.reqDownloadFunc,
        searchFile = searchFile,
        reverseLists = reverseLists)

    print "<BR><B><FONT SIZE=2>Displaying " + str(numVers) + \
          " version(s) of the object.</FONT></B>"

    displayObject.begin_print()
    for meta in metaList:
        displayObject.show_an_object_compact(meta)
    displayObject.end_print()

    ryw_view.print_footer()

    reverseLists.done()
    searchFile.done()
def main():
    ryw.check_logging(os.path.join(RepositoryRoot, 'WWW', 'logs'),
                      'upload.log')
    logging.debug('CurrSelToThisSel: entered...')
    ryw_view.print_header_logo()


    success,objID,version = ryw.get_obj_str()
    if not success:
        ryw.give_bad_news('CurrSelToThisSel: failed to get objstr.',
                          logging.critical)
        DisplaySelection.exit_now(1)
    
    success,searchFile,reverseLists = \
        ReverseLists.open_searchfile_reverselists('CurrSelToThisSel:')
    if not success:
        ryw.give_bad_news('CurrSelToThisSel: ' +
                          'open_searchfile_reverselists failed.',
                          logging.critical)
        DisplaySelection.exit_now(1)
    

    rfpath = DisplaySelection.get_file_path(
        objID, version, searchFile = searchFile)
    if not rfpath:
        ryw.give_bad_news(
            'CurrSelToThisSel: no selection file name found.',
            logging.error)
        DisplaySelection.exit_now(1)
    oldContainees = ShowQueue.read_list(rfpath)

    queueName = DeleteRepReq.get_queue_name()
    if not queueName:
        ryw.give_bad_news(
            'CurrSelToThisSel: failed to get current selection file name.',
            logging.error)
        DisplaySelection.exit_now(1)
    newContainees = ShowQueue.read_list(queueName)

    try:
        shutil.copyfile(queueName, rfpath)
    except:
        ryw.give_bad_news('CurrSelToThisSel: failed to overwrite: ' +
                          queueName + ' -> ' + rfpath,
                          logging.critical)
        DisplaySelection.exit_now(1)

    ryw.give_news(
        'The current selection successfully loaded as this selection.',
        logging.info)
    ryw.give_news('You may want to reload the page containing '+
                  'this selection.', logging.info)

    success = reverseLists.redefine_container(
        objID+'#'+str(version), oldContainees, newContainees)
    if not success:
        ryw.give_bad_news('CurrSelToThisSel: ' +
                          'reverseLists.redefine_container failed.',
                          logging.critical)

    reverseLists.done()
    searchFile.done()
    ryw_view.print_footer()