forked from wangyf/sordw3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.py
executable file
·36 lines (33 loc) · 1000 Bytes
/
configure.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
#!/usr/bin/env python
"""
Read configuration files
"""
import os, sys
from . import util
def configure( save=False, machine=None ):
"""
Read configuration files
"""
cwd = os.getcwd()
path = os.path.realpath( os.path.dirname( __file__ ) )
os.chdir( path )
conf = {}
exec(open( 'conf/conf.py').read(), conf)
if not machine and os.path.isfile( 'machine' ):
machine = open( 'machine' ).read().strip()
if machine:
machine = os.path.basename( machine )
path = os.path.join( 'conf', machine, 'conf.py' )
exec(open( path ).read(), conf)
conf['machine'] = machine
if save:
open( 'machine', 'w' ).write( machine )
util.prune( conf, pattern='(^_)|(^.$)' )
os.chdir( cwd )
return conf
# Set configuration from command line.
if __name__ == '__main__':
cf = configure( True, *sys.argv[1:2] )
for k in sorted( cf.keys() ):
if k != 'notes':
print( '%s = %r' % (k, cf[k]) )