def checkFanStatus(self): fan_result = common.PASS fan_bus = DEVICE_BUS['fan'] fan_alert = STATUS_ALERT['fan'] fan_led = LED_COMMAND['fan_led'] fan_normal = 'green' fan_abnormal = 'blink_amber' led_bus = DEVICE_BUS['status_led'] led_path = common.I2C_PREFIX + led_bus[0] + '/' + LED_NODES[3] status, output = common.doBash("ls " + common.I2C_PREFIX) if output.find(fan_bus[0]) != -1: for num in range(0, FAN_NUM): for alert_type in fan_alert: path = common.I2C_PREFIX + fan_bus[0] + "/fan" + str( num + 1) + "_" + alert_type result = common.readFile(path) if result != 'Error': fan_result += int(result) if fan_result != common.PASS: if self.fan_led_status != fan_abnormal: common.writeFile(led_path, fan_led[fan_abnormal]) self.fan_led_status = fan_abnormal common.syslog.syslog(common.syslog.LOG_ERR, 'FAN Status Error !!!') return common.FAIL if self.fan_led_status != fan_normal: common.writeFile(led_path, fan_led[fan_normal]) self.fan_led_status = fan_normal common.syslog.syslog(common.syslog.LOG_ERR, 'FAN Status Normal !!!') return common.PASS
def deviceInit(): # Set led for i in range(0, len(DEVICE_INIT['led'])): setGetLed(DEVICE_INIT['led'][i]) # Set tx disable cpld_bus = DEVICE_BUS['cpld'] for x in range(0, SFP_MAX_NUM): if x < CPLDB_SFP_NUM: bus = cpld_bus[1] elif x < CPLDB_SFP_NUM + CPLDA_SFP_NUM: bus = cpld_bus[0] else: bus = cpld_bus[2] path = common.I2C_PREFIX + bus + '/sfp' + str(x + 1) + '_tx_disable' result = common.writeFile(path, "0") # Set QSFP reset to normal for x in range(SFP_MAX_NUM, TOTAL_PORT_NUM): path = common.I2C_PREFIX + cpld_bus[2] + '/sfp' + str(x + 1) + '_reset' result = common.writeFile(path, "1") # Set QSFP I2C enable for x in range(SFP_MAX_NUM, TOTAL_PORT_NUM): path = common.I2C_PREFIX + cpld_bus[2] + '/sfp' + str(x + 1) + '_modeseln' result = common.writeFile(path, "0") return
def checkPsuStatus(self): psu_result = common.PASS psu_bus = DEVICE_BUS['psu'] psu_alert = STATUS_ALERT['psu'] psu_led = LED_COMMAND['pwr_led'] psu_normal = 'green' psu_abnormal = 'blink_amber' led_bus = DEVICE_BUS['status_led'] led_path = common.I2C_PREFIX + led_bus[0] + '/' + LED_NODES[1] status, output = common.doBash("ls " + common.I2C_PREFIX) if output.find(psu_bus[0]) != -1 and output.find(psu_bus[1]) != -1: for nodes in psu_bus: for alert_type in psu_alert: path = common.I2C_PREFIX + nodes + "/" + alert_type result = common.readFile(path) if result != 'Error': psu_result += int(result) if psu_result != common.PASS: if self.psu_led_status != psu_abnormal: common.writeFile(led_path, psu_led[psu_abnormal]) self.psu_led_status = psu_abnormal common.syslog.syslog(common.syslog.LOG_ERR, 'PSU Status Error !!!') return common.FAIL if self.psu_led_status != psu_normal: common.writeFile(led_path, psu_led[psu_normal]) self.psu_led_status = psu_normal common.syslog.syslog(common.syslog.LOG_ERR, 'PSU Status Normal !!!') return common.PASS
def donwload(url, path): if not os.path.exists(path): c = common.httpGet(url) common.writeFile(path, c) else: if os.path.getsize(path) < 1024: print(path, os.path.getsize(path)) c = common.httpGet(url) common.writeFile(path, c)
def registerF(): name = raw_input('请输入注册账号:').strip() passwd = raw_input('请输入注册密码:').strip() passwd2 = raw_input('请确认注册密码:').strip() if passwd == passwd2: email = raw_input('请输入注册邮箱:').strip() data = name + '|' + passwd + '|' + email writeFile(filename,data) a = '注册成功!' else: a = '<两次输入密码不一致!>' return a return render_template('register.html',register=regis)
def writeFullDictionary(language): wl = loadWordlist(language) full_dictionary = buildDictionary(wl, language) full_dictionary_filename = cm.mkpath('dictionary', language, '_full_dictionary.json') # Line reduction trick does not work for this one, use some search & replace to fix up the formatting a bit: encoded = json.dumps(full_dictionary, indent=2) encoded = encoded.replace(' [\n "', ' ["') encoded = encoded.replace('",\n "', '", "') encoded = encoded.replace('"\n ]', '"]') print(encoded) cm.writeFile(full_dictionary_filename, encoded)
def setGetLed(args): """ Commands: sys_led : System status led [green/amber/off/blink_green/blink_amber] pwr_led : Power status led [green/amber/off/blink_green/blink_amber] loc_led : Locator led [on/off/blink] fan_led : Fan led [green/amber/off/blink_green/blink_amber] """ if len(args) < 3 or args[1] not in LED_COMMAND: return setGetLed.__doc__ led_bus = DEVICE_BUS['status_led'] for i in range(0, len(LED_NODES)): if args[1] == LED_NODES[i]: path = common.I2C_PREFIX + led_bus[0] + '/' + LED_NODES[i] command = LED_COMMAND[args[1]] if args[0] == 'set': if args[2] in command: data = command[args[2]] result = common.writeFile(path, data) else: result = setGetLed.__doc__ else: result = common.readFile(node) if result != "Error": result = list(command.keys())[list(command.values()).index(result)] return result
def cache(path=None, format=None, filename=None): url = request.args.get('url', '').encode('utf-8') url = url.split('?')[0] parsed_tuple = urlparse.urlparse(url) path_dir = 'cache/' + parsed_tuple.netloc + \ os.path.dirname(parsed_tuple.path) common.mkdir_p(path_dir) filepath, tmpfilename = os.path.split(url) shotname, extension = os.path.splitext(tmpfilename) filename = path_dir + '/' + tmpfilename print(filepath, tmpfilename, shotname, extension) print(filename) # print requests.get(url).text if os.path.exists(filename): # print() if os.path.getsize(filename) < 1024: print(filename, os.path.getsize(filename)) c = common.httpGet(url) common.writeFile(path, c) c = common.readFile(filename) else: c = common.httpGet(url) common.writeFile(filename, c) if extension == '.m3u8': ts_urls = get_ts_url(c) for index, ts_url in enumerate(ts_urls): fpath = path_dir + '/' + ts_url furl = filepath + '/' + ts_url donwload(furl, fpath) return c
def save(self, keys, param): # 更新数据 self.__GetConn() self.__DB_CONN.text_factory = str try: opt = "" for key in keys.split(','): opt += key + "=?," opt = opt[0:len(opt) - 1] sql = "UPDATE " + self.__DB_TABLE + " SET " + opt + self.__OPT_WHERE common.writeFile('/tmp/test.pl', sql) # 处理拼接WHERE与UPDATE参数 tmp = list(param) for arg in self.__OPT_PARAM: tmp.append(arg) self.__OPT_PARAM = tuple(tmp) result = self.__DB_CONN.execute(sql, self.__OPT_PARAM) self.__close() self.__DB_CONN.commit() return result.rowcount except Exception, ex: return "error: " + str(ex)
request = cli_sock.recv(1024) requestStr = request.decode('utf-8').split(' ') requestType = requestStr[0].lower() requestFileName = requestStr[1] serverFilePath = 'server_data/' clientFilePath = 'client_data/' # Processing the request if requestType == "put": clientFilePath += requestFileName requestFileData = common.readFile(responseMessage, clientFilePath) if requestFileData is not None: serverFilePath += requestFileName common.writeFile(responseMessage, serverFilePath, requestFileData) elif requestType == "get": serverFilePath += requestFileName serverFileData = common.readFile(responseMessage, serverFilePath) if serverFileData is not None: clientFilePath += requestFileName common.writeFile(responseMessage, clientFilePath, serverFileData) elif requestType == "list": common.listDirectoryContents(responseMessage) else: print("Server can't deal with this request. \n")
# -- coding:utf-8 -- import time import sys import os chdir = os.getcwd() sys.path.append(chdir + '/class/core') sys.path.append("/usr/local/lib/python2.7/site-packages") import common if not os.path.exists(os.getcwd() + '/logs'): os.mkdir(os.getcwd() + '/logs') if not os.path.exists('data/port.pl'): common.writeFile('data/port.pl', '9000') app_port = common.readFile('data/port.pl') bind = [] if os.path.exists('data/ipv6.pl'): bind.append('[0:0:0:0:0:0:0:0]:%s' % app_port) else: bind.append('0.0.0.0:%s' % app_port) threads = 2 backlog = 512 reload = True daemon = True worker_class = 'geventwebsocket.gunicorn.workers.GeventWebSocketWorker' timeout = 7200 keepalive = 60