-
Notifications
You must be signed in to change notification settings - Fork 0
/
confighandler.py
63 lines (52 loc) · 1.38 KB
/
confighandler.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
import os
import platform
from morris import Signal
DB_TOKEN = None
def is_darwin():
return platform.system().lower() == "darwin"
def pth_root():
root = os.path.expanduser( "~/.gifbox" )
if not os.path.exists( root ):
os.mkdir( root )
return root
def path_for_resource( pth_resource ):
return os.path.join( pth_root(), pth_resource )
def pth_token():
return path_for_resource( "db_token" )
def load_dropboxtoken( fn_token=None ):
global DB_TOKEN
token = None
if fn_token is None:
print "get default path"
fn_token = pth_token()
print "fn_token: %s" % fn_token
if os.path.exists( fn_token ):
fh = open( fn_token )
token = fh.read().rstrip()
fh.close()
if len(token) < 1:
token = None
DB_TOKEN = token
return token
def dropbox_token():
global DB_TOKEN
if DB_TOKEN is None:
load_dropboxtoken()
return DB_TOKEN
@Signal.define
def token_saved( pth_token ):
pass
def save_token( self, token ):
fn_token = pth_token()
fh = open( fn_token, "w" )
fh.write( token )
fh.close()
token_saved( fn_token )
def load_config():
fh = open( path_for_resource( ".env" ) )
lines = fh.readlines()
fh.close()
for line in lines:
line = line.rstrip()
key, val = line.split( "=" )
os.environ[ key ] = val