def get_meta(searchFile, objID, version, repositoryRoot):
    success,meta = searchFile.get_meta(objID, version)
    if success:
        #
        # I'm doing this to hardwire all
        # places of gettting objectstoreroot.
        #
        #return (meta, meta['objectstore'])
        return (meta, ryw.hard_wired_objectstore_root())
    
    logging.warning(
        'ryw_meta.get_meta: not finding it in the SearchFile: ' +
        objID + ' # ' + str(version) + ', but attempting to continue')
    
    #
    # look for the hardwired objectstore root.  not nice but...
    #
    objroot = os.path.join(repositoryRoot, 'WWW', 'ObjectStore')
    if not os.path.exists(objroot):
        ryw.give_bad_news(
            'DeleteObject.get_meta: even the hardwired root does not exist: '+
            objroot, logging.critical)
        return (None, None)
    
    success,meta = ryw.get_meta(objroot, objID, version)
    if not success:
        logging.warning(
            'ryw.get_meta: failed to read metadata from objstore: '+
            objID + ' # ' + str(version))
        return (None, objroot)

    return (meta, objroot)
def out_obj_dir_name(objStoreRoot, objname, version, currCounter):

    if currCounter >= 9999:
        ryw.give_bad_news('out_obj_dir_name: counter exceeded 9999.',
                          logging.warning)
        #return (False, None, currCounter)
    
    success,meta = ryw.get_meta(objStoreRoot, objname, version)
    if not success:
        ryw.give_bad_news('out_obj_dir_name: failed to get meta data: ' +
                          objname + '#' + str(version), logging.error)
        return (False, None, currCounter)

    if meta.has_key('content_alias'):
        author = meta['content_alias']
        author = stripStr(author)
    elif meta.has_key('author_name'):
        author = meta['author_name']
        author = stripStr(author)
        author = re.sub('(^[mM]s)|(^[mM]r)|(^[mM]rs)|(^[mM]iss)', '', author)
    else:
        author = 'unknown'

    prefix = str(currCounter).zfill(2)
    dirName = prefix + author
    dirName = dirName[:32]
    logging.debug('out_obj_dir_name: dirName is: ' + dirName)
        
    return (True, dirName, currCounter + 1)
def get_paths(objID, version):
    oRoot = os.path.join(RepositoryRoot, 'WWW', 'ObjectStore')
    try:
        success,meta = ryw.get_meta(oRoot, objID, version)
        if not success:
            ryw.give_bad_news(
                'CreateNewThumbDir.get_paths: ryw.get_meta failed: ' +
                repr(meta), logging.error)
            return (False,None,None)

        success,dataURL,auxiURL,auxiDir = ryw_view.get_server_URLs(meta)
        if not success:
            ryw.give_bad_news(
                'CreateNewThumbDir.get_paths: get_server_URLs failed: ' +
                repr(meta), logging.error)
            return (False,None,None)
        return (True,auxiURL,auxiDir)
    except:
        ryw.give_bad_news(
            'CreateNewThumbDir.get_paths: failed to get server URLs: ' +
            objID + '#' + str(version), logging.error)
        return (False,None,None)
	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("\\"," » ")
            #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()