本文整理汇总了Python中executor.Executor.execute_cmd方法的典型用法代码示例。如果您正苦于以下问题:Python Executor.execute_cmd方法的具体用法?Python Executor.execute_cmd怎么用?Python Executor.execute_cmd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类executor.Executor
的用法示例。
在下文中一共展示了Executor.execute_cmd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Hostapd
# 需要导入模块: from executor import Executor [as 别名]
# 或者: from executor.Executor import execute_cmd [as 别名]
class Hostapd(object):
""" Wrapper class for UCI (OpenWRT) commands """
executor = None
devicename = None
def __init__(self, config = "/etc/hostapd/hostapd.conf", wifi_restart_command, executor=None):
if executor == None:
self.executor = Executor()
else:
self.executor = executor
self.config = config
self.restart_command = wifi_restart_command
def get_wifi_interface(self):
"Return the wifi interface name (e.g. 'wlan0')"
ret = self.executor.execute_cmd(['grep', '^interface', self.config, '|', 'cut','-f2','-d"="'])
if ret is None:
print 'No WiFi device name found.'
return ret
def get_bridge_interface(self):
"Return the bridge interface name (e.g. 'br0')"
ret = self.executor.execute_cmd(['grep', '^bridge', self.config, '|', 'cut','-f2','-d"="'])
if ret is None:
print 'No bridge device name found.'
return ret
def get_wifi_mode(self):
"Get operation mode (e.g. n)"
ret = self.executor.execute_cmd(['grep', '^hw_mode', self.config, '|', 'cut','-f2','-d"="'])
if ret is None:
print 'No mode found in config.'
return ret
def set_channel(self, channel):
"Sets the wifi channel. Requires commit and restart of WiFi for changes to take effect"
self.executor.execute_cmd(['sudo','cat',self.config,'|','sed','-e',"s/channel=[0-9][0-9]*/channel=%d/g" % channel, '>', '/tmp/tmp_hostapd.conf'])
self.executor.execute_cmd(['sudo','mv','/tmp/tmp_hostapd.conf',self.config])
def restart():
"Restart hostapd"
self.executor.execute_cmd(wifi_restart_command)
def get_wifi_ssid(self):
"Return the wifi ssid (e.g. for 'node1-wifi')"
ret = self.executor.execute_cmd(['grep', '^ssid', self.config, '|', 'cut','-f2','-d"="'])
if ret is None:
print 'No SSID found in config.'
return ret