[Volute] r5262 - trunk/projects/semantics/vocabularies

Volute commit messages volutecommits at g-vo.org
Tue Dec 11 11:56:34 CET 2018


Author: msdemlei
Date: Tue Dec 11 11:56:33 2018
New Revision: 5262

Log:
vocabularies: porting convert.py to new directory organisation.

Modified:
   trunk/projects/semantics/vocabularies/   (props changed)
   trunk/projects/semantics/vocabularies/convert.py

Modified: trunk/projects/semantics/vocabularies/convert.py
==============================================================================
--- trunk/projects/semantics/vocabularies/convert.py	Tue Dec 11 11:38:25 2018	(r5261)
+++ trunk/projects/semantics/vocabularies/convert.py	Tue Dec 11 11:56:33 2018	(r5262)
@@ -13,7 +13,6 @@
 are mandatory.  Here's how to configure a vocabulary myterms::
 
 	[myterms]
-	baseuri: "http://www.ivoa.net/rdf/myterms"
 	timestamp: 2016-08-17
 	title: My terms as an example
 	description: This is a collection of terms not actually used 
@@ -52,7 +51,7 @@
 
 
 MANDATORY_KEYS = frozenset([
-	"baseuri", "timestamp", "title", "description", "authors"])
+	"timestamp", "title", "description", "authors"])
 
 HT_ACCESS_TEMPLATE = """# .htaccess for content negotiation
 
@@ -336,22 +335,23 @@
 
 ########### Parsing our input files, generating our output files
 
-def _make_vocab_meta(parser, vocab_name):
-	"""returns a vocabulary dictionary for vocab_name from a ConfigParser
+def _make_vocab_meta(parser, vocab_path, root_uri):
+	"""returns a vocabulary dictionary for vocab_path from a ConfigParser
 	instance parser.
 
 	This makes sure all the necessary keys are present and that the
 	implied terms file is readable; also, it generates the terms file
 	name.
 	"""
-	vocab_def = dict(parser.items(vocab_name))
+	vocab_def = dict(parser.items(vocab_path))
 	missing_keys = MANDATORY_KEYS-set(vocab_def)
 	if missing_keys:
 		raise ReportableError("Vocabulary definition for {} incomplete:"
-			" {} missing.".format(vocab_name, ", ".join(missing_keys)))
+			" {} missing.".format(vocab_path, ", ".join(missing_keys)))
 
-	vocab_def["name"] = vocab_name
-	vocab_def["terms_fname"] = vocab_name+".terms"
+	vocab_def["baseuri"] = root_uri+vocab_path
+	vocab_def["name"] = vocab_path.split("/")[-1]
+	vocab_def["terms_fname"] = os.path.join(vocab_path, "terms.csv")
 
 	try:
 		with open(vocab_def["terms_fname"]) as f:
@@ -364,7 +364,7 @@
 	return vocab_def
 
 
-def read_meta(input_name):
+def read_meta(input_name, root_uri):
 	"""reads the vocabulary configuration and returns a sequence
 	of vocabulary definition dicts.
 	"""
@@ -377,8 +377,8 @@
 			"Cannot open or read vocabulary configuration {}".format(input_name))
 	
 	meta = []
-	for vocab_name in parser.sections():
-		meta.append(_make_vocab_meta(parser, vocab_name))
+	for vocab_path in parser.sections():
+		meta.append(_make_vocab_meta(parser, vocab_path, root_uri))
 	return meta
 
 
@@ -534,15 +534,13 @@
 	return terms
 
 
-def build_vocab(vocab_def, install_root):
-	"""builds, in a subdirectory named <name>/<timestamp>, all files
+def build_vocab(vocab_def, dest_root):
+	"""builds, in a subdirectory named <dest_root>/<name>/<timestamp>, all files
 	necessary on the server side.
 
 	It also puts an .htaccess into the <name>/ directory that will redirect 
 	clients to the appropriate files of this release based using content 
 	negotiation.
-
-	install_root is the URI of the directory the result will reside in.
 	"""
 	try:
 		terms = parse_terms(vocab_def["terms_fname"])
@@ -551,14 +549,15 @@
 			"The following error was raised from within {}:\n".format(
 				vocab_def["terms_fname"]))
 		raise
-	dest_dir = "{}/{}".format(vocab_def["name"], vocab_def["timestamp"])
 
-	with work_dir(dest_dir):
+	with work_dir(
+			os.path.join(dest_root, vocab_def["name"], vocab_def["timestamp"])):
 		write_ontology(vocab_def, terms)
 		write_html(vocab_def, terms)
 
-	with work_dir(vocab_def["name"]):
-		write_htaccess(vocab_def, install_root)
+	with work_dir(
+			os.path.join(dest_root, vocab_def["name"])):
+		write_htaccess(vocab_def, terms)
 		write_meta_inf(vocab_def)
 
 
@@ -569,28 +568,34 @@
 	parser.add_argument("vocab_config", 
 		help="Name of the vocabularies configuration file.",
 		type=str)
-	parser.add_argument("--install-root", 
-		help="Use URI instead of"
+	parser.add_argument("--root-uri", 
+		help="Use URI as the common root of the vocabularies instead of"
 		" the official IVOA location as the root of the vocabulary"
-		" hierarchy.  This is for test installations.",
+		" hierarchy.  This is for test installations at this point.",
 		action="store", 
-		dest="install_root", 
+		dest="root_uri", 
 		default="http://www.ivoa.net/rdf/",
 		metavar="URI")
+	parser.add_argument("--dest-dir",
+		help="Write HTML and RDF output files to PATH.",
+		action="store",
+		dest="dest_dir",
+		default="build",
+		metavar="PATH")
 	args = parser.parse_args()
 	
-	if not args.install_root.endswith("/"):
-		args.install_root = args.install_root+"/"
+	if not args.root_uri.endswith("/"):
+		args.root_uri = args.root_uri+"/"
 	
 	return args
 
 
 def main():
 	args = parse_command_line()
-	meta = read_meta(args.vocab_config)
+	meta = read_meta(args.vocab_config, args.root_uri)
 		
 	for vocab_def in meta:
-		build_vocab(vocab_def, args.install_root)
+		build_vocab(vocab_def, args.dest_dir)
 
 
 if __name__=="__main__":


More information about the Volutecommits mailing list