forked from brewsterkahle/archivecd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchivecd_config.py
More file actions
40 lines (34 loc) · 1.18 KB
/
archivecd_config.py
File metadata and controls
40 lines (34 loc) · 1.18 KB
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
#!/usr/bin/env python
import os
import yaml
#from wizard import BASE_DIR
homedir = '~/.archivecd/'
#homedir = '~'
configfile= 'archivecd.yml'
thepath= ''
# read()
#_________________________________________________________________________________________
def read((base_dir)):
global homedir
try:
homedir= os.path.expanduser(homedir)
thepath= os.path.join(homedir,configfile)
if not os.path.exists(thepath):
if os.path.exists(os.path.join(base_dir,configfile)):
thepath= os.path.join(base_dir,configfile)
f = open(thepath)
config = yaml.safe_load(f)
except Exception:
print('Could not read {p}'.format(p=os.path.join(thepath,configfile)))
config = {}
return config
# save()
#_________________________________________________________________________________________
def save(config):
try:
f = open(thepath, 'w')
yaml.dump(config, f, default_flow_style=False)
print yaml.dump(config, default_flow_style=False)
except Exception:
#raise ScribeException('Could not save config to {p}'.format(p=path))
print('Could not save config to {p}'.format(p=thepath))