Public Member Functions | Static Public Attributes | Private Attributes | List of all members
wirecell.command.Config Class Reference

Public Member Functions

def __init__ (self, kwds)
 
def load (self, kwds)
 
def load_wcjson (self, string)
 
def load_wcfile (self, filename)
 
def load_configlist (self, cfglist)
 
def load_configdict (self, cfgdict)
 
def get (self, type, name='')
 
def load_one (self, type, name, data)
 
def merge (self, other)
 
def wcjson (self)
 
def __str__ (self)
 

Static Public Attributes

string formats = 'wcjson wcfile configlist configdict'
 

Private Attributes

 _cfg
 

Detailed Description

Definition at line 25 of file command.py.

Constructor & Destructor Documentation

def wirecell.command.Config.__init__ (   self,
  kwds 
)

Definition at line 29 of file command.py.

29  def __init__(self, **kwds):
30  self._cfg = defaultdict(dict)
31  self.load(**kwds)
32 
def load(self, kwds)
Definition: command.py:33
def __init__(self, kwds)
Definition: command.py:29

Member Function Documentation

def wirecell.command.Config.__str__ (   self)

Definition at line 85 of file command.py.

85  def __str__(self):
86  return self.wcjson()
87 
def wirecell.command.Config.get (   self,
  type,
  name = '' 
)

Definition at line 55 of file command.py.

55  def get(self, type, name=''):
56  return self._cfg[(type,name)]
57 
def get(self, type, name='')
Definition: command.py:55
def wirecell.command.Config.load (   self,
  kwds 
)

Definition at line 33 of file command.py.

33  def load(self, **kwds):
34  for form in self.formats:
35  obj = kwds.get(form,None)
36  if not obj: continue
37  meth = getattr(self, 'load_'+form)
38  meth(obj)
39 
def load(self, kwds)
Definition: command.py:33
def wirecell.command.Config.load_configdict (   self,
  cfgdict 
)

Definition at line 51 of file command.py.

51  def load_configdict(self, cfgdict):
52  for (t,n),d in self._cfg.items():
53  self.load_one(t,n,d)
54 
def load_one(self, type, name, data)
Definition: command.py:58
def load_configdict(self, cfgdict)
Definition: command.py:51
def wirecell.command.Config.load_configlist (   self,
  cfglist 
)

Definition at line 47 of file command.py.

47  def load_configlist(self, cfglist):
48  for d in cfglist:
49  self.load_one(d['type'], d.get('name',''), d['data'])
50 
def load_one(self, type, name, data)
Definition: command.py:58
def load_configlist(self, cfglist)
Definition: command.py:47
def wirecell.command.Config.load_one (   self,
  type,
  name,
  data 
)

Definition at line 58 of file command.py.

58  def load_one(self, type, name, data):
59  val = self.get(type,name)
60  val.update(data)
61  self._cfg[(type,name)] = val
62 
63 
def load_one(self, type, name, data)
Definition: command.py:58
def get(self, type, name='')
Definition: command.py:55
def wirecell.command.Config.load_wcfile (   self,
  filename 
)

Definition at line 44 of file command.py.

44  def load_wcfile(self, filename):
45  self.load_wcjson(open(filename).read())
46 
def load_wcfile(self, filename)
Definition: command.py:44
int open(const char *, int)
Opens a file descriptor.
def load_wcjson(self, string)
Definition: command.py:40
int read(int, char *, size_t)
Read bytes from a file descriptor.
def wirecell.command.Config.load_wcjson (   self,
  string 
)

Definition at line 40 of file command.py.

40  def load_wcjson(self, string):
41  cl = json.loads(string)
42  self.load_configlist(cl)
43 
def load_configlist(self, cfglist)
Definition: command.py:47
def load_wcjson(self, string)
Definition: command.py:40
def wirecell.command.Config.merge (   self,
  other 
)
Merge other into copy of self and return new Config object

Definition at line 64 of file command.py.

64  def merge(self, other):
65  '''
66  Merge other into copy of self and return new Config object
67  '''
68  ret = Config()
69  for (t,n),d in self._cfg.items():
70  ret.load_one(t,n,d)
71  if other:
72  for (t,n),d in other._cfg.items():
73  ret.load_one(t,n,d)
74  return ret
75 
def merge(self, other)
Definition: command.py:64
def wirecell.command.Config.wcjson (   self)
Return wire-cell compatible JSON representation.

Definition at line 76 of file command.py.

76  def wcjson(self):
77  '''
78  Return wire-cell compatible JSON representation.
79  '''
80  dat = list()
81  for (t,n),d in self._cfg.items():
82  dat.append(dict(type=t, name=n, data=d))
83  return json.dumps(dat)
84 

Member Data Documentation

wirecell.command.Config._cfg
private

Definition at line 30 of file command.py.

string wirecell.command.Config.formats = 'wcjson wcfile configlist configdict'
static

Definition at line 27 of file command.py.


The documentation for this class was generated from the following file: