def refresh_info(self, refresh=0): """ Reload the data file information and show them on the main dialog. The information here includes both metadata and hosts module info from the data file. :param refresh: A flag indicating whether the information on main dialog needs to be reloaded or not. The value could be `0` or `1`. ======= ============= refresh operation ======= ============= 0 Do NOT reload 1 Reload ======= ============= :type refresh: int """ if refresh and RetrieveData.conn is not None: RetrieveData.clear() try: RetrieveData.unpack() RetrieveData.connect_db() self.set_func_list(refresh) self.refresh_func_list() self.set_info() except (BadZipfile, IOError, OSError): self.warning_incorrect_datafile()
def __init__(self): """ Initialize a new TUI session. * Load server list from a configuration file under working directory. * Try to load the hosts data file under working directory if it exists. .. note:: IF hosts data file does not exists correctly in current working directory, a warning message box would popup. And operations to change the hosts file on current system could be done only until a new data file has been downloaded. .. seealso:: :meth:`~tui.curses_d.CursesDaemon.session_daemon` method in :class:`~tui.curses_d.CursesDaemon`. .. seealso:: :meth:`~gui.hostsutil.HostsUtil.init_main` in :class:`~gui.hostsutil.HostsUtil` class. """ super(HostsUtil, self).__init__() # Set mirrors self.settings[0][2] = CommonUtil.set_network("network.conf") # Read data file and set function list try: self.set_platform() RetrieveData.unpack() RetrieveData.connect_db() self.set_info() self.set_func_list() except IOError: self.messagebox("No data file found! Press F6 to get data file " "first.", 1) except BadZipfile: self.messagebox("Incorrect Data file! Press F6 to get a new data " "file first.", 1)
def check_version(cls): """ Compare version of local data file to the version from the server. Modified from tui.curses_d.CursesDaemon.new_version() """ if not os.path.isfile(cls.filename): return 1 RetrieveData.unpack() RetrieveData.connect_db() cls.set_info() RetrieveData.disconnect_db() local_ver = cls.hostsinfo["Version"] server_ver = cls.update["version"] local_ver = local_ver.split('.') server_ver = server_ver.split('.') for i, ver_num in enumerate(local_ver): if server_ver[i] > ver_num: return 1 return 0
def start(cls,silent=0,mode='system'): cls.make_mode=mode #Possible values are 'utf-8', 'ansi' and 'system'. cls.silent=silent cls.set_platform() cls.check_connection() cls.update = cls.check_update() if cls.check_version(): cls.show_status("Update found!") cls.fetch_update() RetrieveData.unpack() RetrieveData.connect_db() cls.set_func_list() cls.select_all() cls.set_config_bytes() mk=MakeHosts(cls) mk.make() RetrieveData.clear() return 1 else: cls.show_status("No update!") RetrieveData.clear() return 0
def init_main(self): """ Set up the elements on the main dialog. Check the environment of current operating system and current session. * Load server list from a configuration file under working directory. * Try to load the hosts data file under working directory if it exists. .. note:: IF hosts data file does not exists correctly in current working directory, a warning message box would popup. And operations to change the hosts file on current system could be done only until a new data file has been downloaded. .. seealso:: Method :meth:`~tui.hostsutil.HostsUtil.__init__` in :class:`~tui.hostsutil.HostsUtil` class. """ self.ui.SelectMirror.clear() self.set_version() # Set mirrors self.mirrors = CommonUtil.set_network("network.conf") self.set_mirrors() # Read data file and set function list try: RetrieveData.unpack() RetrieveData.connect_db() self.set_func_list(1) self.refresh_func_list() self.set_info() except IOError: self.warning_no_datafile() except BadZipfile: self.warning_incorrect_datafile() # Check if current session have root privileges self.check_writable() self.init_flag += 1