def save(self): self.plot.finish() if not self.plot is None: for filename in self.plotdict["output_filenames"]: self.plot.save(filename) log.info("Created plot \"%s\"." % filename) if not (self.plotdict["live"]==None): # if 'userpc', get the username and name of desktop machine if self.plotdict["userpc"]: userpc = ("%s@%s" % (tools.get_environment_variable("USER"), tools.get_environment_variable("HARRY_USERPC"))).replace("\n", "") for output_filename in self.plotdict["output_filenames"]: if self.plotdict["userpc"]: extrafunctions.show_plot_userpc(output_filename, self.plotdict["live"], tools.get_environment_variable('USER'), userpc) else: extrafunctions.show_plot(output_filename, self.plotdict["live"]) # web plotting # TODO: make this more configurable if users want to user other webspaces etc. if self.plotdict["www"] != None: self.webplotting( www = self.plotdict["www"], output_dir = self.plotdict["output_dir"], output_filenames = self.plotdict["output_filenames"], www_text= self.plotdict["www_text"], www_title = self.plotdict["www_title"], additional_output_files = self.plotdict["additional_output_files"] if "additional_output_files" in self.plotdict else False, save_legend = self.plotdict.get("save_legend", False), export_json = self.plotdict["export_json"] ) return self.plotdict["output_filenames"]
def save(self): self.plot.finish() if not self.plot is None: for filename in self.plotdict["output_filenames"]: self.plot.save(filename) log.info('Created plot "%s".' % filename) if not (self.plotdict["live"] == None): # if 'userpc', get the username and name of desktop machine if self.plotdict["userpc"]: userpc = ( "%s@%s" % (tools.get_environment_variable("USER"), tools.get_environment_variable("HARRY_USERPC")) ).replace("\n", "") for output_filename in self.plotdict["output_filenames"]: if self.plotdict["userpc"]: extrafunctions.show_plot_userpc( output_filename, self.plotdict["live"], tools.get_environment_variable("USER"), userpc ) else: extrafunctions.show_plot(output_filename, self.plotdict["live"]) # web plotting # TODO: make this more configurable if users want to user other webspaces etc. if self.plotdict["www"] != None: # set some needed variables user = tools.get_environment_variable("HARRY_REMOTE_USER") overview_filename = "overview.html" date = datetime.date.today().strftime("%Y_%m_%d") remote_dir = tools.get_environment_variable("HARRY_REMOTE_DIR") + "/%s/%s/" % ( date, (self.plotdict["www"] if type(self.plotdict["www"]) == str else ""), ) remote_path = tools.get_environment_variable("HARRY_REMOTE_PATH") + "/%s" % remote_dir url = tools.get_environment_variable("HARRY_URL") + "/%s/%s" % (remote_dir, overview_filename) plots_for_gallery = [ p for p in sorted(os.listdir(self.plotdict["output_dir"])) if ((".png" in p) or (".pdf" in p)) ] plots_to_copy = [os.path.basename(filename), overview_filename] if self.plotdict.get("save_legend", False): for f in self.plotdict["formats"]: plots_to_copy.append(".".join([self.plotdict["save_legend"], f])) html_content = "" log.info("Copying plots to webspace...") # loop over plots, make gallery for plot in [p for p in plots_for_gallery if ((".png" in p) or (".pdf" in p))]: # try to link to pdf file, if it exists href = plot.replace(".png", ".pdf") if href not in plots_for_gallery: href = plot title = plot.split("/")[-1][:-4].replace("_", " ") html_content += htmlTemplatePlot % (title, href, title, plot) with open(self.plotdict["output_dir"] + "/" + overview_filename, "w") as f: f.write(htmlTemplate % (url, html_content)) # create remote dir, copy plots and overview file create_dir_command = ["ssh", tools.get_environment_variable("HARRY_SSHPC"), "mkdir -p", remote_path] log.debug("\nIssueing mkdir command: " + " ".join(create_dir_command)) subprocess.call(create_dir_command) rsync_command = ( ["rsync", "-u"] + [os.path.join(self.plotdict["output_dir"], p) for p in plots_to_copy] + ["%s:%s" % (tools.get_environment_variable("HARRY_SSHPC"), remote_path)] ) log.debug("\nIssueing rsync command: " + " ".join(rsync_command) + "\n") subprocess.call(rsync_command) log.info("Copied {0}; see {1}".format(filename.split("/")[-1], url)) return self.plotdict["output_filenames"]
def save(self): self.plot.finish() if not self.plot is None: for filename in self.plotdict["output_filenames"]: self.plot.save(filename) log.info('Created plot "%s".' % filename) if not (self.plotdict["live"] == None): # if 'userpc', get the username and name of desktop machine if self.plotdict["userpc"]: userpc = ( "%s@%s" % (tools.get_environment_variable("USER"), tools.get_environment_variable("HARRY_USERPC")) ).replace("\n", "") for output_filename in self.plotdict["output_filenames"]: if self.plotdict["userpc"]: extrafunctions.show_plot_userpc( output_filename, self.plotdict["live"], tools.get_environment_variable("USER"), userpc ) else: extrafunctions.show_plot(output_filename, self.plotdict["live"]) # web plotting # TODO: make this more configurable if users want to user other webspaces etc. if self.plotdict["www"] != None: # set some needed variables user = tools.get_environment_variable("HARRY_REMOTE_USER") overview_filename = "overview.html" date = datetime.date.today().strftime("%Y_%m_%d") remote_dir = os.path.expandvars( os.path.join( "$HARRY_REMOTE_DIR", date, (self.plotdict["www"] if type(self.plotdict["www"]) == str else "") ) ) remote_path = os.path.expandvars(os.path.join("$HARRY_REMOTE_PATH", remote_dir)) url = os.path.expandvars(os.path.join("$HARRY_URL", remote_dir, overview_filename)) plots_for_gallery = [ p for p in sorted(os.listdir(self.plotdict["output_dir"])) if ( os.path.isfile(os.path.join(self.plotdict["output_dir"], p)) and all([not p.endswith("." + ext) for ext in ["json", "html", "root"]]) ) ] html_content = "" log.info("Copying plots to webspace...") # loop over plots, make gallery html_template = None with open( os.path.expandvars("$ARTUSPATH/HarryPlotter/data/template_webplotting_overview.html") ) as html_template_file: html_template = string.Template(html_template_file.read()) html_template_plot = None with open( os.path.expandvars("$ARTUSPATH/HarryPlotter/data/template_webplotting_plot.html") ) as html_template_plot_file: html_template_plot = string.Template(html_template_plot_file.read()) for plot in [p for p in plots_for_gallery]: # try to link to pdf file, if it exists href = plot.replace(".png", ".pdf") if href not in plots_for_gallery: href = plot filename = os.path.splitext(plot)[0] html_content += html_template_plot.substitute( title=filename, href=href, plot=plot, json=filename + ".json" ) with open(os.path.join(self.plotdict["output_dir"], overview_filename), "w") as overview_file: overview_file.write(html_template.substitute(url=url, html_content=html_content)) # create remote dir, copy plots and overview file sshpc = tools.get_environment_variable("HARRY_SSHPC") create_dir_command = ["ssh", user + "@" + sshpc, "mkdir -p", remote_path] log.debug("\nIssueing mkdir command: " + " ".join(create_dir_command)) logger.subprocessCall(create_dir_command) rsync_command = ( ["rsync", "-u"] + glob.glob(os.path.join(self.plotdict["output_dir"], "*.*")) + ["%s@%s:%s" % (user, sshpc, remote_path)] ) log.debug("\nIssueing rsync command: " + " ".join(rsync_command) + "\n") logger.subprocessCall(rsync_command) log.info("Copied {0}; see {1}".format(filename.split("/")[-1], url)) return self.plotdict["output_filenames"]