Commit 2d46d88e authored by Matthieu Muffato's avatar Matthieu Muffato
Browse files

Only create the temporary files once, and under _build/ so that they don't clutter the filesystem

parent 3cca9c10
......@@ -84,36 +84,52 @@ display_config_json = json.dumps( {
} )
json_filename = None
pipeconfig_filename = None
def generate_dot_diagram(pipeconfig_content):
# A temporary file for the JSON config
json_fh = tempfile.NamedTemporaryFile(delete = False)
#print "json_fh:",
print >> json_fh, display_config_json
global json_filename
if json_filename is None:
json_fh = tempfile.NamedTemporaryFile(dir = "_build", delete = False)
#print "json_fh:",
print >> json_fh, display_config_json
json_filename =
# eHive's default configuration file
default_config_file = os.environ["EHIVE_ROOT_DIR"] + os.path.sep + "hive_config.json"
# A temporary file for the sample PipeConfig
pipeconfig_fh = tempfile.NamedTemporaryFile(suffix = '.pm', dir = os.getcwd(), delete = False)
package_name = os.path.basename([:-3]
global pipeconfig_filename
if pipeconfig_filename is None:
pipeconfig_fh = tempfile.NamedTemporaryFile(suffix = '.pm', dir = "_build", delete = False)
pipeconfig_filename =
pipeconfig_fh = open(pipeconfig_filename, "w")
package_name = "_build::" + os.path.basename([:-3]
#print "pipeconfig:",, package_name
print >> pipeconfig_fh, pipeconfig_template % (package_name, pipeconfig_content)
# Run generate_graph and read the content of the dot file
graph_path = os.path.join(os.environ["EHIVE_ROOT_DIR"], "scripts", "")
dotcontent = subprocess.check_output([graph_path, "-pipeconfig",, "--format", "dot", "-config_file", default_config_file, "-config_file",], stderr=sys.stderr)
# Remove the temporary files
dotcontent = subprocess.check_output([graph_path, "-pipeconfig",, "--format", "dot", "-config_file", default_config_file, "-config_file", json_filename], stderr=sys.stderr)
return dotcontent
def cleanup_tmp_files(app, exception):
if json_filename is not None:
if pipeconfig_filename is not None:
## Register the extension
def setup(app):
app.add_directive('hive_diagram', HiveDiagramDirective)
app.connect('build-finished', cleanup_tmp_files)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment