Controller.py
Go to the documentation of this file.
1 from config_parser import config_parser
2 import os
3 import cPickle
4 import Component
5 import datetime
6 
7 class Controller():
8 
9  def __init__(self, config_file, verbose=False):
10  self.verbose = verbose
11  self.config = config_parser(config_file)
12  self.name = self.config["name"]
13  self.version = self.config["version"]
14  self.release = self.config["release"]
15  self.user = os.environ["NOVAANAVALID_USERNAME"]
16 
17  optional_attributes = ["description"]
18  for attr in optional_attributes:
19  if attr in self.config.keys():
20  setattr(self, attr, self.config[attr])
21  else:
22  setattr(self, attr, False)
23 
24  self.components = []
25  for component_config in self.config["components"]:
26  self.components.append(Component.Component(component_config, release=self.release, verbose=self.verbose, user=self.user))
27  self.output_dir = False
28  self.creation_time = datetime.datetime.now()
29 
30  def make_output_directory(self, output_directory, overwrite=False):
31  self.output_dir = "%s/%s/v%s"%(output_directory, self.config["name"], self.config["version"])
32  if self.verbose: print "cntrl: output directory will be: %s"%self.output_dir
33  if (not overwrite) and os.path.exists(self.output_dir):
34  print "cntrl: output directory:"
35  print self.output_dir
36  print "cntrl: already exists, aborting\n"
37  exit(1)
38  os.system("mkdir -p %s"%self.output_dir)
39  for component in self.components:
40  component.output_dir = "%s/%s/v%s"%(self.output_dir, component.name, component.version)
41  if component.dataset: component.output_dir += "/%s"%component.dataset
42  os.system("mkdir -p %s"%component.output_dir)
43  if component.sam:
44  os.system("mkdir -p %s/hadd_hist"%component.output_dir)
45  os.system("mkdir -p %s/logs"%component.output_dir)
46 
47  def write(self):
48  if (not self.output_dir):
49  print "cntrl: Output directory has not been set, so cannot write"
50  return False
51  self.file_name = self.output_dir+"/controller.pkl"
52  print "cntrl: Saving as: %s"%self.file_name
53  cPickle.dump(self,open(self.file_name,"w"))
def make_output_directory(self, output_directory, overwrite=False)
Definition: Controller.py:30
procfile open("FD_BRL_v0.txt")
exit(0)
def __init__(self, config_file, verbose=False)
Definition: Controller.py:9