"""Shell script plots make images via command line programs.
These are usually shell scripts to command line programs for data
analysis that use the filesystem for io. This can be rather slow
processing, but it makes for easy development.
"""
from django.contrib.dataplot import GenericPlot
class Plot(GenericPlot):
"""Make plots through the filesystem and command line programs.
"""
def get_cline_template_dict(self):
"""Dict used to fill in self.cmdtmp string.
"""
if 'TEMPLATE_DICT_CACHE' in dir(self):
return self.TEMPLATE_DICT_CACHE
di={
'infile':self.get_full_base(),
'outfile':self.from_filename(),
}
# Defaults may be overridden by arguments
# additional arguments may also be specified by get_plot_args dict
di.update(self.get_plot_args())
self.TEMPLATE_DICT_CACHE=di
return di
def get_cline(self):
"""Construct command line based on template and dict.
"""
di=self.get_cline_template_dict()
cmd=self.cmdtmp%di
return cmd
def write_data_to_infile(self):
"""Write data from get_plot_args into infile specified.
Presumably this data is the input for a command-line program.
"""
di=self.get_cline_template_dict()
fh=open(di['infile'],'w')
fh.write(di['data'])
fh.close()
def makefile(self):
"""Write data to infile and then execute the commandline.
This presumably makes the convert_from file.
"""
self.write_data_to_infile()
cmd=self.get_cline()
os.system(cmd)