-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsconfig.py
53 lines (48 loc) · 1.25 KB
/
fsconfig.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
import os
import sys
def loadconfig():
[succes,homedir]=gethomedir()
if not succes:
return [False,[]]
try:
f=open(homedir+'/.flowstat/flowstat.conf','r')
lines=f.readlines()
f.close()
path=lines[0].replace('\r','').replace('\n','').replace(' ','\ ')
appsize=lines[1].replace('\r','').replace('\n','').replace(' ','\ ')
print('path='+str(path))
print('appsize='+str(appsize))
return [True,[path,appsize]]
except:
return [False,[]]
def saveconfig(vrs):
[succes,homedir]=gethomedir()
if not succes:
return False
if not os.path.exists(homedir+'/.flowstat'):
# config directory does not exist -> create
try:
os.mkdir(homedir+'/.flowstat')
except:
return False
try:
f=open(homedir+'/.flowstat/flowstat.conf','w')
for var in vrs:
f.write(str(var)+'\n')
f.close()
return True
except:
return False
def gethomedir():
if os.name=='posix':
homedir=os.environ['HOME']
return [True,homedir]
else:
return [False,'']
def strippath(path):
# strip filename from path
components=path.split('/')
opath=''
for i in range(len(components)-1):
opath+='/'+components[i]
return opath