6 from conf
import config
8 from sdict
import sdict
, sdictlist
11 # Read command line options
14 p
= optparse
.OptionParser(add_help_option
=None)
18 add("-i", "--interface", dest
="interface", action
="append",
19 metavar
="iface", help="Prefer this interface")
20 add("-n", "--network", dest
="network", action
="append",
21 metavar
="name[,key]", help="Prefer this wireless network")
22 add("-w", "--wardrive", action
=b
,
23 help="Attempt to connect to any open network in range")
24 add("-d", "--debug", action
=b
, help="Run in foreground (debug mode)")
25 add("-D", "--dropip", action
=b
, help="Release existing ip")
26 add("-k", "--kill", action
=b
, help="Stop %s" % config
.program_name
)
27 add("-?", "--help", action
=c
, callback
=help, help="Display this message")
28 opts
= p
.parse_args()[0]
29 config
.opts
.update( [(k
, opts
.__dict
__[k
]) for k
in opts
.__dict
__] )
31 opts_init_interfaces()
34 p
= optparse
.OptionParser(add_help_option
=None)
38 add("-i", "--interface", dest
="interface", action
="append",
39 metavar
="iface", help="Prefer this interface")
40 add("-t", "--timeout", dest
="timeout", action
="store",
41 metavar
="s", help="Scan for this many seconds, then exit")
42 add("-?", "--help", action
=c
, callback
=opts_help
, help="Display this message")
43 opts
= p
.parse_args()[0]
44 config
.opts
.update( [(k
, opts
.__dict
__[k
]) for k
in opts
.__dict
__] )
45 opts_init_interfaces()
47 def opts_help(option
, opt_str
, value
, parser
):
48 print "Usage: %s [options]" % config
.program_name
49 for o
in parser
.option_list
:
51 if not o
.metavar
: var
= ""
52 argument
= "%s %s %s" % (o
._short
_opts
[0], o
._long
_opts
[0], var
)
53 print " %s %s" % (argument
.strip().ljust(25), o
.help)
56 def opts_init_networks():
57 # merge new nets info global list
58 if config
.opts
.network
:
59 for (i
, n
) in enumerate(config
.opts
.network
):
61 name
= pair
[0] ; pri
= config
.max_priortiy
- i
62 d
= sdict({ 'essid': name
, 'priority': pri
})
63 if len(pair
) == 2: d
['key'] = pair
[1]
64 config
.networks
= config
.networks
.merge1(d
, 'essid')
65 config
.networks
= negated_opts(config
.networks
, 'essid')
67 def opts_init_interfaces():
68 # merge new interfaces into global list
69 if config
.opts
.interface
:
70 for (i
, n
) in enumerate(config
.opts
.interface
):
71 pri
= config
.max_priortiy
- i
72 d
= sdict({'interface': n
, 'priority': pri
})
73 config
.interfaces
= config
.interfaces
.merge1(d
, 'interface')
74 config
.interfaces
= negated_opts(config
.interfaces
, 'interface')
76 def negated_opts(dicts
, key
):
78 for (i
, d
) in enumerate(dicts
):
79 val
= regex
.find1("^\^(.*)", d
[key
])
82 new_dicts
= sdictlist(init_list
=new_dicts
.get_all(\
83 pred
=lambda x
: x
[key
] != val
))
86 def post_negate_nets(nets
, key
):
87 if not config
.opts
.network
: return nets
90 for (i
, n
) in enumerate(config
.opts
.network
):
93 key_value
= regex
.find1("^\^(.*)", key_input
)
95 new_nets
= sdictlist(init_list
=\
96 nets
.get_all(pred
=lambda x
: x
[key
] != key_value
))