-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathosutil.py
50 lines (40 loc) · 1.19 KB
/
osutil.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import hashlib
import os
import psutil
import settings
def netstat():
status_temp = []
net_connections = psutil.net_connections()
for key in net_connections:
status_temp.append(key.status)
return status_temp.count("ESTABLISHED")
# 签名算法
def createSign(appkey, params):
sign = ''
list = sorted(params.items(), key=lambda params: params[0], reverse=False)
for k, v in list:
sign = sign + k + '=' + v + '&'
sign = sign + 'appkey=' + appkey
m2 = hashlib.md5()
m2.update(sign.encode('utf-8'))
return m2.hexdigest()
# 获取当前程序版本
def getAppVersion(appname):
path = settings.APP_ROOT + appname + '/app/'
if os.path.exists(path):
dirs = os.listdir(path)
for dir in dirs:
if os.path.exists(path + dir + '/version'):
return str(dir)
return ''
# 获取当前配置文件版本
def getConfVersion(appname):
path = settings.APP_ROOT + appname + '/conf/'
if os.path.exists(path):
dirs = os.listdir(path)
for dir in dirs:
if os.path.exists(path + dir + '/version'):
return str(dir)
return ''