Skip to content

Commit

Permalink
- Added capitalize keyword argument, issue ZELLMECHANIK-DRESDEN/Shape…
Browse files Browse the repository at this point in the history
…Out#17

- Loading config with empty list now works.
  • Loading branch information
Paul Müller committed Sep 9, 2015
1 parent 0576d1b commit 3859a86
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dclab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def ApplyFilter(self, force=[]):
there = np.where(incl)[0]
incl[there[:remove]] = 0
self._filter_limit = incl
print("'Limit Events' set to", np.sum(incl))
print("'Limit Events' set to {}/{}".format(np.sum(incl), incl.shape[0]))
elif limit == numevents:
# everything is ok
self._filter_limit = np.ones_like(self._filter)
Expand Down
2 changes: 1 addition & 1 deletion dclab/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version="0.1.2"
version="0.1.2dev1"
35 changes: 23 additions & 12 deletions dclab/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def GetKnownIdentifiers():
return uid


def LoadConfiguration(cfgfilename, cfg=None):
def LoadConfiguration(cfgfilename, cfg=None, capitalize=True):
""" Load a configuration file
Expand All @@ -79,6 +79,12 @@ def LoadConfiguration(cfgfilename, cfg=None):
cfg : dict
Dictionary to update/overwrite. If `cfg` is not set, a new
dicitonary will be created.
capitalize : bool
Capitalize dictionary entries. This is useful to
prevent duplicate entries in configurations dictionaries
like "Flow Rate" and "flow rate". It is not useful when
dictionary entries are not capitalized, e.g. for other
configuration files like index files of ShapeOut sessions.
Returns
Expand Down Expand Up @@ -111,7 +117,7 @@ def LoadConfiguration(cfgfilename, cfg=None):
cfg[section] = dict()
continue
var, val = line.split("=")
var,val = MapParameterStr2Type(var,val)
var,val = MapParameterStr2Type(var, val, capitalize=capitalize)
if len(var) != 0 and len(str(val)) != 0:
cfg[section][var] = val
f.close()
Expand All @@ -131,25 +137,30 @@ def LoadDefaultConfiguration():



def MapParameterStr2Type(var,val):
def MapParameterStr2Type(var, val, capitalize=True):
if not ( isinstance(val, str) or isinstance(val, unicode) ):
# already a type:
return var.strip(), val
var = var.strip()
val = val.strip()
# capitalize var
if len(var) != 0:
varsubs = var.split()
newvar = u""
for vs in varsubs:
newvar += vs[0].capitalize()+vs[1:]+" "
var = newvar.strip()
if capitalize:
# capitalize var
if len(var) != 0:
varsubs = var.split()
newvar = u""
for vs in varsubs:
newvar += vs[0].capitalize()+vs[1:]+" "
var = newvar.strip()
# Find values
if len(var) != 0 and len(val) != 0:
# check for float
if val.startswith("[") and val.endswith("]"):
values = val.strip("[],").split(",")
values = [float(v) for v in values]
if len(val.strip("[],")) == 0:
# empty list
values = []
else:
values = val.strip("[],").split(",")
values = [float(v) for v in values]
return var, values
elif val.lower() in ["true", "y"]:
return var, True
Expand Down

0 comments on commit 3859a86

Please sign in to comment.