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)
session.save() return redirect(url(controller='vocabs', action='publish'), code=303) #Check file exists if not os.path.isfile(vocabfile): shutil.rmtree(vocabdir) session['welcome_flash'] = """Error uploading the file %s"""%filename session.save() return redirect(url(controller='vocabs', action='publish'), code=303) message = [] #====================================================== #Get the prefix and namespace uri from the vocab identifier = None ns_prefix = None c.base_URI = None if check_rdf(vocabfile) or check_n3(vocabfile): (identifier, c.base_URI, ns_prefix) = get_vocab_base(vocabfile) if ns_prefix: if refvocab and filename == 'vocab': filename = ns_prefix newvocabfile = os.path.join(vocabdir, filename.lstrip(os.sep)) os.rename(vocabfile, newvocabfile) vocabfile = newvocabfile newvocabdir = "%s/%s"%(ag.vocabulariesdir, ns_prefix) if os.path.isdir(newvocabdir): message = [] message.append("""Vocabulary added to <a href="http://vocab.ox.ac.uk/%s">%s</a>"""%c.vocabprefix) message.append("""Extracted the namespace prefix <b>%s</b> from the \ vocabulary file. A vocabulary already exists with this obtained prefix. \ See <a href="http://vocab.ox.ac.uk/%s">%s</a>"""%(ns_prefix, ns_prefix, ns_prefix)) else:
#Check file exists if not os.path.isfile(vocabfile): shutil.rmtree(vocabdir) session[ 'welcome_flash'] = """Error uploading the file %s""" % filename session.save() return redirect(url(controller='vocabs', action='publish'), code=303) message = [] #====================================================== #Get the prefix and namespace uri from the vocab identifier = None ns_prefix = None c.base_URI = None if check_rdf(vocabfile) or check_n3(vocabfile): (identifier, c.base_URI, ns_prefix) = get_vocab_base(vocabfile) if ns_prefix: if refvocab and filename == 'vocab': filename = ns_prefix newvocabfile = os.path.join(vocabdir, filename.lstrip(os.sep)) os.rename(vocabfile, newvocabfile) vocabfile = newvocabfile newvocabdir = "%s/%s" % (ag.vocabulariesdir, ns_prefix) if os.path.isdir(newvocabdir): message = [] message.append( """Vocabulary added to <a href="http://vocab.ox.ac.uk/%s">%s</a>""" % c.vocabprefix) message.append( """Extracted the namespace prefix <b>%s</b> from the \