mirror of
https://github.com/gryf/wicd.git
synced 2025-12-21 21:38:06 +01:00
Convert from tabs to (4) spaces
This commit is contained in:
292
cli/wicd-cli.py
292
cli/wicd-cli.py
@@ -31,17 +31,17 @@ else:
|
|||||||
|
|
||||||
bus = dbus.SystemBus()
|
bus = dbus.SystemBus()
|
||||||
try:
|
try:
|
||||||
daemon = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon'),
|
daemon = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon'),
|
||||||
'org.wicd.daemon')
|
'org.wicd.daemon')
|
||||||
wireless = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon/wireless'),
|
wireless = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon/wireless'),
|
||||||
'org.wicd.daemon.wireless')
|
'org.wicd.daemon.wireless')
|
||||||
wired = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon/wired'),
|
wired = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon/wired'),
|
||||||
'org.wicd.daemon.wired')
|
'org.wicd.daemon.wired')
|
||||||
config = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon/config'),
|
config = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon/config'),
|
||||||
'org.wicd.daemon.config')
|
'org.wicd.daemon.config')
|
||||||
except dbus.DBusException:
|
except dbus.DBusException:
|
||||||
print 'Error: Could not connect to the daemon. Please make sure it is running.'
|
print 'Error: Could not connect to the daemon. Please make sure it is running.'
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
|
|
||||||
@@ -67,176 +67,176 @@ options, arguments = parser.parse_args()
|
|||||||
op_performed = False
|
op_performed = False
|
||||||
|
|
||||||
if not (options.wireless or options.wired):
|
if not (options.wireless or options.wired):
|
||||||
print "Please use --wireless or --wired to specify " + \
|
print "Please use --wireless or --wired to specify " + \
|
||||||
"the type of connection to operate on."
|
"the type of connection to operate on."
|
||||||
|
|
||||||
# functions
|
# functions
|
||||||
def is_valid_wireless_network_id(network_id):
|
def is_valid_wireless_network_id(network_id):
|
||||||
if not (network_id >= 0 \
|
if not (network_id >= 0 \
|
||||||
and network_id < wireless.GetNumberOfNetworks()):
|
and network_id < wireless.GetNumberOfNetworks()):
|
||||||
print 'Invalid wireless network identifier.'
|
print 'Invalid wireless network identifier.'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def is_valid_wired_network_id(network_id):
|
def is_valid_wired_network_id(network_id):
|
||||||
num = len(wired.GetWiredProfileList())
|
num = len(wired.GetWiredProfileList())
|
||||||
if not (network_id < num and \
|
if not (network_id < num and \
|
||||||
network_id >= 0):
|
network_id >= 0):
|
||||||
print 'Invalid wired network identifier.'
|
print 'Invalid wired network identifier.'
|
||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
|
|
||||||
def is_valid_wired_network_profile(profile_name):
|
def is_valid_wired_network_profile(profile_name):
|
||||||
if not profile_name in wired.GetWiredProfileList():
|
if not profile_name in wired.GetWiredProfileList():
|
||||||
print 'Profile of that name does not exist.'
|
print 'Profile of that name does not exist.'
|
||||||
sys.exit(5)
|
sys.exit(5)
|
||||||
|
|
||||||
if options.scan and options.wireless:
|
if options.scan and options.wireless:
|
||||||
# synchronized scan
|
# synchronized scan
|
||||||
wireless.Scan(True)
|
wireless.Scan(True)
|
||||||
op_performed = True
|
op_performed = True
|
||||||
|
|
||||||
if options.load_profile and options.wired:
|
if options.load_profile and options.wired:
|
||||||
is_valid_wired_network_profile(options.name)
|
is_valid_wired_network_profile(options.name)
|
||||||
config.ReadWiredNetworkProfile(options.name)
|
config.ReadWiredNetworkProfile(options.name)
|
||||||
op_performed = True
|
op_performed = True
|
||||||
|
|
||||||
if options.list_networks:
|
if options.list_networks:
|
||||||
if options.wireless:
|
if options.wireless:
|
||||||
print '#\tBSSID\t\t\tChannel\tESSID'
|
print '#\tBSSID\t\t\tChannel\tESSID'
|
||||||
for network_id in range(0, wireless.GetNumberOfNetworks()):
|
for network_id in range(0, wireless.GetNumberOfNetworks()):
|
||||||
print '%s\t%s\t%s\t%s' % (network_id,
|
print '%s\t%s\t%s\t%s' % (network_id,
|
||||||
wireless.GetWirelessProperty(network_id, 'bssid'),
|
wireless.GetWirelessProperty(network_id, 'bssid'),
|
||||||
wireless.GetWirelessProperty(network_id, 'channel'),
|
wireless.GetWirelessProperty(network_id, 'channel'),
|
||||||
wireless.GetWirelessProperty(network_id, 'essid'))
|
wireless.GetWirelessProperty(network_id, 'essid'))
|
||||||
elif options.wired:
|
elif options.wired:
|
||||||
print '#\tProfile name'
|
print '#\tProfile name'
|
||||||
id = 0
|
id = 0
|
||||||
for profile in wired.GetWiredProfileList():
|
for profile in wired.GetWiredProfileList():
|
||||||
print '%s\t%s' % (id, profile)
|
print '%s\t%s' % (id, profile)
|
||||||
id += 1
|
id += 1
|
||||||
op_performed = True
|
op_performed = True
|
||||||
|
|
||||||
if options.network_details:
|
if options.network_details:
|
||||||
if options.wireless:
|
if options.wireless:
|
||||||
if options.network >= 0:
|
if options.network >= 0:
|
||||||
is_valid_wireless_network_id(options.network)
|
is_valid_wireless_network_id(options.network)
|
||||||
network_id = options.network
|
network_id = options.network
|
||||||
else:
|
else:
|
||||||
network_id = wireless.GetCurrentNetworkID(0)
|
network_id = wireless.GetCurrentNetworkID(0)
|
||||||
is_valid_wireless_network_id(network_id)
|
is_valid_wireless_network_id(network_id)
|
||||||
# we're connected to a network, print IP
|
# we're connected to a network, print IP
|
||||||
print "IP: %s" % wireless.GetWirelessIP(0)
|
print "IP: %s" % wireless.GetWirelessIP(0)
|
||||||
|
|
||||||
print "Essid: %s" % wireless.GetWirelessProperty(network_id, "essid")
|
print "Essid: %s" % wireless.GetWirelessProperty(network_id, "essid")
|
||||||
print "Bssid: %s" % wireless.GetWirelessProperty(network_id, "bssid")
|
print "Bssid: %s" % wireless.GetWirelessProperty(network_id, "bssid")
|
||||||
if wireless.GetWirelessProperty(network_id, "encryption"):
|
if wireless.GetWirelessProperty(network_id, "encryption"):
|
||||||
print "Encryption: On"
|
print "Encryption: On"
|
||||||
print "Encryption Method: %s" % \
|
print "Encryption Method: %s" % \
|
||||||
wireless.GetWirelessProperty(network_id, "encryption_method")
|
wireless.GetWirelessProperty(network_id, "encryption_method")
|
||||||
else:
|
else:
|
||||||
print "Encryption: Off"
|
print "Encryption: Off"
|
||||||
print "Quality: %s" % wireless.GetWirelessProperty(network_id, "quality")
|
print "Quality: %s" % wireless.GetWirelessProperty(network_id, "quality")
|
||||||
print "Mode: %s" % wireless.GetWirelessProperty(network_id, "mode")
|
print "Mode: %s" % wireless.GetWirelessProperty(network_id, "mode")
|
||||||
print "Channel: %s" % wireless.GetWirelessProperty(network_id, "channel")
|
print "Channel: %s" % wireless.GetWirelessProperty(network_id, "channel")
|
||||||
print "Bit Rates: %s" % wireless.GetWirelessProperty(network_id, "bitrates")
|
print "Bit Rates: %s" % wireless.GetWirelessProperty(network_id, "bitrates")
|
||||||
op_performed = True
|
op_performed = True
|
||||||
|
|
||||||
# network properties
|
# network properties
|
||||||
|
|
||||||
if options.network_property:
|
if options.network_property:
|
||||||
options.network_property = options.network_property.lower()
|
options.network_property = options.network_property.lower()
|
||||||
if options.wireless:
|
if options.wireless:
|
||||||
if options.network >= 0:
|
if options.network >= 0:
|
||||||
is_valid_wireless_network_id(options.network)
|
is_valid_wireless_network_id(options.network)
|
||||||
network_id = options.network
|
network_id = options.network
|
||||||
else:
|
else:
|
||||||
network_id = wireless.GetCurrentNetworkID(0)
|
network_id = wireless.GetCurrentNetworkID(0)
|
||||||
is_valid_wireless_network_id(network_id)
|
is_valid_wireless_network_id(network_id)
|
||||||
if not options.set_to:
|
if not options.set_to:
|
||||||
print wireless.GetWirelessProperty(network_id, options.network_property)
|
print wireless.GetWirelessProperty(network_id, options.network_property)
|
||||||
else:
|
else:
|
||||||
wireless.SetWirelessProperty(network_id, \
|
wireless.SetWirelessProperty(network_id, \
|
||||||
options.network_property, options.set_to)
|
options.network_property, options.set_to)
|
||||||
elif options.wired:
|
elif options.wired:
|
||||||
if not options.set_to:
|
if not options.set_to:
|
||||||
print wired.GetWiredProperty(options.network_property)
|
print wired.GetWiredProperty(options.network_property)
|
||||||
else:
|
else:
|
||||||
wired.SetWiredProperty(options.network_property, options.set_to)
|
wired.SetWiredProperty(options.network_property, options.set_to)
|
||||||
op_performed = True
|
op_performed = True
|
||||||
|
|
||||||
if options.disconnect:
|
if options.disconnect:
|
||||||
daemon.Disconnect()
|
daemon.Disconnect()
|
||||||
if options.wireless:
|
if options.wireless:
|
||||||
if wireless.GetCurrentNetworkID(0) > -1:
|
if wireless.GetCurrentNetworkID(0) > -1:
|
||||||
print "Disconnecting from %s on %s" % (wireless.GetCurrentNetwork(0),
|
print "Disconnecting from %s on %s" % (wireless.GetCurrentNetwork(0),
|
||||||
wireless.DetectWirelessInterface())
|
wireless.DetectWirelessInterface())
|
||||||
elif options.wired:
|
elif options.wired:
|
||||||
if wired.CheckPluggedIn():
|
if wired.CheckPluggedIn():
|
||||||
print "Disconnecting from wired connection on %s" % wired.DetectWiredInterface()
|
print "Disconnecting from wired connection on %s" % wired.DetectWiredInterface()
|
||||||
op_performed = True
|
op_performed = True
|
||||||
|
|
||||||
if options.connect:
|
if options.connect:
|
||||||
check = None
|
check = None
|
||||||
if options.wireless and options.network > -1:
|
if options.wireless and options.network > -1:
|
||||||
is_valid_wireless_network_id(options.network)
|
is_valid_wireless_network_id(options.network)
|
||||||
name = wireless.GetWirelessProperty(options.network, 'essid')
|
name = wireless.GetWirelessProperty(options.network, 'essid')
|
||||||
encryption = wireless.GetWirelessProperty(options.network, 'enctype')
|
encryption = wireless.GetWirelessProperty(options.network, 'enctype')
|
||||||
print "Connecting to %s with %s on %s" % (name, encryption,
|
print "Connecting to %s with %s on %s" % (name, encryption,
|
||||||
wireless.DetectWirelessInterface())
|
wireless.DetectWirelessInterface())
|
||||||
wireless.ConnectWireless(options.network)
|
wireless.ConnectWireless(options.network)
|
||||||
|
|
||||||
check = lambda: wireless.CheckIfWirelessConnecting()
|
check = lambda: wireless.CheckIfWirelessConnecting()
|
||||||
message = lambda: wireless.CheckWirelessConnectingMessage()[1]
|
message = lambda: wireless.CheckWirelessConnectingMessage()[1]
|
||||||
elif options.wired:
|
elif options.wired:
|
||||||
print "Connecting to wired connection on %s" % wired.DetectWiredInterface()
|
print "Connecting to wired connection on %s" % wired.DetectWiredInterface()
|
||||||
wired.ConnectWired()
|
wired.ConnectWired()
|
||||||
|
|
||||||
check = lambda: wired.CheckIfWiredConnecting()
|
check = lambda: wired.CheckIfWiredConnecting()
|
||||||
message = lambda: wired.CheckWiredConnectingMessage()
|
message = lambda: wired.CheckWiredConnectingMessage()
|
||||||
|
|
||||||
# update user on what the daemon is doing
|
# update user on what the daemon is doing
|
||||||
last = None
|
last = None
|
||||||
if check:
|
if check:
|
||||||
while check():
|
while check():
|
||||||
next = message()
|
next = message()
|
||||||
if next != last:
|
if next != last:
|
||||||
# avoid a race condition where status is updated to "done" after the
|
# avoid a race condition where status is updated to "done" after the
|
||||||
# loop check
|
# loop check
|
||||||
if next == "done":
|
if next == "done":
|
||||||
break
|
break
|
||||||
print "%s..." % next.replace("_", " ")
|
print "%s..." % next.replace("_", " ")
|
||||||
last = next
|
last = next
|
||||||
print "done!"
|
print "done!"
|
||||||
op_performed = True
|
op_performed = True
|
||||||
|
|
||||||
# pretty print optional and required properties
|
# pretty print optional and required properties
|
||||||
def str_properties(prop):
|
def str_properties(prop):
|
||||||
if len(prop) == 0:
|
if len(prop) == 0:
|
||||||
return "None"
|
return "None"
|
||||||
else:
|
else:
|
||||||
return ', '.join("%s (%s)" % (x[0], x[1].replace("_", " ")) for x in type['required'])
|
return ', '.join("%s (%s)" % (x[0], x[1].replace("_", " ")) for x in type['required'])
|
||||||
|
|
||||||
if options.wireless and options.list_encryption_types:
|
if options.wireless and options.list_encryption_types:
|
||||||
et = misc.LoadEncryptionMethods()
|
et = misc.LoadEncryptionMethods()
|
||||||
# print 'Installed encryption templates:'
|
# print 'Installed encryption templates:'
|
||||||
print '%s\t%-20s\t%s' % ('#', 'Name', 'Description')
|
print '%s\t%-20s\t%s' % ('#', 'Name', 'Description')
|
||||||
id = 0
|
id = 0
|
||||||
for type in et:
|
for type in et:
|
||||||
print '%s\t%-20s\t%s' % (id, type['type'], type['name'])
|
print '%s\t%-20s\t%s' % (id, type['type'], type['name'])
|
||||||
print ' Req: %s' % str_properties(type['required'])
|
print ' Req: %s' % str_properties(type['required'])
|
||||||
print '---'
|
print '---'
|
||||||
# don't print optionals (yet)
|
# don't print optionals (yet)
|
||||||
#print ' Opt: %s' % str_properties(type['optional'])
|
#print ' Opt: %s' % str_properties(type['optional'])
|
||||||
id += 1
|
id += 1
|
||||||
op_performed = True
|
op_performed = True
|
||||||
|
|
||||||
if options.save and options.network > -1:
|
if options.save and options.network > -1:
|
||||||
if options.wireless:
|
if options.wireless:
|
||||||
is_valid_wireless_network_id(options.network)
|
is_valid_wireless_network_id(options.network)
|
||||||
config.SaveWirelessNetworkProfile(options.network)
|
config.SaveWirelessNetworkProfile(options.network)
|
||||||
elif options.wired:
|
elif options.wired:
|
||||||
config.SaveWiredNetworkProfile(options.name)
|
config.SaveWiredNetworkProfile(options.name)
|
||||||
op_performed = True
|
op_performed = True
|
||||||
|
|
||||||
if not op_performed:
|
if not op_performed:
|
||||||
print "No operations performed."
|
print "No operations performed."
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user