def emulatorcfg_default_check(self): """ We try to found this line: default = "emulator-binary-name" Returns ------- True Emulator is ok! False If default emulator selected is invalid and it was cleaned None If not found default line (then Retropie launch a selector) """ with open(self.m_sCfgSystemPath, "r") as oFile: for line in oFile: lValues = line.strip().split(' ') if lValues[0] == 'default': sBinaryName = lValues[2].replace('"', '') if not self.set_binary(sBinaryName): remove_line(self.m_sCfgSystemPath, "default =") return False else: logging.info("(%s) is selected as default" % self.m_sSelCore) return True #return self.set_binary(sBinaryName) return None
def get_active_folder(self): self.get_folders() value = (" ".join(ini_getlist(CRT_UTILITY_FILE, "music_folder"))).strip() if not value or value not in self.m_lFolders: value = "root" remove_line(CRT_UTILITY_FILE, "music_folder") add_line(CRT_UTILITY_FILE, 'music_folder=%s' % value) self.m_sFolder = value return self.m_sFolder
def set_oc_value(self, p_sINI, p_sValue): if not self.m_bOCEnabled: return if not p_sINI in self.m_dOCConfig['config']: return False self.__clone_cfg() if p_sValue == self.m_dOCConfig['values'][p_sINI][3][0]: remove_line(self.m_sTemp, p_sINI) else: if not ini_sect_set_key(self.m_sTemp, self.m_dOCConfig['section'], p_sINI, p_sValue): ini_sect_add_key(self.m_sTemp, self.m_dOCConfig['section'], p_sINI, p_sValue) self.__upload_cfg()
def connect(self): if self.get_ssid() == "[A:SCAN]" or self.get_pwd == "": return False touch_file(self.TMP_FILE) p_sLine1 = 'country=%s' % self.COUNTRY[self.get_country()] p_sLine2 = 'ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev' p_sLine3 = 'update_config=1' p_sSSIDFix = self.get_ssid() p_sSSIDFix = p_sSSIDFix.replace(' ', '\\ ') p_sSSIDFix = p_sSSIDFix.replace("'", '\xe2\x80\x99') p_sPWDFix = self.get_pwd() p_sPWDFix = p_sPWDFix.replace(' ', '\\ ') p_sPWDFix = p_sPWDFix.replace("'", '\xe2\x80\x99') p = subprocess.Popen('wpa_passphrase ' + p_sSSIDFix + ' ' + p_sPWDFix, stdout=subprocess.PIPE, shell=True) #output, err = p.communicate() #output = output.decode("utf-8") #err = err.decode("utf-8") output = p.communicate()[0].decode("utf-8") p.wait() if 'network={' in output: with open(self.TMP_FILE, 'w') as f: f.write(p_sLine1 + '\n') f.write(p_sLine2 + '\n') f.write(p_sLine3 + '\n') f.write(output) else: with open(self.TMP_FILE, 'w') as f: f.write(p_sLine1 + '\n') f.write(p_sLine2 + '\n') f.write(p_sLine3 + '\n') remove_line(self.TMP_FILE, '#psk="') os.system('sudo cp %s %s > /dev/null 2>&1' % (self.TMP_FILE, self.WPA_FILE)) os.system("sudo rm %s > /dev/null 2>&1" % self.TMP_FILE) p = subprocess.Popen('wpa_cli -i wlan0 reconfigure', stdout=subprocess.PIPE, shell=True) #output, err = p.communicate() #if output: output = output.decode("utf-8") #if err: err = err.decode("utf-8") output = p.communicate()[0].decode("utf-8") p.wait() p_iTime = time.time() p_bCheck = False while True: if time.time() - p_iTime > 60: return p_bCheck if self.status(): p_bCheck = True return p_bCheck time.sleep(0.2)
def host(self, p_sHost): if not self.check_ip_format(p_sHost): return False line1 = self.ini_host + '=' + '"%s"' % p_sHost line2 = self.ini_host_cfile + '=' + '"%s"' % p_sHost line3 = self.ini_host_cfile + '=' + '""' # remove both config lines for host: __netplayhostipXXX remove_line(CRT_NETPLAY_FILE, self.ini_host) remove_line(CRT_NETPLAY_FILE, self.ini_host_cfile) add_line(CRT_NETPLAY_FILE, line1) if self.get_mode() == "client": add_line(CRT_NETPLAY_FILE, line2) else: add_line(CRT_NETPLAY_FILE, line3) new = self.get_host() if new == p_sHost: return new logging.info("INFO: %s wrong edited" % self.ini_host) return False
def get_config(self): if not os.path.exists(CRT_OLED_FILE): touch_file(CRT_OLED_FILE) p_sHash = md5_file(CRT_OLED_FILE) if p_sHash != self.m_sHash_Prev: logging.info("INFO: getting configuration from file") for screen in self.m_lOLEDScrns: for item in screen: if 'scr_' in item: value = ini_get(CRT_OLED_FILE, item) if value == False: value = 0 remove_line(CRT_OLED_FILE, item) add_line(CRT_OLED_FILE, "%s = 0" % item) else: value = int(value) if value > 0: screen[item] = True screen['time'] = value * 60 elif value <= 0: screen[item] = False screen['time'] = 0 self.m_sHash_Prev = md5_file(CRT_OLED_FILE)
def emulatorcfg_per_game(self): """ Retropie allows to choice per game an specific emulator from available we check if emulator is valid or clean emulators.cfg Returns ------- False If emulator is wrong and it was cleaned True Emulator is ok or not specific emulator for this game was selected """ p_bNeedClean = False if not os.path.exists(RETROPIE_CUSTEMU_FILE): #create emulators.cfg if doesn't exists touch_file(RETROPIE_CUSTEMU_FILE) logging.info("Created emulators.cfg") sCleanName = re.sub('[^a-zA-Z0-9-_]+', '', self.m_sGameName).replace(" ", "") sGameSystemName = "%s_%s" % (self.m_sSystem, sCleanName) with open(RETROPIE_CUSTEMU_FILE, 'r') as oFile: for line in oFile: lValues = line.strip().split(' ') if lValues[0] == sGameSystemName: sBinaryName = lValues[2].replace('"', '') if self.set_binary(sBinaryName): logging.info("(%s) is " % self.m_sSelCore + \ "selected for this game, will " + \ "be the chosen core to launch") return True else: # not valid is just ignored p_bNeedClean = True # clean emulators.cfg if have an invalid binary if p_bNeedClean: logging.info("cleaning line %s from %s" % (sGameSystemName, RETROPIE_CUSTEMU_FILE)) remove_line(RETROPIE_CUSTEMU_FILE, sGameSystemName) return False return True
def get_config(self, m_sScreen=""): if not os.path.exists(CRT_OLED_FILE): touch_file(CRT_OLED_FILE) p_sHash = md5_file(CRT_OLED_FILE) if p_sHash != self.m_sHash_Prev: for item in self.m_lOLEDScrns: if 'scr_' in item: value = ini_get(CRT_OLED_FILE, item) if value == False: value = 0 remove_line(CRT_OLED_FILE, item) add_line(CRT_OLED_FILE, "%s = 0" % item) else: value = int(value) if value > 0: self.m_lOLEDScrns[item] = str(value) + "m" elif value <= 0: self.m_lOLEDScrns[item] = "Disabled" self.m_sHash_Prev = md5_file(CRT_OLED_FILE) if m_sScreen: for item in self.m_lOLEDScrns: if item == m_sScreen: return self.m_lOLEDScrns[item] return 0
def clean_oc_options(self): p_lOCFullOpt = [ 'arm_freq', 'gpu_freq', 'core_freq', 'h264_freq', 'isp_freq', 'v3d_freq', 'hevc_freq', 'sdram_freq', 'over_voltage', 'over_voltage_sdram', 'over_voltage_sdram_c', 'over_voltage_sdram_i', 'over_voltage_sdram_p', 'force_turbo', 'initial_turbo', 'arm_freq_min', 'core_freq_min', 'gpu_freq_min', 'h264_freq_min', 'isp_freq_min', 'v3d_freq_min', 'hevc_freq_min', 'sdram_freq_min', 'over_voltage_min', 'temp_limit', 'temp_soft_limit', 'sdram_schmoo', 'avoid_pwm_pll', ] p_dOptToMove = [] p_lSection = [] p_bSectFound = False if ini_set_check_section(RASP_BOOTCFG_FILE, self.m_dOCConfig['section']): p_lSection = ini_sect_get_keys(RASP_BOOTCFG_FILE, self.m_dOCConfig['section']) p_bSectFound = True for opt in p_lOCFullOpt: value = ini_get(RASP_BOOTCFG_FILE, opt) if value: p_bFound = False for item in p_lSection: if opt == item[0]: p_bFound = True if not p_bFound: try: value = int(value) except: pass p_dOptToMove.append([opt, value]) valueOut = ini_outofsect_get_key(RASP_BOOTCFG_FILE, self.m_dOCConfig['section'], 'dtparam=sd_overclock') valueIn = ini_sect_get_key(RASP_BOOTCFG_FILE, self.m_dOCConfig['section'], 'dtparam=sd_overclock') if valueOut: if valueIn: try: valueIn = int(valueIn) except: pass p_dOptToMove.append(['dtparam=sd_overclock', valueIn]) else: try: valueOut = int(valueOut) except: pass p_dOptToMove.append(['dtparam=sd_overclock', valueOut]) if p_dOptToMove: self.__clone_cfg() if not p_bSectFound: ini_sect_create_section(self.m_sTemp, self.m_dOCConfig['section']) for opt in p_dOptToMove: remove_line(self.m_sTemp, opt[0]) if opt[1] not in self.m_dOCConfig['values'][opt[0]][3]: opt[1] = self.m_dOCConfig['values'][opt[0]][0] ini_sect_add_key(self.m_sTemp, self.m_dOCConfig['section'], opt[0], opt[1]) self.__upload_cfg()
def clean(self, p_sName): if remove_line(CRT_AUTOFREQ_FILE, p_sName): logging.info("Game was cleaned") else: logging.error("Game could not be cleaned")