本文整理汇总了Python中Command.Command.run方法的典型用法代码示例。如果您正苦于以下问题:Python Command.run方法的具体用法?Python Command.run怎么用?Python Command.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Command.Command
的用法示例。
在下文中一共展示了Command.run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_messages
# 需要导入模块: from Command import Command [as 别名]
# 或者: from Command.Command import run [as 别名]
def handle_messages(self):
# Initialize DB
self.conn = sqlite3.connect('telegram.db')
self.c = self.conn.cursor()
# Create tables
self.c.execute('''create table if not exists Telegram (name STRING, last_name STRING, userid STRING UNIQUE)''')
while True:
print ("Waiting for message in queue")
message = self.queue.get()
user_info = message[1]
user_id = user_info[0]
first_name = user_info[1]
last_name = user_info[2]
if last_name is None:
last_name = "N/A"
print ("Got and handle message "+str(message.text))
res="Command not understood"
try:
#Extract the command
cmd_list = message.text.split()
if str(message.text) == "/start":
self.new_user(first_name, last_name, user_id)
continue
#Replace protocol command with OS command
cmd = commands.allowable_commands[cmd_list[0]]
cmd_list[0] = cmd
runner = Command(cmd_list)
runner.run(5)
print("RES "+str(runner.res)+" /RES")
self._send_message(message.sender.id, runner.res)
except Exception as e:
print ("Except: "+str(e))
示例2: run
# 需要导入模块: from Command import Command [as 别名]
# 或者: from Command.Command import run [as 别名]
def run(self):
logging.info('Kill old sessions.')
self.kill_tcp_processes()
logging.info('Starting sniffers.')
if FLAGS.sspath:
ss_log_name = '%s_%s_%s_%s.ss.log' % \
(self.carrier, self.browser, self.domain, str(time.time()))
ss_log_path = os.path.join(FLAGS.logdir, ss_log_name)
ss_fh = open(ss_log_path + '.tmp', 'w')
ss_log = subprocess.Popen([FLAGS.sspath,'-g'], stdout = ss_fh)
pcap_name = '%s_%s_%s_%s.pcap' % (self.carrier, self.browser, self.domain,
str(time.time()))
pcap_path = os.path.join(FLAGS.logdir, pcap_name)
pcap = subprocess.Popen(
['tcpdump','-i','%s' % self.interface,'-w', pcap_path + '.tmp'])
logging.info(str(['tcpdump','-i','%s' % self.interface,'-w', pcap_path]))
time.sleep(2)
logging.info('Starting browser.')
# TODO(tierney): Hacks to fix how we deal with non-terminating connections.
to_kill = None
if self.browser == 'chrome':
to_kill = 'chromedriver'
elif self.browser == 'firefox':
to_kill = '/usr/lib/firefox-10.0.2/firefox'
command = Command('./BrowserRun.py --browser %s --domain %s' % \
(self.browser, self.domain))
command.run(timeout = FLAGS.timeout, pskill = to_kill)
pcap.terminate()
os.rename(pcap_path +'.tmp', pcap_path)
if FLAGS.sspath:
ss_fh.flush()
ss_log.terminate()
ss_fh.flush()
ss_fh.close()
os.rename(ss_log_path + '.tmp', ss_log_path)
return
示例3: download
# 需要导入模块: from Command import Command [as 别名]
# 或者: from Command.Command import run [as 别名]
def download(uri, dirname=None, output=None):
if dirname is None:
dirname = os.getcwd()
if output is None:
output = '/dev/null'
dest_path = os.path.join(dirname, os.path.basename(uri))
cmd = get_download_command(uri, dest_path, output)
if cmd is None:
return False
command = Command(cmd, dirname)
try:
command.run()
except:
return False
return os.path.exists(dest_path)
示例4: client_experiment
# 需要导入模块: from Command import Command [as 别名]
# 或者: from Command.Command import run [as 别名]
def client_experiment(region, host, carrier, browser, protocol, port,
do_traceroute, port80explicit=False, pipelining=0):
global _CARRIER_IFACES_MAGIC_DICT
port = str(port)
interface = _CARRIER_IFACES_MAGIC_DICT.get(carrier)
timestamp = time.strftime('%Y-%m-%d-%H-%M-%S')
# Start server tcpdump
server = xmlrpclib.ServerProxy('http://%s:%d' % (host, FLAGS.rpcport))
logging.info('Calling .start() at http://%s:%d %s.' % \
(host, FLAGS.rpcport, '_'.join([timestamp, region,
carrier, browser, port])))
pid = server.start(timestamp, region, carrier, browser, pipelining, port)
logging.info('Started on server with PID %d.' % pid)
# Start our tcpdump
pcap_name = '%s_%s_%s_%s_%s_%s.client.pcap' % \
(timestamp, region, carrier, browser, pipelining, port)
tcpdump = subprocess.Popen(
shlex.split('tcpdump -i %s -w %s' % (interface, pcap_name)),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Start browser
# TODO(tierney): Currently only supports chrome and firefox.
to_kill = None
if browser == 'chrome':
to_kill = 'chromedriver'
elif browser == 'firefox':
to_kill = '/usr/lib/firefox-10.0.2/firefox'
if port == '80' and not port80explicit:
browser_command = './BrowserRun.py --browser %s --domain %s --pipelining %d' % \
(browser, protocol + '://' + host, pipelining)
else:
browser_command = './BrowserRun.py --browser %s --domain %s --pipelining %d' % \
(browser, protocol + '://' + host + ':' + str(port), pipelining)
logging.info('Starting browser %s.' % browser)
command = Command(browser_command)
command.run(timeout = FLAGS.timeout, pskill = to_kill)
# Kill local and remote tcpdumps.
tcpdump.terminate()
proxy_ips = server.stop(
timestamp, region, carrier, browser, pipelining, port, pid, do_traceroute)
logging.info('Proxies: %s.' % ', '.join(proxy_ips))
# Traceroute measurement.
if do_traceroute:
for proxy_ip in proxy_ips:
logging.info('Tracerouting %s.' % proxy_ip)
tr_file = '%s_%s_%s_%s_%s_%s.client.traceroute' % \
(timestamp, region, carrier, browser, port, proxy_ip)
with open(tr_file, 'w') as tr_fh:
subprocess.Popen('traceroute %s' % (proxy_ip),
shell=True, stdout=tr_fh).wait()
logging.info('Tracerouting %s.' % host)
tr_file = '%s_%s_%s_%s_%s_%s.client.traceroute' % \
(timestamp, region, carrier, browser, port, host)
with open(tr_file, 'w') as tr_fh:
subprocess.Popen('traceroute %s -m 50' % (host),
shell=True, stdout=tr_fh).wait()
# Zip up local tcpdump.
subprocess.call(['bzip2', pcap_name])