def do_delete(objID, version, searchFile=None):
    """the optional searchFile argument is for cases of calling this
    thing in a loop: the first time, searchFile is None, so we do
    an open of the searchFile, and this gets returned to the caller,
    and the caller (in a loop) gets to reuse the searchFile argument."""    

    if not searchFile:
        searchFile = ryw_meta.open_search_file(RepositoryRoot)
        ryw.db_print('DeleteObject.do_delete: opening searchFile.', 18)
    else:
        ryw.db_print('DeleteObject.do_delete: reusing searchFile.', 18)
        
    if not searchFile:
        return (False, None)

    meta,objroot = ryw_meta.get_meta(searchFile, objID, version,
                                     RepositoryRoot)
    if not meta and not objroot:
        ryw.give_bad_news('do_delete: no meta, no objroot, giving up...',
                          logging.critical)
        searchFile.done()
        return (False, searchFile)

    #
    # try to continue deletion even if we can't get metadata.
    #

    paths = ryw_meta.get_paths(objroot, objID, version, meta, RepositoryRoot)
    if not paths:
        ryw.give_bad_news('do_delete: failed to get paths.',
                          logging.critical)
        searchFile.done()
        return (False, searchFile)

    if meta:
        #
        # hack.  I had a bug when the following function crashed
        # with meta=None
        # I didn't bother to understand what's going on.
        #
        process_reverse_lists(objID, version, meta, searchFile)

    remove_from_search_file(searchFile, objID, version)
    remove_paths(paths)
    searchFile.done()
    return (True, searchFile)
def get_path(objID, version, searchFile, repositoryRoot):
    """a helper function.
    a replacement for DisplaySelection.get_path().
    called by get_file_path() below."""
    
    success,meta = searchFile.get_meta(objID, version)
    if not success or not meta:
        ryw.give_bad_news(
            'ReverseLists.get_path: get_path failed.', logging.critical)
        return (False, None)

    objroot = ryw_meta.get_objectstore_root(repositoryRoot, meta)
    paths = ryw_meta.get_paths(objroot, objID, version,
                               meta, RepositoryRoot)
    if not paths:
        ryw.give_bad_news('ReverseLists.get_path: failed to get paths.',
                          logging.critical)
        return (False, None)

    return (True, paths[0])
def get_all_paths(objID, version, skipLock = False, searchFile = None,
             allowNullSearchFile = False):
    #searchFile = ryw_meta.open_search_file(RepositoryRoot)
    #if not searchFile:
    #    return (False, None)

    #meta,objroot = ryw_meta.get_meta(searchFile, objID, version,
    #                                 RepositoryRoot)
    #searchFile.done()

    if searchFile == None and not allowNullSearchFile:
        ryw.give_bad_news('DisplaySelection.get_path: warning, no ' +
                          'searchFile. ok but should fix.',
                          logging.warning)

    if searchFile:
        success,meta = searchFile.get_meta(objID, version)
        if success and meta:
            objroot = ryw_meta.get_objectstore_root(RepositoryRoot, meta)
    else:
        success,meta,objroot = ryw_meta.get_meta2(
            RepositoryRoot, objID, version, skipLk = skipLock)
        logging.warning('DisplaySelection.get_path: get_meta2 called.')

    if not success or (not meta and not objroot):
        ryw.give_bad_news(
            'DisplaySelection: no meta, no objroot, giving up...',
            logging.critical)
        return (False, None, None)

    paths = ryw_meta.get_paths(objroot, objID, version, meta, RepositoryRoot)
    if not paths:
        ryw.give_bad_news('DisplaySelection: failed to get paths.',
                          logging.critical)
        return (False, None, None)

    return (True, paths, meta)
def main():
    # initialization.
    print_header()
    form = cgi.FieldStorage()
    setup_logging()

    # cgi.print_form(form)

    success,objID,version = ryw.get_obj_str2(form)
    if not success:
        ryw_upload.quick_exit(1)
    logging.debug('EditObject: ' + objID + '#' + str(version))

    if not ryw_meta.check_required_fields(form):
        ryw_upload.quick_exit(1)

    success,meta,objroot = ryw_meta.get_meta2(RepositoryRoot,
                                                  objID, version)
    if not success:
        ryw_upload.quick_exit(1)



    reext = re_extract_or_not(form)
    if reext:
        paths = ryw_meta.get_paths(objroot, objID, version,
                                   meta, RepositoryRoot)
        if not paths:
            ryw.give_bad_news('EditObject: failed to get paths.',
                              logging.critical)
            ryw_upload.quick_exit(1)

        dataPath = paths[0]
        fileName = get_file_name(dataPath)
        if not fileName:
            reext = False



    success = ryw_meta.process_error_fields(form, meta)
    if not success:
        ryw_upload.quick_exit(1)

    ryw_meta.process_fields(form, meta)
    logging.debug('EditObjects: ' + repr(meta))

    meta = ryw_upload.get_change_date_time(meta)

    #ryw.give_news(repr(meta), logging.info)



    if reext:
        re_extract(dataPath, fileName, meta)


    success,searchFile = do_update_metadata(objroot, objID, version, meta)
    if not success:
        ryw_upload.quick_exit(1)


    show_one_server_object(meta, searchFile)
    ryw.give_good_news('edit completed.', logging.info)

    ryw_view.print_footer()

    if searchFile:
        searchFile.done()
    sys.exit(0)