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)
def get_file_path(searchFile = None, allowNullSearchFile = False):
    success,objID,version = ryw.get_obj_str()
    if not success:
        ryw.give_bad_news('ThisSelToCurrSel: failed to get objstr.',
                          logging.critical)
        return None

    rfpath = DisplaySelection.get_file_path(
        objID, version, searchFile = searchFile,
        allowNullSearchFile = allowNullSearchFile)
    return rfpath
def delete_request(queuePath):
    print_header()
    success,objID,version = ryw.get_obj_str()
    if not success:
        print "Deletion of request failed."
        sys.exit(1)
    reqStr = objID + '#' + str(version)
    
    success = do_delete(queuePath, reqStr)
    if success:
        sys.stdout.write("True")
    else:
        print "Deletion of request failed."
        sys.exit(1)
def main():
    ryw.check_logging(os.path.join(RepositoryRoot, 'WWW', 'logs'),
                      'upload.log')
    logging.debug('DeleteObject: entered...')

    success,objID,version = ryw.get_obj_str()
    if not success:
        sys.exit(1)

    if do_show(objID, version):
        pass
	#sys.stdout.write("True")
        #ryw.give_good_news('Delete object: apparent success', logging.info)

    sys.exit(0)
def init(enteredMsg, headerMsg):
    ryw.check_logging(os.path.join(RepositoryRoot, 'WWW', 'logs'),
                      'upload.log')
    logging.debug(enteredMsg)
    ryw.print_header()
    print headerMsg

    success,objID,version = ryw.get_obj_str()
    if not success:
        return (False, None, None)

    logging.debug('CreateNewThumbDir.init: objstr: ' + objID + '#' +
                  str(version))
    print ryw_view.begin_print_str()
    return (True, objID, version)
def main():
    ryw.check_logging(os.path.join(RepositoryRoot, 'WWW', 'logs'),
                      'upload.log')
    logging.debug('DisplayObject: entered...')
    ryw_view.print_header_logo()

    print "<TITLE>Displaying an Object</TITLE>"

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

    if do_show(objID, version):
        pass
	#sys.stdout.write("True")
        #ryw.give_good_news('Delete object: apparent success', logging.info)

    DisplaySelection.exit_now(0)
def main():
    ryw.check_logging(os.path.join(RepositoryRoot, 'WWW', 'logs'),
                      'upload.log')
    logging.debug('DeleteObject: entered...')

    ryw.print_header()

    success,objID,version = ryw.get_obj_str()
    if not success:
        sys.exit(1)

    success,searchFile = do_delete(objID, version)
    if success:
	sys.stdout.write("True")
        #ryw.give_good_news('Delete object: apparent success', logging.info)

    if searchFile:
        searchFile.done()

    sys.exit(0)
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()
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()
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()