-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil.py
82 lines (71 loc) · 2.12 KB
/
util.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import time
import os
from functools import wraps
from tenacity import retry, stop_after_attempt
from adbutils.errors import AdbError
import uiautomator2 as u2
import configparser
import os
def getConfig(section):
#获取配置信息
config = configparser.ConfigParser()
root = os.path.dirname(__file__)
config.read(os.path.join(root, 'config.ini'), encoding='utf8')
return config[section]
def getDBURI():
config = getConfig('ONLINE')
uri = 'mongodb://'
if 'userName' in config and 'password' in config:
uri = uri + config['userName'] + ':' + config['password'] + '@'
uri = uri + config['host'] + ':' + config['port'] + '/' + config['DBName']
return uri
def decTime(fn):
@wraps(fn)
def innerFn(*args, **kwargs):
start = time.time()
name = fn.__name__
temp = fn(*args, **kwargs)
end = time.time()
print('{0} 耗时 {1}'.format(name, end - start))
return temp
return innerFn
@retry(stop=stop_after_attempt(2))
def connect():
try:
d = u2.connect('127.0.0.1:7555')
return d
except AdbError:
os.popen('adb connect 127.0.0.1:7555')
print('链接失败,尝试重连中...')
time.sleep(10)
print(AdbError)
raise AdbError
class LazyProperty(object):
"""
LazyProperty
explain: http://www.spiderpy.cn/blog/5/
"""
def __init__(self, func):
self.func = func
def __get__(self, instance, owner):
if instance is None:
return self
else:
value = self.func(instance)
setattr(instance, self.func.__name__, value)
return value
class CachedCalled:
"""
"""
cache = {}
def __call__(self, func):
@wraps(func)
def innerFn(*args, **kwargs):
key = func.__name__
keys = self.cache.keys()
if key in keys:
return self.cache[key]
value = func(*args, **kwargs)
self.cache[key] = value
return value
return innerFn