forked from leo-vip/cockybook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
47 lines (36 loc) · 1003 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import datetime
import json
import logging
__author__ = 'lei'
# #connect path
def connect_path(base, name):
if name.startswith('/'):
name = name[1:]
if base.endswith('/'):
return base + name
else:
return base + '/' + name
def getNow():
return datetime.datetime.now().strftime("%Y-%m-%dT%I:%M:%SZ")
def getFile(jjson,paths):
'''
get json object
:param jjson: json object
:param paths: json path
:return: json object
'''
try:
if len(paths)==1:
if paths[0]=='':
return jjson
elif jjson.has_key(paths[0]):
return jjson[paths[0]]
else:
logging.warn( 'Jjson',json.dumps(jjson))
logging.warn( 'No this Key:', paths[0])
return None
elif len(paths)>1:
return getFile(jjson[paths[0]], paths[1:])
except AttributeError ,e:
logging.error(e.message)
return None