def __getList(self): from os import popen as os_popen PKG_NAME = 0 PKG_REL = 1 PKG_INFO = 2 map = {} try: out = os_popen("opkg update") for line in out: print("[loadOpkgfeed]", line) out = os_popen("opkg list") for line in out: if line[0] == " ": continue #print "[PkgList] ",line package = line.split(' - ') if len(package) > 2: if "Collected errors:" in package: # Schleife self.err = True return if package[PKG_NAME] in map: if map[package[PKG_NAME]][0] > package[PKG_REL]: continue map.update({ package[PKG_NAME]: [(package[PKG_REL][:-1] if len(package) < 3 else package[PKG_REL]), ("" if len(package) < 3 else package[PKG_INFO][:-1]), "0", "0"] }) out = os_popen("opkg list-installed") for line in out: package = line.split(' - ') if package[PKG_NAME] in map: map[package[PKG_NAME]][2] = "1" out = os_popen("opkg list-upgradable") for line in out: package = line.split(' - ') if package[PKG_NAME] in map: map[package[PKG_NAME]][0] = package[PKG_REL].replace( "experimental-", "exp. ") + " -> " + package[PKG_INFO][:-1].replace( "experimental-", "exp. ") map[package[PKG_NAME]][3] = "1" keys = list(map.keys()) keys.sort() return [(name, map[name][0], map[name][1], map[name][2], map[name][3]) for name in keys] except Exception as e: print("[PkgList] except: ", str(e)) return []
def check_local_cpolar_http_status(self): """ 检查本地cpolar http状态, 如果不存在则重启cpolar(测试偶尔会有问题) :return: """ process_check_response = os_popen( 'ps aux | grep \"cpolar http 80\"').readlines() if len(process_check_response) > 2: print('[+] cpolar http 80正常运行ing ...') else: print('[-] cpolar http 80未在运行, 重启ing...') # 重启 os_popen('cd ~ && nohup ./cpolar http 80 -log=stdout &')
def getCmdOutput(self, cmd): pipe = os_popen('{ ' + cmd + '; } 2>&1', 'r') text = pipe.read() pipe.close() if text[-1:] == '\n': text = text[:-1] return text
def popen(commands): r"""Executes an array of commands, connecting the standard output of one to the standard input of the other. The _commands_ parameter must be an array of commands, each command is an array of strings: the command line parameters. Returns a file object that is the output of the last command. Example:: >>> f = popen([ ['ls'], ['grep', 'java'], ['grep', 'SSL'] ]) >>> f.readlines() ['OpenSSL.java\n'] """ if _not_unix: # inefficient, use shell to pipe everything return os_popen(build_command(commands)) else: # efficient, but works only on Linux/MacOS, Unix derivatives r_out, w_out = pipe() status = spawn(commands, w_out) close(w_out) return fdopen(r_out, 'r')
def __getPartitionType(self, device): fstype = None try: if path.exists("/lib/udev/vol_id"): val = os_popen("/lib/udev/vol_id --type " + device) fstype = val.read().strip() elif path.exists("/sbin/blkid"): for line in os_popen("/sbin/blkid " + device).read().split('\n'): if not line.startswith(device): continue fstobj = re.search(r' TYPE="((?:[^"\\]|\\.)*)"', line) if fstobj: fstype = fstobj.group(1) except: print("[FlashExpander] <error get fstype>") return False return fstype
def showInfo(self): if self["filelist"].canDescent(): if self["filelist"].getSelectionIndex()!=0: curSelDir = self["filelist"].getSelection()[0] dir_stats = os_stat(curSelDir) dir_infos = "size "+str(self.formatSize(dir_stats.st_size))+" " dir_infos = dir_infos+"last-mod "+time_strftime("%d.%m.%Y %H:%M:%S",time_localtime(dir_stats.st_mtime))+" " dir_infos = dir_infos+"mode "+str(dir_stats.st_mode) self.setTitle(_(dir_infos)) else: try: ret = "" out_line = os_popen("uptime").readline() ret = ret + "at" + out_line + "\n" out_lines = [] out_lines = os_popen("cat /proc/meminfo").readlines() for lidx in range(len(out_lines)-1): tstLine = out_lines[lidx].split() if "MemTotal:" in tstLine: ret = ret + out_lines[lidx] elif "MemFree:" in tstLine: ret = ret + out_lines[lidx] + "\n" out_lines = [] out_lines = os_popen("cat /proc/stat").readlines() for lidx in range(len(out_lines)-1): tstLine = out_lines[lidx].split() if "procs_running" in tstLine: ret = ret + _("Running processes: ") + tstLine[1] except: ret = "N/A" msg = self.session.open(MessageBox, _("Dreambox model: " + self.boxtype + "\n\n" + ret), MessageBox.TYPE_INFO, windowTitle=_("Dream-Explorer")) else: curSelFile = self["filelist"].getCurrentDirectory() + self["filelist"].getFilename() file_stats = os_stat(curSelFile) file_infos = "size "+str(self.formatSize(file_stats.st_size))+" " file_infos = file_infos+"last-mod "+time_strftime("%d.%m.%Y %H:%M:%S",time_localtime(file_stats.st_mtime))+" " file_infos = file_infos+"mode "+str(file_stats.st_mode) self.setTitle(_(file_infos)) if curSelFile.endswith(".ts"): serviceref = eServiceReference("1:0:0:0:0:0:0:0:0:0:" + curSelFile) serviceHandler = eServiceCenter.getInstance() info = serviceHandler.info(serviceref) evt = info.getEvent(serviceref) if evt: self.session.open(EventViewSimple, evt, ServiceReference(serviceref))
def __getPartitionType(self,device): fstype = None try: if path.exists("/lib/udev/vol_id"): val = os_popen("/lib/udev/vol_id --type " + device) fstype = val.read().strip() elif path.exists("/sbin/blkid"): for line in os_popen("/sbin/blkid " + device).read().split('\n'): if not line.startswith(device): continue fstobj = re.search(r' TYPE="((?:[^"\\]|\\.)*)"', line) if fstobj: fstype = fstobj.group(1) except: print "[FlashExpander] <error get fstype>" return False return fstype
def getPackages(self): from os import popen as os_popen map = {} try: out = os_popen("opkg list") for line in out: if line[0] == " ": continue package = line.split(' - ') if map.has_key(package[0]): if map[package[0]][0] > package[1]: continue map.update({ package[0]: [(package[1][:-1] if len(package) < 3 else package[1]), ("" if len(package) < 3 else package[2][:-1]), "0", "0"] }) out = os_popen("opkg list-installed") for line in out: package = line.split(' - ') if map.has_key(package[0]): map[package[0]][2] = "1" out = os_popen("opkg list-upgradable") for line in out: package = line.split(' - ') if map.has_key(package[0]): map[package[0]][0] = package[1] map[package[0]][3] = package[2][:-1] keys = map.keys() keys.sort() ret = [] for name in keys: ret.append({ "name": name, "v": map[name][0], "d": map[name][1], "i": map[name][2], "u": map[name][3] }) return ret except Exception, e: return []
def getPackages(self): from os import popen as os_popen map = {} try: out = os_popen("opkg list") for line in out: if line[0] == " ": continue package = line.split(' - ') if map.has_key(package[0]): if map[package[0]][0] > package[1]: continue map.update( { package[0] : [ (package[1][:-1] if len(package) < 3 else package[1]), ("" if len(package) < 3 else package[2][:-1]), "0" , "0"] } ) out = os_popen("opkg list-installed") for line in out: package = line.split(' - ') if map.has_key(package[0]): map[package[0]][2] = "1" out = os_popen("opkg list-upgradable") for line in out: package = line.split(' - ') if map.has_key(package[0]): map[package[0]][0] = package[1] map[package[0]][3] = package[2][:-1] keys=map.keys() keys.sort() ret = [] for name in keys: ret.append({ "name": name, "v": map[name][0], "d": map[name][1], "i": map[name][2], "u": map[name][3] }) return ret except Exception, e: return []
def system_popen(cmd): mypipe = os_popen(cmd, 'r') myret = mypipe.read() try: sys_stdout.flush() except: pass try: mypipe.close() except: pass return myret
def exec_to_pod(command, pod_name, namespace='default'): """ This method uninterractively exec to the pod with the command specified. :param list command: list of the str which specify the command. (required) :param str/kubernetes.client.models.v1_pod.V1Pod pod_name: Pod name or V1Pod obj of the pod. (required) :param str namespace: namespace of the Pod. (default to 'default') :return: str: Output of the command. """ config.load_kube_config() # If someone send kubernetes.client.models.v1_pod.V1Pod object in pod_name if isinstance(pod_name, V1Pod): pod_name = pod_name.metadata.name # config.load_kube_config() conf = Configuration() assert_hostname = conf.assert_hostname conf.assert_hostname = False Configuration.set_default(conf) api = core_v1_api.CoreV1Api() try: result = stream(api.connect_get_namespaced_pod_exec, pod_name,\ namespace, command=command,\ stderr=True, stdin=False, stdout=True, tty=False) except ApiException as err: print 'Execing to NDM-Pod using kubernetes API failed:', str(err) try: result = subprocess.check_output( ['kubectl', 'exec', '-n', namespace, pod_name] + ['--'] + command) except subprocess.CalledProcessError as err: print 'Subprocess error occured',\ 'while executing command on pod:', err.returncode except Exception as err: print 'An error occured while executing command on pod:',\ str(err) try: result = os_popen('kubectl exec -n ' + namespace\ + ' ' + pod_name + ' -- '\ + ' '.join(command)).read() except Exception as err: raise err finally: # Undoing the previous changes to configuration conf.assert_hostname = assert_hostname Configuration.set_default(conf) return result
def getList(self): list = [] files = os_popen("ls /etc/apt/sources.list.d") for n in files: file = n[:-1] if file.endswith(".list") or file.endswith(".off"): print "[PkgConfList] file ", file text ="" with open("/etc/apt/sources.list.d/" + file) as f: text = f.read() print "[PkgConfList] text ",text f.close() list.append((file, text)) return list
def getList(self): list = [] files = os_popen("ls /usr/script") for n in files: file = n[:-1] if file.endswith(".sh"): print "[WebScriptList] file ", file text ="" with open("/usr/script/" + file) as f: text = f.read() print "[WebScriptList] text ",text f.close() list.append((file, text)) return list
def getList(self): list = [] files = os_popen("ls /etc/opkg") for n in files: file = n[:-1] if file.endswith(".conf") or file.endswith(".off"): print "[PkgConfList] file ", file text = "" with open("/etc/opkg/" + file) as f: text = f.read() print "[PkgConfList] text ", text f.close() list.append((file, text)) return list
def __exit__(self, exc_type, exc_val, exc_tb): if SYSTEM == 0: os_popen('taskkill /F /T /PID ' + str(self.chrome_pid)) else: pass # self.driver.service.process.kill() # os_killpg(self.chrome_pid,9) #os_popen('kill -9 chromium') ''' try: self.driver.quit() except KeyboardInterrupt: self.driver.quit() ''' if exc_type in [SystemExit, KeyboardInterrupt]: print(COLOR.NOTE, "QUIT!", COLOR.END) elif exc_type != None: send_err(str(exc_type) + '\n' + str(exc_val) + '\n' + str(exc_tb)) print('程序遇到错误,请分析处理:') print('TYPE:' + str(exc_type)) print('VAL: ' + str(exc_val)) print('TB: ' + str(exc_tb)) return True
def print_hdr(self, device, url, descr, id): try: rows, columns = os_popen('stty size', 'r').read().split() except ValueError: columns = '150' #pass print '' print '' print '-' * int(columns) print '***' print '**** DEVICE::', device print '**** TEST CASE::', url+' | '+descr print '***' print '-' * int(columns) print ''
def print_hdr(self, device, url, descr, id): try: rows, columns = os_popen("stty size", "r").read().split() except ValueError: columns = "150" # pass print "" print "" print "-" * int(columns) print "***" print "**** DEVICE::", device print "**** TEST CASE::", url + " | " + descr print "***" print "-" * int(columns) # sys.stdout.write('== > Result:: ') print "" print "== > Actual Result:: " print ""
def render_POST(self, req): data = req.args['file'][0] print("[filename req.args]", req.args['filename'][0]) filename = mbasename(req.args['filename'][0]) print("[filename]", filename) if not filename.endswith(".ipk"): return self.res % (_("wrong filetype!"), _("Close"), _("Add")) if not data: req.setResponseCode(http.OK) return self.res % (_("filesize was 0, not uploaded"), _("Close"), _("Add")) fd, fn = mkstemp(dir="/tmp/") cnt = os_write(fd, data) os_close(fd) os_chmod(fn, 0o755) if cnt <= 0: # well, actually we should check against len(data) but lets assume we fail big time or not at all try: os_unlink(fn) except OSError as oe: pass req.setResponseCode(http.OK) return self.res % (_("error writing to disk, not uploaded"), _("Close"), _("Add")) else: file = "/tmp/" + filename os_rename(fn, (file)) if file is not None: out = os_popen("opkg install %s" % file) debug = "" for line in out: debug += line else: return self.res % (_("error writing to disk, not uploaded"), _("Close"), _("Add")) req.setResponseCode(http.OK) return self.res % ((debug), _("Close"), _("Add"))
def run(self): selecteditem = self["list"].getCurrent() if selecteditem is not None: for opcja in self.myList: if opcja[0] == selecteditem: self.SkryptOpcji = opcja[2] if opcja[1] == "CONSOLE": self.session.openWithCallback( self.endrun, translatedConsole, title="%s" % selecteditem, cmdlist=[('chmod 775 %s 2>/dev/null' % self.SkryptOpcji), ('%s' % self.SkryptOpcji)]) if opcja[1] == "YESNO": self.session.openWithCallback( self.YESNO, MessageBox, _("Execute %s?") % selecteditem, MessageBox.TYPE_YESNO) if opcja[1] == "SILENT": self.system("%s" % self.SkryptOpcji) self.endrun() elif opcja[1] == "RUN": self.system("%s" % self.SkryptOpcji) self.session.openWithCallback(self.endrun, MessageBox, _("%s executed!") % (selecteditem), MessageBox.TYPE_INFO, timeout=5) elif opcja[1] == "MSG": msgline = "" popenret = os_popen(self.SkryptOpcji) for readline in popenret.readlines(): msgline += readline self.session.openWithCallback(self.endrun, MessageBox, "%s" % (msgline), MessageBox.TYPE_INFO, timeout=15)
def run(self): selecteditem = self["list"].getCurrent() if selecteditem is not None: for opcja in self.myList: if opcja[0] == selecteditem: self.SkryptOpcji = opcja[2] if opcja[1] == "CONSOLE": self.session.openWithCallback(self.endrun ,UserSkinconsole, title = "%s" % selecteditem, cmdlist = [ ('%s' % self.SkryptOpcji) ]) if opcja[1] == "YESNO": self.session.openWithCallback(self.YESNO ,MessageBox,_("Execute %s?") % selecteditem, MessageBox.TYPE_YESNO) if opcja[1] == "SILENT": self.system("%s" % self.SkryptOpcji) self.endrun() elif opcja[1] == "RUN": self.system("%s" % self.SkryptOpcji) self.session.openWithCallback(self.endrun,MessageBox,_("%s executed!") %( selecteditem ), MessageBox.TYPE_INFO, timeout=5) elif opcja[1] == "MSG": msgline = "" popenret = os_popen( self.SkryptOpcji) for readline in popenret.readlines(): msgline += readline self.session.openWithCallback(self.endrun,MessageBox, "%s" %( msgline ), MessageBox.TYPE_INFO, timeout=15)
#signal(CTRL_CLOSE_EVENT,check_exit) else: signal(SIGHUP, check_exit) if len(argv) == 1: logindata = getlogindata_phone()[0:2] mode = 0 rate = 1 noans_num = 5 else: logindata = (argv[1]).split(',') mode = int(argv[2]) rate = eval(argv[3]) noans_num = eval(argv[4]) QueryAns.noans_num = noans_num PlayMedia.rate = rate try: process = Login_courses_by_request(logindata, mode) # process = Login_courses_by_chrome(logindata,mode) #备用登录选项 process.work() finally: if chrome_pid != 0: if SYSTEM == 0: os_popen('taskkill /F /T /PID ' + str(chrome_pid)) else: #os_popen('kill -9 '+str(chrome_pid)) if len(argv) == 6 and argv[5] == 'last': killpg(getppid(), 9)
def doAction(self): self.SelectedIndex = self["list"].getIndex() printDEBUG( "doAction" , "self.keyGreenAction = '%s'" % self.keyGreenAction ) if self.BlockedInput == True and self.keyGreenAction != 'LocalPackage': printDEBUG( "doAction" , "self.BlockedInput == True" ) return with open("/proc/sys/vm/drop_caches", "w") as f: f.write("1\n") if self.keyGreenAction == 'LocalPackage': printDEBUG( "doAction" , "self.keyGreenAction == 'LocalPackage':" ) from filebrowserwidget import DirectorySelectorWidget self.session.openWithCallback(self.doManualInstall, DirectorySelectorWidget, currDir='/', title=_("Select package") , selectFiles = True ) return elif self.MainMenu == True and self.LocalFileName == "" and not self.keyGreenAction.endswith('UpgradeAll'): printDEBUG( "doAction" , "self.MainMenu == True and self.LocalFileName == "" not self.keyGreenAction.endswith('UpgradeAll')" ) #self.ActiveFilter = "" self.MainMenu = False self.refreshLists() return elif self.keyGreenAction != '': printDEBUG( "doAction" , "self.keyGreenAction = '%s'" % self.keyGreenAction ) current = self['list'].getCurrent() if current[0] == '': printDEBUG( "doAction" , "current[0] = ''" ) return #>>>>> Usuwanie pakietów... if self.keyGreenAction.find("remove") > 0: tekst=_("Are you sure, you want delete % package?") % current[0] #>>>>> przy za malej ilosci pamieci pozwalamy jedynie na remove... elif self.BlockedInstall == True: free_flash_space = self.getFreeSpace('/') human_free_space = free_flash_space / 1048576 msg = _('Only %d MB left!!!\nAt least 8MB is required to safely install and upgrade packages.') % human_free_space self.session.openWithCallback(self.InfoBoxReturn, MessageBox,msg, type = MessageBox.TYPE_INFO, timeout = 10) return #>>>>> upgrade wszystkiego... elif self.keyGreenAction == ('UpgradeAll'): if self.packages2upgrade > self.maxPackages and self.getFreeSpace(self.CacheDir) < self.maxSize * 3: #ze jest wolnego 8MB to juz wiemy self.session.openWithCallback(self.close, MessageBox,_("Too many packages and too small free space for upgrade!!!" ), type = MessageBox.TYPE_INFO, timeout = 10) return else: self.session.openWithCallback(self.doActionFullUpdate, MessageBox,_("Do you want to upgrade all packages?"), type = MessageBox.TYPE_YESNO) return #>>>>> upgrade konkretnego pakietu... elif self.keyGreenAction.startswith('opkg upgrade'): tekst=_("Do you want to upgrade %s package?") % current[0] #>>>>> wszystkie inne przypadki else: #sprawdzmy, czy mamy odpowiednio wolną przestrzeń try: result = os_popen("opkg info %s | grep -m 1 '^Size:' | cut -d ' ' -f2" % current[0]) except: result = 'ERROR' sizetxt="unknown" if result != 'ERROR': for x in result.readlines(): print "OPKG manager, packet size: %s" % x x = x.strip() if x.isdigit(): size = int(x) sizetxt="%dKB" % int(size/1024) if self.keyGreenAction.find("install") > 0: if self.LocalFileName != "": tekst=_("Are you sure to install %s package?") % self.LocalFileName else: tekst=_("Are you sure to install %s package with %s size?") % (current[0],sizetxt) else: tekst=_("Do you want to run '%s'? (package size %s)") % (self.keyGreenAction,sizetxt) if self.SkinSelectorInstalled == 0 and self.keyGreenAction.find("enigma2-skin-") > 0: # dodajemy skinSelektor self.keyGreenAction += " enigma2-plugin-skinselector" #finalnie wykonujemy akcje if None != tekst: self.session.openWithCallback(self.doActionAfterYESNO, MessageBox, tekst, type = MessageBox.TYPE_YESNO)
def __getList(self): from os import popen as os_popen PKG_NAME = 0 PKG_REL = 1 PKG_INFO = 2 map = {} try: out = os_popen("opkg update") for line in out: print "[loadOpkgfeed]", line out = os_popen("opkg list") for line in out: if line[0] == " ": continue # print "[PkgList] ",line package = line.split(" - ") if len(package) > 2: if "Collected errors:" in package: # Schleife self.err = True return if map.has_key(package[PKG_NAME]): if map[package[PKG_NAME]][0] > package[PKG_REL]: continue map.update( { package[PKG_NAME]: [ (package[PKG_REL][:-1] if len(package) < 3 else package[PKG_REL]), ("" if len(package) < 3 else package[PKG_INFO][:-1]), "0", "0", ] } ) out = os_popen("opkg list-installed") for line in out: package = line.split(" - ") if map.has_key(package[PKG_NAME]): map[package[PKG_NAME]][2] = "1" out = os_popen("opkg list-upgradable") for line in out: package = line.split(" - ") if map.has_key(package[PKG_NAME]): map[package[PKG_NAME]][0] = ( package[PKG_REL].replace("experimental-", "exp. ") + " -> " + package[PKG_INFO][:-1].replace("experimental-", "exp. ") ) map[package[PKG_NAME]][3] = "1" keys = map.keys() keys.sort() return [(name, map[name][0], map[name][1], map[name][2], map[name][3]) for name in keys] except Exception, e: print "[PkgList] except: ", str(e) return []
def run(self): selecteditem = self["list"].getCurrent() if selecteditem is not None: for opcja in self.myList: if opcja[0] == selecteditem: ClearMemory() self.OptionScript = opcja[2] self.OptionScript = self.OptionScript.replace( '[InstallPath]', config.plugins.IPTVplayersManager.InstallPath.value) self.OptionScript = self.OptionScript.replace( '[installAsFork]', str(config.plugins.IPTVplayersManager.installAsFork. value)) if opcja[1] == "CONSOLE": self.session.openWithCallback( self.endrun, translatedConsole, title="%s" % selecteditem, cmdlist=[('chmod 775 %s 2>/dev/null' % self.OptionScript), ('%s' % self.OptionScript)]) if opcja[1] == "YESNO": self.session.openWithCallback( self.YESNO, MessageBox, _("Execute %s?") % selecteditem, MessageBox.TYPE_YESNO) if opcja[1] == "SILENT": os_system("%s" % self.OptionScript) self.endrun() elif opcja[1] == "RUN": os_system("%s" % self.OptionScript) self.session.openWithCallback(self.endrun, MessageBox, _("%s executed!") % (selecteditem), MessageBox.TYPE_INFO, timeout=5) elif opcja[1] == "MSG": msgline = "" popenret = os_popen(self.OptionScript) for readline in popenret.readlines(): msgline += readline self.session.openWithCallback(self.endrun, MessageBox, "%s" % (msgline), MessageBox.TYPE_INFO, timeout=15) elif opcja[1] == "PYEXEC": try: exec(self.OptionScript) self.endrun() except Exception: pass elif opcja[1] == "DEF": try: exec(self.OptionScript, globals, locals) self.endrun() except Exception as e: self.session.openWithCallback( self.endrun, MessageBox, "Executing'%s' EXCEPTION: %s" % (self.OptionScript, str(e)), MessageBox.TYPE_INFO, timeout=15)
def current_user(): return str(os_popen("whoami").read()).replace("\n", "")
os_close(fd) os_chmod(fn, 0755) if cnt <= 0: # well, actually we should check against len(data) but lets assume we fail big time or not at all try: os_unlink(fn) except OSError, oe: pass req.setResponseCode(http.OK) return self.res % (_("error writing to disk, not uploaded"),_("Close"), _("Add")) else: file = "/tmp/" + filename os_rename(fn,(file)) if file is not None: out = os_popen("opkg install %s" %file) debug = "" for line in out: debug += line else: return self.res % (_("error writing to disk, not uploaded"),_("Close"), _("Add")) req.setResponseCode(http.OK) return self.res % ((debug), _("Close"), _("Add") ) def render_GET(self, req): req.setResponseCode(http.OK) req.setHeader('Content-type', 'text/html')
os_close(fd) os_chmod(fn, 0755) if cnt <= 0: # well, actually we should check against len(data) but lets assume we fail big time or not at all try: os_unlink(fn) except OSError, oe: pass req.setResponseCode(http.OK) return self.res % (_("error writing to disk, not uploaded"),_("Close"), _("Add")) else: file = "/tmp/" + filename os_rename(fn,(file)) if file is not None: out = os_popen("dpkg -i %s" %file) debug = "" for line in out: debug += line else: return self.res % (_("error writing to disk, not uploaded"),_("Close"), _("Add")) req.setResponseCode(http.OK) return self.res % ((debug), _("Close"), _("Add") ) def render_GET(self, req): req.setResponseCode(http.OK) req.setHeader('Content-type', 'text/html')
def getColumns(self): return int(os_popen("stty size", "r").read().split()[1])
def doAction(self): self.SelectedIndex = self["list"].getIndex() printDEBUG("doAction", "self.keyGreenAction = '%s'" % self.keyGreenAction) if self.BlockedInput == True and self.keyGreenAction != 'LocalPackage': printDEBUG("doAction", "self.BlockedInput == True") return with open("/proc/sys/vm/drop_caches", "w") as f: f.write("1\n") if self.keyGreenAction == 'LocalPackage': printDEBUG("doAction", "self.keyGreenAction == 'LocalPackage':") from filebrowserwidget import DirectorySelectorWidget self.session.openWithCallback(self.doManualInstall, DirectorySelectorWidget, currDir='/', title=_("Select package"), selectFiles=True) return elif self.MainMenu == True and self.LocalFileName == "" and not self.keyGreenAction.endswith( 'UpgradeAll'): printDEBUG( "doAction", "self.MainMenu == True and self.LocalFileName == " " not self.keyGreenAction.endswith('UpgradeAll')") #self.ActiveFilter = "" self.MainMenu = False self.refreshLists() return elif self.keyGreenAction != '': printDEBUG("doAction", "self.keyGreenAction = '%s'" % self.keyGreenAction) current = self['list'].getCurrent() if current[0] == '': printDEBUG("doAction", "current[0] = ''") return #>>>>> Usuwanie pakietów... if self.keyGreenAction.find("remove") > 0: tekst = _( "Are you sure, you want delete % package?") % current[0] #>>>>> przy za malej ilosci pamieci pozwalamy jedynie na remove... elif self.BlockedInstall == True: free_flash_space = self.getFreeSpace('/') human_free_space = free_flash_space / 1048576 msg = _( 'Only %d MB left!!!\nAt least 8MB is required to safely install and upgrade packages.' ) % human_free_space self.session.openWithCallback(self.InfoBoxReturn, MessageBox, msg, type=MessageBox.TYPE_INFO, timeout=10) return #>>>>> upgrade wszystkiego... elif self.keyGreenAction == ('UpgradeAll'): if self.packages2upgrade > self.maxPackages and self.getFreeSpace( self.CacheDir ) < self.maxSize * 3: #ze jest wolnego 8MB to juz wiemy self.session.openWithCallback( self.close, MessageBox, _("Too many packages and too small free space for upgrade!!!" ), type=MessageBox.TYPE_INFO, timeout=10) return else: self.session.openWithCallback( self.doActionFullUpdate, MessageBox, _("Do you want to upgrade all packages?"), type=MessageBox.TYPE_YESNO) return #>>>>> upgrade konkretnego pakietu... elif self.keyGreenAction.startswith('opkg upgrade'): tekst = _("Do you want to upgrade %s package?") % current[0] #>>>>> wszystkie inne przypadki else: #sprawdzmy, czy mamy odpowiednio wolną przestrzeń try: result = os_popen( "opkg info %s | grep -m 1 '^Size:' | cut -d ' ' -f2" % current[0]) except: result = 'ERROR' sizetxt = "unknown" if result != 'ERROR': for x in result.readlines(): print "OPKG manager, packet size: %s" % x x = x.strip() if x.isdigit(): size = int(x) sizetxt = "%dKB" % int(size / 1024) if self.keyGreenAction.find("install") > 0: if self.LocalFileName != "": tekst = _("Are you sure to install %s package?" ) % self.LocalFileName else: tekst = _( "Are you sure to install %s package with %s size?" ) % (current[0], sizetxt) else: tekst = _("Do you want to run '%s'? (package size %s)") % ( self.keyGreenAction, sizetxt) if self.SkinSelectorInstalled == 0 and self.keyGreenAction.find( "enigma2-skin-") > 0: # dodajemy skinSelektor self.keyGreenAction += " enigma2-plugin-skinselector" #finalnie wykonujemy akcje if None != tekst: self.session.openWithCallback(self.doActionAfterYESNO, MessageBox, tekst, type=MessageBox.TYPE_YESNO)