initial comit
This commit is contained in:
commit
8145e57c38
11
dj_local_conf.json
Normal file
11
dj_local_conf.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"database.host": "localhost",
|
||||||
|
"database.password": "datajoint",
|
||||||
|
"database.port": 3306,
|
||||||
|
"loglevel": "DEBUG",
|
||||||
|
"display.width": 14,
|
||||||
|
"display.limit": 7,
|
||||||
|
"safemode": true,
|
||||||
|
"database.user": "dj",
|
||||||
|
"connection.init_function": null
|
||||||
|
}
|
45
util.py
Normal file
45
util.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
from IPython import embed
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
def read_info_file(file_name):
|
||||||
|
"""
|
||||||
|
Reads the info file and returns the stored metadata in a dictionary. The dictionary may be nested.
|
||||||
|
@param file_name: The name of the info file.
|
||||||
|
@return: dictionary, the stored information.
|
||||||
|
"""
|
||||||
|
root = {}
|
||||||
|
with open(file_name, 'r') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
for l in lines:
|
||||||
|
if not l.startswith("#"):
|
||||||
|
continue
|
||||||
|
l = l.strip("#").strip()
|
||||||
|
if len(l) == 0:
|
||||||
|
continue
|
||||||
|
if not ": " in l: # subsection
|
||||||
|
sec = {}
|
||||||
|
root[l[:-1] if l.endswith(":") else l] = sec
|
||||||
|
else:
|
||||||
|
parts = l.split(': ')
|
||||||
|
sec[parts[0].strip()] = parts[1].strip('"').strip()
|
||||||
|
return root
|
||||||
|
|
||||||
|
|
||||||
|
def find_key_recursive(dictionary, key, path=[]):
|
||||||
|
assert(isinstance(dictionary, dict))
|
||||||
|
if key in dictionary.keys():
|
||||||
|
path.append(key)
|
||||||
|
return True
|
||||||
|
for k in dictionary.keys():
|
||||||
|
if isinstance(dictionary[k], dict):
|
||||||
|
if find_key_recursive(dictionary[k], key, path):
|
||||||
|
path.insert(-1, k)
|
||||||
|
break
|
||||||
|
return len(path) > 0
|
||||||
|
|
||||||
|
|
||||||
|
def deep_get(dictionary, keys, default=None):
|
||||||
|
assert(isinstance(dictionary, dict))
|
||||||
|
assert(isinstance(keys, list))
|
||||||
|
return reduce(lambda d, key: d.get(key, default) if isinstance(d, dict) else default, keys, dictionary)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user