3 # Author: Martin Matusiak <numerodix@gmail.com>
4 # Licensed under the GNU Public License, version 3.
9 from conf
import config
10 from output
import logger
12 from sdict
import sdict
, sdictlist
15 # Read command line options
18 return optparse
.OptionParser(add_help_option
=None)
20 def read_opts(parser
):
21 def opts_help(option
, opt_str
, value
, parser
):
22 print "Usage: %s [options]" % config
.program_name
23 for o
in parser
.option_list
:
25 if not o
.metavar
: var
= ""
26 argument
= "%s %s %s" % (o
._short
_opts
[0], o
._long
_opts
[0], var
)
27 print " %s %s" % (argument
.strip().ljust(25), o
.help)
30 parser
.add_option("-h", "--help", action
="callback", callback
=opts_help
,
31 help="Display this message")
32 opts
= parser
.parse_args()[0]
33 config
.opts
.update( [(k
, opts
.__dict
__[k
]) for k
in opts
.__dict
__] )
35 # merge new nets info global list
36 if config
.opts
.network
:
37 for (i
, n
) in enumerate(config
.opts
.network
):
39 name
= pair
[0] ; pri
= config
.max_priortiy
- i
40 d
= sdict({ 'essid': name
, 'priority': pri
})
41 if len(pair
) == 2: d
['key'] = pair
[1]
42 config
.networks
= config
.networks
.merge1(d
, 'essid')
43 config
.networks
= negated_opts(config
.networks
, 'essid')
45 # merge new interfaces into global list
46 if config
.opts
.interface
:
47 for (i
, n
) in enumerate(config
.opts
.interface
):
48 pri
= config
.max_priortiy
- i
49 d
= sdict({'interface': n
, 'priority': pri
})
50 config
.interfaces
= config
.interfaces
.merge1(d
, 'interface')
51 config
.interfaces
= negated_opts(config
.interfaces
, 'interface')
53 def negated_opts(dicts
, key
):
55 for (i
, d
) in enumerate(dicts
):
56 val
= regex
.find1("^\^(.*)", d
[key
])
59 new_dicts
= sdictlist(init_list
=new_dicts
.get_all(\
60 pred
=lambda x
: x
[key
] != val
))
63 def post_negate_nets(nets
, key
):
64 if not config
.opts
.network
: return nets
66 for (i
, n
) in enumerate(config
.opts
.network
):
67 key_value
= regex
.find1("^\^(.*)[,]?.*", n
)
69 new_nets
= sdictlist(init_list
=\
70 new_nets
.get_all(pred
=lambda x
: x
[key
] != key_value
))