def publish(self): identity = request.environ.get("repoze.who.identity") if identity: #Get list of vocabularies created by userid c.userid = identity['repoze.who.userid'] c.user_det = get_mediator_details(c.userid) vocabs = get_mediator_vocabs(c.userid) #Get status of vocab - is rdf, ready to convert to html, new rdf check, convert to html, html check c.vocab_list = {} for k, v in vocabs.iteritems(): files = get_vocab_files(k) description = {} for f, vals in files.iteritems(): if vals['format'] == 'application/rdf+xml': description = get_vocab_description(vals['path'], k) msgs = get_vocab_editorial_note(k) c.vocab_list[k] = description c.vocab_list[k]['files'] = files c.vocab_list[k]['uri'] = v[0] c.vocab_list[k]['svn'] = v[1] c.vocab_list[k]['note'] = msgs return render('/publish.html') else: session[ 'login_flash'] = "Please login to view vocabularies published and managed by you and to upload new vocabularies" session.save() destination = "/login?came_from=publish" return redirect(destination, code=303)
def publish(self): identity = request.environ.get("repoze.who.identity") if identity: #Get list of vocabularies created by userid c.userid = identity['repoze.who.userid'] c.user_det = get_mediator_details(c.userid) vocabs = get_mediator_vocabs(c.userid) #Get status of vocab - is rdf, ready to convert to html, new rdf check, convert to html, html check c.vocab_list = {} for k, v in vocabs.iteritems(): files = get_vocab_files(k) description = {} for f, vals in files.iteritems(): if vals['format'] == 'application/rdf+xml': description = get_vocab_description(vals['path'], k) msgs = get_vocab_editorial_note(k) c.vocab_list[k] = description c.vocab_list[k]['files'] = files c.vocab_list[k]['uri'] = v[0] c.vocab_list[k]['svn'] = v[1] c.vocab_list[k]['note'] = msgs return render('/publish.html') else: session['login_flash'] = "Please login to view vocabularies published and managed by you and to upload new vocabularies" session.save() destination = "/login?came_from=publish" return redirect(destination, code=303)
def generate(self, prefix): came_from = "/publish" identity = request.environ.get("repoze.who.identity") if not identity: session['login_flash'] = "Please login to convert vocabularies published and managed by you" session.save() destination = "/login?came_from=%s"%came_from return redirect(destination, code=303) #Check if userid has permissions for this vocab userid = identity['repoze.who.userid'] vocablist = get_mediator_vocabs(userid) if vocablist and not prefix in vocablist.keys(): session['welcome_flash'] = "You are not authorized to make any changes to %s"%prefix session.save() return redirect(url(controller='vocabs', action='publish'), code=303) params = request.params if not 'file' in params or not params['file']: session['welcome_flash'] = """No file was selected to modify""" session.save() return redirect(url(controller='vocabs', action='publish'), code=303) c.vocabprefix = prefix c.filename = params.get('file') #Get vocab properties vocab_properties = get_vocab_properties(c.vocabprefix) #Get vocab rdf file properties files = get_vocab_files(c.vocabprefix) rdf_vocab_properties = None for f, val in files.iteritems(): if val['name'] == c.filename and val['format'] == 'application/rdf+xml': rdf_vocab_properties = val rdf_vocab_properties['uri'] = f break #Check file exists if not rdf_vocab_properties or not os.path.isfile(rdf_vocab_properties['path']): session['welcome_flash'] = """Could not locate the file %s for %s"""%(c.filename, c.vocabprefix) session.save() return redirect(url(controller='vocabs', action='publish'), code=303) #Get editorial notes notes = get_vocab_editorial_note(c.vocabprefix) vocab_msgs = [] for (msg, recepient) in notes: if (not recepient) or recepient == c.filename: vocab_msgs.append(msg) #vocab_file_msgs.append(msg) if vocab_editorial_descriptions[5] in vocab_msgs: #TODO: Get the URI for the html file session['welcome_flash'] = "HTML file exists for %s"%c.vocabprefix session.save() return redirect(url(controller='vocabs', action='publish'), code=303) if not vocab_editorial_descriptions[3] in vocab_msgs: if vocab_editorial_descriptions[1] in vocab_msgs: session['welcome_flash'] = "%s in %s"%(vocab_editorial_descriptions[1], c.vocabprefix) session.save() return redirect(url(controller='vocabs', action='publish'), code=303) if vocab_editorial_descriptions[2] in vocab_msgs: session['welcome_flash'] = "%s in %s"%(vocab_editorial_descriptions[2], c.filename) session.save() return redirect(url(controller='vocabs', action='publish'), code=303) if vocab_editorial_descriptions[4] in vocab_msgs: session['welcome_flash'] = "%s in %s"%(vocab_editorial_descriptions[4], c.filename) session.save() return redirect(url(controller='vocabs', action='publish'), code=303) del_status(c.vocabprefix, rdf_vocab_properties['uri'], 'skos:editorialNote', vocab_editorial_descriptions[3]) #Check if file is rdf if not check_rdf(rdf_vocab_properties['path']): add_status(c.vocabprefix, rdf_vocab_properties['uri'], 'skos:editorialNote', vocab_editorial_descriptions[2]) session['welcome_flash'] = "Could not parse %s as an rdf file"%c.filename session.save() return redirect(url(controller='vocabs', action='publish'), code=303) html_vocab_properties = {} html_vocab_properties['format'] = 'text/html' html_vocab_properties['name'] = "%s.html"%os.path.splitext(rdf_vocab_properties['name'])[0] (head, tail) = os.path.split(rdf_vocab_properties['path']) html_vocab_properties['path'] = os.path.join(head, html_vocab_properties['name']) uri_parts = rdf_vocab_properties['uri'].split('/') for i in range(len(uri_parts)-1, -1, -1): if uri_parts[i] == rdf_vocab_properties['name']: uri_parts[i] = html_vocab_properties['name'] break html_vocab_properties['uri'] = '/'.join(uri_parts) loc = rdf_vocab_properties['path'] dest = html_vocab_properties['path'] #try: # s = SpecGen(loc, c.vocabprefix, vocab_properties['preferredNamespaceUri'], ag.conversion_template, dest) # s.create_file() #except Exception, e: # add_status(c.vocabprefix, rdf_vocab_properties['uri'], 'skos:editorialNote', vocab_editorial_descriptions[4]) # add_status(c.vocabprefix, rdf_vocab_properties['uri'], 'skos:note', str(e)) # session['welcome_flash'] = """%s <br>%s"""%(vocab_editorial_descriptions[4], str(e)) # session.save() # return redirect(url(controller='vocabs', action='publish'), code=303) s = SpecGen(loc, c.vocabprefix, vocab_properties['preferredNamespaceUri'], ag.conversion_template, dest) s.create_file() add_file_to_vocab_status(c.vocabprefix, html_vocab_properties) add_status(c.vocabprefix, rdf_vocab_properties['uri'], 'skos:editorialNote', vocab_editorial_descriptions[5]) add_status(c.vocabprefix, html_vocab_properties['uri'], 'dcterms:isFormatOf', rdf_vocab_properties['uri']) message = ["""Generated the html file %s"""%html_vocab_properties['uri']] #Commit svn changes (status1, msg1) = svn_add(dest, "Created HTML file") if not status1: message.append("""Error committing to SVN: %s"""%msg1) (status2, msg2) = svn_commit([dest], "Generated HTML file. Committing changes") if not status2: message.append("""Error committing to SVN: %s"""%msg2) session['welcome_flash'] = '<br>'.join(message) session.save() return redirect(url(controller='vocabs', action='publish'), code=303)
def generate(self, prefix): came_from = "/publish" identity = request.environ.get("repoze.who.identity") if not identity: session[ 'login_flash'] = "Please login to convert vocabularies published and managed by you" session.save() destination = "/login?came_from=%s" % came_from return redirect(destination, code=303) #Check if userid has permissions for this vocab userid = identity['repoze.who.userid'] vocablist = get_mediator_vocabs(userid) if vocablist and not prefix in vocablist.keys(): session[ 'welcome_flash'] = "You are not authorized to make any changes to %s" % prefix session.save() return redirect(url(controller='vocabs', action='publish'), code=303) params = request.params if not 'file' in params or not params['file']: session['welcome_flash'] = """No file was selected to modify""" session.save() return redirect(url(controller='vocabs', action='publish'), code=303) c.vocabprefix = prefix c.filename = params.get('file') #Get vocab properties vocab_properties = get_vocab_properties(c.vocabprefix) #Get vocab rdf file properties files = get_vocab_files(c.vocabprefix) rdf_vocab_properties = None for f, val in files.iteritems(): if val['name'] == c.filename and val[ 'format'] == 'application/rdf+xml': rdf_vocab_properties = val rdf_vocab_properties['uri'] = f break #Check file exists if not rdf_vocab_properties or not os.path.isfile( rdf_vocab_properties['path']): session[ 'welcome_flash'] = """Could not locate the file %s for %s""" % ( c.filename, c.vocabprefix) session.save() return redirect(url(controller='vocabs', action='publish'), code=303) #Get editorial notes notes = get_vocab_editorial_note(c.vocabprefix) vocab_msgs = [] for (msg, recepient) in notes: if (not recepient) or recepient == c.filename: vocab_msgs.append(msg) #vocab_file_msgs.append(msg) if vocab_editorial_descriptions[5] in vocab_msgs: #TODO: Get the URI for the html file session[ 'welcome_flash'] = "HTML file exists for %s" % c.vocabprefix session.save() return redirect(url(controller='vocabs', action='publish'), code=303) if not vocab_editorial_descriptions[3] in vocab_msgs: if vocab_editorial_descriptions[1] in vocab_msgs: session['welcome_flash'] = "%s in %s" % ( vocab_editorial_descriptions[1], c.vocabprefix) session.save() return redirect(url(controller='vocabs', action='publish'), code=303) if vocab_editorial_descriptions[2] in vocab_msgs: session['welcome_flash'] = "%s in %s" % ( vocab_editorial_descriptions[2], c.filename) session.save() return redirect(url(controller='vocabs', action='publish'), code=303) if vocab_editorial_descriptions[4] in vocab_msgs: session['welcome_flash'] = "%s in %s" % ( vocab_editorial_descriptions[4], c.filename) session.save() return redirect(url(controller='vocabs', action='publish'), code=303) del_status(c.vocabprefix, rdf_vocab_properties['uri'], 'skos:editorialNote', vocab_editorial_descriptions[3]) #Check if file is rdf if not check_rdf(rdf_vocab_properties['path']): add_status(c.vocabprefix, rdf_vocab_properties['uri'], 'skos:editorialNote', vocab_editorial_descriptions[2]) session[ 'welcome_flash'] = "Could not parse %s as an rdf file" % c.filename session.save() return redirect(url(controller='vocabs', action='publish'), code=303) html_vocab_properties = {} html_vocab_properties['format'] = 'text/html' html_vocab_properties['name'] = "%s.html" % os.path.splitext( rdf_vocab_properties['name'])[0] (head, tail) = os.path.split(rdf_vocab_properties['path']) html_vocab_properties['path'] = os.path.join( head, html_vocab_properties['name']) uri_parts = rdf_vocab_properties['uri'].split('/') for i in range(len(uri_parts) - 1, -1, -1): if uri_parts[i] == rdf_vocab_properties['name']: uri_parts[i] = html_vocab_properties['name'] break html_vocab_properties['uri'] = '/'.join(uri_parts) loc = rdf_vocab_properties['path'] dest = html_vocab_properties['path'] #try: # s = SpecGen(loc, c.vocabprefix, vocab_properties['preferredNamespaceUri'], ag.conversion_template, dest) # s.create_file() #except Exception, e: # add_status(c.vocabprefix, rdf_vocab_properties['uri'], 'skos:editorialNote', vocab_editorial_descriptions[4]) # add_status(c.vocabprefix, rdf_vocab_properties['uri'], 'skos:note', str(e)) # session['welcome_flash'] = """%s <br>%s"""%(vocab_editorial_descriptions[4], str(e)) # session.save() # return redirect(url(controller='vocabs', action='publish'), code=303) s = SpecGen(loc, c.vocabprefix, vocab_properties['preferredNamespaceUri'], ag.conversion_template, dest) s.create_file() add_file_to_vocab_status(c.vocabprefix, html_vocab_properties) add_status(c.vocabprefix, rdf_vocab_properties['uri'], 'skos:editorialNote', vocab_editorial_descriptions[5]) add_status(c.vocabprefix, html_vocab_properties['uri'], 'dcterms:isFormatOf', rdf_vocab_properties['uri']) message = [ """Generated the html file %s""" % html_vocab_properties['uri'] ] #Commit svn changes (status1, msg1) = svn_add(dest, "Created HTML file") if not status1: message.append("""Error committing to SVN: %s""" % msg1) (status2, msg2) = svn_commit([dest], "Generated HTML file. Committing changes") if not status2: message.append("""Error committing to SVN: %s""" % msg2) session['welcome_flash'] = '<br>'.join(message) session.save() return redirect(url(controller='vocabs', action='publish'), code=303)