def is_pppoe_conneced(): c = Commander() rd, ed = c.command2("plog") for l in rd.split("\n"): index = l.find("local IP address") if index != -1: ip = l[index + len("local IP address"):].strip() return True, ip return False, "error"
def __init__(self, configuration): self._configuration = configuration self._communicator = Communicator(self, configuration.get_client_key(), configuration.get_computer_key()) self._commander = Commander(self) self._samplers = [ CpuSampler(self, 5), #60 * 10), DiskSampler(self, 5), #60 * 10) ConnectionSampler(self, 60), MemoSampler(self, 5), LogSampler(self, "/var/log/auth.log"), LogSampler(self, "/var/log/syslog") ]
class Server(object): def __init__(self, configuration): self._configuration = configuration self._communicator = Communicator(self, configuration.get_client_key(), configuration.get_computer_key()) self._commander = Commander(self) self._samplers = [ CpuSampler(self, 5), #60 * 10), DiskSampler(self, 5), #60 * 10) ConnectionSampler(self, 60), MemoSampler(self, 5), LogSampler(self, "/var/log/auth.log"), LogSampler(self, "/var/log/syslog") ] def run(self): logging.info("Server Initializing") # Run all components self._communicator.run() self._commander.run() for sampler in self._samplers: sampler.run() # When starting, send the current os version operating = " ".join(platform.linux_distribution()) for line in operating.splitlines(): tokens = line.split(" ", 1) self._communicator.send_statistics( "system", dict(os=tokens[0], name=os.uname()[1], version=tokens[1], cpu=next( row.split("\t:", 1) for row in open("/proc/cpuinfo", "rt").readlines() if row.startswith("model name"))[1].strip())) # Wait for components to finish self._communicator.wait() @property def communicator(self): return self._communicator @property def configuration(self): return self._configuration
def get_files(): root = {'label': config['dir_path'], 'children': []} results = Commander.scan_only([config['dir_path']]) files = sorted([ os.path.relpath(yaml, config['dir_path']) for excel,yaml in results ]) for group_name, group_items in itertools.groupby(files, lambda filename: os.path.split(filename)[0]): child = {'label': group_name} child['children'] = [{'label': os.path.split(filename)[1], 'value':filename} for filename in group_items] root['children'].append(child) return json.dumps(root)
def change_mac(interface): mac = "%02x:%02x:%02x:%02x:%02x:%02x" % (randint(1, 16), randint( 1, 16), randint(1, 16), randint(1, 16), randint(1, 16), randint(1, 16)) print mac c = Commander() with open('/etc/ppp/mac_list', 'a+') as f: f.write("%s\t%s\n" % (datetime.datetime.now(), mac)) c.command2("ifconfig %s down" % interface) c.command2("ifconfig %s hw ether %s " % (interface, mac)) rd, ed = c.command2("ifconfig %s " % interface) print rd return True
def init_pppoe(args, status_loop=60): c = Commander() c.command2("poff -a") c.command2("killall -9 pppoe") if args.get("<username>") is None: logging.error("not have pppoe-username") return False, "pppoe param error" if args.get('<password>') is None: logging.error("not have password") return False, "pppoe param error" ok = writeconf("/etc/ppp/peers/dsl-provider.tp", "/etc/ppp/peers/dsl-provider", username=args["<username>"], interface=args["--interface"]) if not ok: logging.error("write conf /etc/ppp/peers/dsl-provider failed") return False, "write conf /etc/ppp/peers/dsl-provider failed" ok = writeconf("/etc/ppp/pap-secrets.tp", "/etc/ppp/pap-secrets", username=args["<username>"], password=args['<password>']) if not ok: logging.error("write conf /etc/ppp/pap-secrets failed") return False, "write conf /etc/ppp/pap-secrets failed" c = Commander() rd, ed = c.command2("pon dsl-provider") if len(ed) > 0: logging.error("pon failed") return False, "pon failed" for i in range(status_loop): ok, why = is_pppoe_conneced() logging.info("pppoe {ok}({why})".format(ok=ok, why=why)) if ok: return True, why time.sleep(1) return False, "pppoe error"
def main(): sys.setrecursionlimit(10000) commander = Commander() board = commander.createSudoku() commander.solveSudoku(board)
import pyglet import speech_recognition as sr import subprocess from command import Commander running = True def say(text): #whit subpproccess we can pass console commands subprocess.call('say ' + text, shell=True) r = sr.Recognizer() cmd = Commander() def initSpeech(): print("listening...") fileStart = pyglet.resource.media('audio/audio2.mp3') fileStart.play() with sr.Microphone() as source: print('Say someting') audio = r.listen(source) fileEnd = pyglet.resource.media('audio/audio1.mp3') fileEnd.play() # voice = pyglet.resource.media(audio) # voice.play() # pyglet.app.run()
def check(): results = [] request_data = request.get_json() args = request_data['fs'] # args = u'24.吉林/2014_院校专业' files = [ os.path.join(config['dir_path'], p) for p in args.strip().split(',')] for index, filename in enumerate(files): commander = Commander([filename]) commander.load_data() # 基础校验 commander.do_base_correct() commander.do_extend() commander.do_correct() commander.do_validation() error_basic, error_basic_rows = commander.filter_error_logs(loggers=['validation']) # 行级校验 commander.do_row_correction() commander.do_row_validation() error_row, error_row_rows = commander.filter_error_logs(loggers=['validation_row']) # 全局校验 commander.do_group_validation() error_global, error_global_rows = commander.filter_error_logs(loggers=['order', 'duplicate', 'continuous_unique']) # 抽样校验 error_sample = commander.do_sample_validation(verbose=False) # 数据量校验 error_count = commander.do_count_validation(verbose=False) count = { 'number': len(error_count), 'sample': len(error_sample), 'basic': sum([len(i) for i in error_basic.values()],0), 'row': sum([len(i) for i in error_row.values()],0), 'global': sum([len(i) for i in error_global.values()],0) } count['total'] = sum(count.values()) list_rows = sorted(set(error_basic_rows + error_row_rows)) list_danger = sorted(set(error_global_rows)) msg = {} msg['rows'] = ','.join([str(i) for i in list_rows]) if len(list_rows)>0 else u'无' msg['danger'] = ','.join([str(i) for i in list_danger]) if len(list_danger)>0 else u'无' results.append({ 'id': index, 'name': os.path.split(filename)[1], 'filename': filename, 'time': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'count': count, 'msg': msg, 'number': '<br>'.join(error_count), 'sample': '<br>'.join(error_sample), 'basic': '<br>'.join(list(itertools.chain(*error_basic.values()))), 'row': '<br>'.join(list(itertools.chain(*error_row.values()))), 'global': '<br>'.join(list(itertools.chain(*error_global.values()))) }) return json.dumps(results)
#!coding: utf-8 """ Usage: hkpoff Options: -h --help Show help """ import sys from docopt import docopt import time from command import Commander import logging if __name__ == "__main__": c = Commander() c.command2("poff -a") c.command2("killall -9 pppoe") rd, ed = c.command2("plog -n 20") print rd
#!coding: utf-8 """ Usage: hkplog Options: -h --help Show help """ import sys from docopt import docopt import time from command import Commander import logging if __name__ == "__main__": c = Commander() rd, ed = c.command2("plog -n 20") print rd