From 01214ad01bea18657a9d88a21e33c59bf87ccb02 Mon Sep 17 00:00:00 2001 From: huhamhire Date: Sun, 19 Jan 2014 18:58:13 +0800 Subject: [PATCH 01/11] update docstring for __version__ --- README.rst | 10 +++++----- __version__.py | 2 +- doc/dev/index.rst | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index c5eb85f..9232147 100644 --- a/README.rst +++ b/README.rst @@ -4,11 +4,11 @@ Hosts Setup Utility Introduction ============ -Since the governments of some countries are using the blocking the internet -access to several websites and web service providers which includes some world -famous sites like Google, YouTube, twitter, Facebook, and Wikipedia etc., we -designed this tiny utility in order to help people getting through the -Internet blockade. +Since the governments of some countries are using technical methods blocking +internet access to some websites and web service providers which includes some +world famous sites like Google, YouTube, twitter, Facebook, and Wikipedia +etc., we designed this tiny utility in order to help people getting through +the Internet blockade. `Hosts Setup Utility` provides basic tools to manage the hosts file on current operating systems. It also provides both support for Graphical Desktop diff --git a/__version__.py b/__version__.py index baae79d..8ec75b6 100644 --- a/__version__.py +++ b/__version__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# __version__.py : +# __version__.py : Version info for Hosts Setup Tool. # # Copyleft (C) 2014 - huhamhire hosts team # ===================================================================== diff --git a/doc/dev/index.rst b/doc/dev/index.rst index fe31d16..0da3203 100644 --- a/doc/dev/index.rst +++ b/doc/dev/index.rst @@ -1,11 +1,11 @@ Hosts Setup Utility Developer Documentation =========================================== -Since the government of some countries are using the blocking the internet -access to several websites and web service providers which includes some world -famous sites like Google, YouTube, twitter, Facebook, and Wikipedia etc., we -designed this tiny utility in order to help people getting through the -Internet blockade. +Since the governments of some countries are using technical methods blocking +internet access to some websites and web service providers which includes some +world famous sites like Google, YouTube, twitter, Facebook, and Wikipedia +etc., we designed this tiny utility in order to help people getting through +the Internet blockade. Chapter one of this documentation contains a brief introduction of `Hosts Setup Utility` and basic usage to start this tool. While the others From f30408f331df30673ca09e1070dab8b19f0ea6f7 Mon Sep 17 00:00:00 2001 From: huhamhire Date: Mon, 20 Jan 2014 15:13:11 +0800 Subject: [PATCH 02/11] fix bug in terminal after quit from curses --- tui/curses_ui.py | 8 ++++++++ tui/hostsutil.py | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tui/curses_ui.py b/tui/curses_ui.py index 80a908b..87bf6cf 100644 --- a/tui/curses_ui.py +++ b/tui/curses_ui.py @@ -163,6 +163,14 @@ def __init__(self): for i, color in enumerate(self.colorpairs): curses.init_pair(i + 1, *color) + def __del__(self): + """ + Reset terminal before quit. + """ + curses.nocbreak() + curses.echo() + curses.endwin() + def banner(self): """ Draw the banner in the TUI window. diff --git a/tui/hostsutil.py b/tui/hostsutil.py index 7796279..585c125 100644 --- a/tui/hostsutil.py +++ b/tui/hostsutil.py @@ -99,8 +99,10 @@ def __init__(self): def __del__(self): """ - Clear up the temporary data file while TUI session is finished. + Reset the terminal and clear up the temporary data file while TUI + session is finished. """ + super(HostsUtil, self).__del__() try: RetrieveData.clear() except: From 2552e76cb36c8f3061a56ef05ca852b5aee1b7c5 Mon Sep 17 00:00:00 2001 From: huhamhire Date: Tue, 21 Jan 2014 15:14:20 +0800 Subject: [PATCH 03/11] merge make hosts base module from gui and tui into util --- gui/_make.py | 123 +++--------------------------- gui/qdialog_d.py | 9 +-- tui/__doc__.py | 10 +-- tui/curses_d.py | 14 +++- util/__doc__.py | 9 +++ util/__init__.py | 3 +- tui/_make.py => util/makehosts.py | 78 ++++++++++++------- 7 files changed, 89 insertions(+), 157 deletions(-) rename tui/_make.py => util/makehosts.py (65%) diff --git a/gui/_make.py b/gui/_make.py index 548be79..d72e52c 100644 --- a/gui/_make.py +++ b/gui/_make.py @@ -18,9 +18,10 @@ import sys sys.path.append("..") from util import RetrieveData +from util import MakeHosts -class QSubMakeHosts(QtCore.QThread): +class QSubMakeHosts(QtCore.QThread, MakeHosts): """ QSubMakeHosts is a subclass of :class:`PyQt4.QtCore.QThread`. This class contains methods to make a new hosts file for client. @@ -72,37 +73,12 @@ class QSubMakeHosts(QtCore.QThread): .. seealso:: Method :meth:`~gui.qdialog_d.QDialogDaemon.move_hosts` in :class:`~gui.qdialog_d.QDialogDaemon` class. - :ivar int count: Number of the module being processed currently in the - operation sequence. - :ivar str make_mode: Operation mode for making hosts file. The valid value - could be one of `system`, `ansi`, and `utf-8`. - - .. seealso:: :attr:`make_mode` in - :class:`~gui.qdialog_d.QDialogDaemon` class. - - :ivar str hostname: File Name of hosts file. - :ivar file hosts_file: The hosts file to write hosts to. - :ivar dict make_cfg: Configuration to make a new hosts file. - :ivar int mod_num: Total number of modules written to hosts file. - :ivar str eol: End-of-Line used by the hosts file created. - :ivar time make_time: Timestamp of making hosts file. - - .. seealso:: :class:`tui._make.MakeHosts` class. + .. seealso:: :class:`util.makehosts.MakeHosts` class. """ info_trigger = QtCore.pyqtSignal(str, int) fina_trigger = QtCore.pyqtSignal(str, int) move_trigger = QtCore.pyqtSignal() - count = 0 - make_mode = "" - - hostname = "" - hosts_file = None - make_cfg = {} - mod_num = 0 - eol = "" - make_time = None - def __init__(self, parent): """ Initialize a new instance of this class. Retrieve configuration from @@ -114,40 +90,21 @@ class to fetch settings from. .. warning:: :attr:`parent` MUST NOT be set as `None`. """ - super(QSubMakeHosts, self).__init__(parent) - self.count = 0 - self.make_cfg = parent.make_cfg - self.make_mode = parent.make_mode - make_path = parent.make_path - self.hostname = parent.hostname - if parent.make_mode == "system": - self.eol = parent.sys_eol - self.hosts_file = open("hosts", "wb") - elif parent.make_mode == "ansi": - self.eol = "\r\n" - self.hosts_file = open(unicode(make_path), "wb") - elif parent.make_mode == "utf-8": - self.eol = "\n" - self.hosts_file = open(unicode(make_path), "wb") + QtCore.QThread.__init__(self, parent) + MakeHosts.__init__(self, parent) def run(self): """ Start operations to retrieve data from the data file and generate new hosts file. """ - RetrieveData.connect_db() start_time = time.time() - self.make_time = start_time - self.write_head() - self.write_info() - self.get_hosts(self.make_cfg) - self.hosts_file.close() + self.make() end_time = time.time() total_time = "%.4f" % (end_time - start_time) self.fina_trigger.emit(total_time, self.count) if self.make_mode == "system": self.move_trigger.emit() - RetrieveData.disconnect_db() def get_hosts(self, make_cfg): """ @@ -167,69 +124,9 @@ def get_hosts(self, make_cfg): mods = RetrieveData.get_ids(mod_cfg) for mod_id in mods: self.mod_num += 1 + hosts, mod_name = RetrieveData.get_host(part_id, mod_id) + self.info_trigger.emit(mod_name, self.mod_num) if part_id == 0x02: - self.write_localhost_mod(part_id, mod_id) + self.write_localhost_mod(hosts) else: - self.write_common_mod(part_id, mod_id) - - def write_head(self): - """ - Write the head part into the new hosts file. - """ - for head_str in RetrieveData.get_head(): - self.hosts_file.write("%s%s" % (head_str[0], self.eol)) - - def write_info(self): - """ - Write the information part into the new hosts file. - """ - info = RetrieveData.get_info() - info_lines = [ - "#", - "# %s: %s" % ("Version", info["Version"]), - "# %s: %s" % ("BuildTime", info["Buildtime"]), - "# %s: %s" % ("ApplyTime", int(self.make_time)), - "#" - ] - for line in info_lines: - self.hosts_file.write("%s%s" % (line, self.eol)) - - def write_common_mod(self, part_id, mod_id): - """ - Write hosts entries in a module specified by `mod_id` from a part of - the data file to the new hosts file specified by `part_id`. - - :param part_id: Index number of a part in the data file. - :type part_id: int - :param mod_id: Index number of a module in the data file. - :type mod_id: int - """ - hosts, mod_name = RetrieveData.get_host(part_id, mod_id) - self.info_trigger.emit(mod_name, self.mod_num) - self.hosts_file.write( - "%s# Section Start: %s%s" % (self.eol, mod_name, self.eol)) - for host in hosts: - self.hosts_file.write("%s %s%s" % (host[0], host[1], self.eol)) - self.count += 1 - self.hosts_file.write("# Section End: %s%s" % (mod_name, self.eol)) - - def write_localhost_mod(self, part_id, mod_id): - """ - Write hosts entries in a localhost module specified by `mod_id` from a - part of the data file to the new hosts file specified by `part_id`. - - :param part_id: Index number of a part in the data file. - :type part_id: int - :param mod_id: Index number of a module in the data file. - :type mod_id: int - """ - hosts, mod_name = RetrieveData.get_host(part_id, mod_id) - self.info_trigger.emit(mod_name, self.mod_num) - self.hosts_file.write( - "%s# Section Start: Localhost%s" % (self.eol, self.eol)) - for host in hosts: - if "#Replace" in host[1]: - host = (host[0], self.hostname) - self.hosts_file.write("%s %s%s" % (host[0], host[1], self.eol)) - self.count += 1 - self.hosts_file.write("# Section End: Localhost%s" % (self.eol)) \ No newline at end of file + self.write_common_mod(hosts, mod_name) diff --git a/gui/qdialog_d.py b/gui/qdialog_d.py index b03df86..f446dab 100644 --- a/gui/qdialog_d.py +++ b/gui/qdialog_d.py @@ -81,7 +81,7 @@ class and parent class of :class:`~gui.qdialog_slots.QDialogSlots`. could be one of `system`, `ansi`, and `utf-8`. .. seealso:: :attr:`make_mode` in - :class:`~gui._make.QSubMakeHosts` class. + :class:`~util.makehosts.MakeHosts` class. :ivar str sys_eol: The End-Of-Line marker. This maker could typically be one of `CR`, `LF`, or `CRLF`. @@ -89,7 +89,6 @@ class and parent class of :class:`~gui.qdialog_slots.QDialogSlots`. .. seealso:: :attr:`sys_eol` in :class:`~tui.curses_ui.CursesUI` class. """ - _down_flag = 0 _update = {} @@ -99,12 +98,12 @@ class and parent class of :class:`~gui.qdialog_slots.QDialogSlots`. choice = [[], []] slices = [[], []] make_cfg = {} - platform = "" + platform = '' hostname = '' hosts_path = '' - sys_eol = "" + sys_eol = '' - make_mode = "" + make_mode = '' def __init__(self): super(QDialogDaemon, self).__init__() diff --git a/tui/__doc__.py b/tui/__doc__.py index 37344c1..7849776 100644 --- a/tui/__doc__.py +++ b/tui/__doc__.py @@ -42,6 +42,7 @@ :members: .. automethod:: tui.curses_ui.CursesUI.__init__ + .. automethod:: tui.curses_ui.CursesUI.__del__ FetchUpdate @@ -51,13 +52,4 @@ :members: .. automethod:: tui._update.FetchUpdate.__init__ - - -MakeHosts ---------- - -.. autoclass:: tui._make.MakeHosts - :members: - - .. automethod:: tui._make.MakeHosts.__init__ """ \ No newline at end of file diff --git a/tui/curses_d.py b/tui/curses_d.py index a57f165..29939ff 100644 --- a/tui/curses_d.py +++ b/tui/curses_d.py @@ -21,11 +21,11 @@ import sys from curses_ui import CursesUI -from _make import MakeHosts from _update import FetchUpdate sys.path.append("..") from util import CommonUtil, RetrieveData +from util import MakeHosts class CursesDaemon(CursesUI): @@ -106,6 +106,14 @@ class CursesDaemon(CursesUI): :ivar str hosts_path: The absolute path to the hosts file on current operating system. + :ivar str make_mode: Operation mode for making hosts file. The valid value + could be one of `system`, `ansi`, and `utf-8`. + + .. seealso:: :attr:`make_mode` in + :class:`~util.makehosts.MakeHosts` class. + + :ivar str make_path: Temporary path to store generated hosts file. The + default value of :attr:`make_path` is "`./hosts`". :ivar list _ops_keys: Hot keys used to start a specified operation. Default operation keys are `F5`, `F6`, and `F10`. :ivar list _hot_keys: Hot keys used to select a item or confirm an @@ -124,6 +132,9 @@ class CursesDaemon(CursesUI): hostname = '' hosts_path = '' + make_mode = '' + make_path = "./hosts" + _ops_keys = [curses.KEY_F5, curses.KEY_F6, curses.KEY_F10] _hot_keys = [curses.KEY_UP, curses.KEY_DOWN, 10, 32] @@ -213,6 +224,7 @@ def session_daemon(self): confirm = self.messagebox(msg, 2) if confirm: self.set_config_bytes() + self.make_mode = "system" maker = MakeHosts(self) maker.make() self.move_hosts() diff --git a/util/__doc__.py b/util/__doc__.py index b7cdf49..7e87193 100644 --- a/util/__doc__.py +++ b/util/__doc__.py @@ -22,6 +22,15 @@ :members: +MakeHosts +--------- + +.. autoclass:: util.makehosts.MakeHosts + :members: + + .. automethod:: util.makehosts.MakeHosts.__init__ + + RetrieveData ------------ .. autoclass:: util.retrievedata.RetrieveData diff --git a/util/__init__.py b/util/__init__.py index 817cffe..25acfea 100644 --- a/util/__init__.py +++ b/util/__init__.py @@ -11,6 +11,7 @@ # ===================================================================== from common import CommonUtil +from makehosts import MakeHosts from retrievedata import RetrieveData -__all__ = ["CommonUtil", "RetrieveData"] \ No newline at end of file +__all__ = ["CommonUtil", "MakeHosts", "RetrieveData"] \ No newline at end of file diff --git a/tui/_make.py b/util/makehosts.py similarity index 65% rename from tui/_make.py rename to util/makehosts.py index 3b0571a..cb8be71 100644 --- a/tui/_make.py +++ b/util/makehosts.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# _make.py: Make a hosts file. +# makehosts.py: Make a hosts file. # # Copyleft (C) 2014 - huhamhire # ===================================================================== @@ -12,11 +12,9 @@ __author__ = "huhamhire " -import sys import time -sys.path.append("..") -from util import RetrieveData +from retrievedata import RetrieveData class MakeHosts(object): @@ -24,19 +22,30 @@ class MakeHosts(object): MakeHosts class contains methods to make a hosts file with host entries from a single data file. + :ivar str make_mode: Operation mode for making hosts file. The valid value + could be one of `system`, `ansi`, and `utf-8`. + + .. seealso:: :attr:`make_mode` in + :class:`~gui.qdialog_d.QDialogDaemon` class. + :ivar str hostname: File Name of hosts file. :ivar file hosts_file: The hosts file to write hosts to. :ivar int mod_num: Total number of modules written to hosts file. + :ivar int count: Number of the module being processed currently in the + operation sequence. :ivar dict make_cfg: Configuration to make a new hosts file. :ivar str eol: End-of-Line used by the hosts file created. :ivar time make_time: Timestamp of making hosts file. - .. seealso:: :class:`gui._make.QSubMakeHosts` class. + .. seealso:: :class:`gui._make.QSubMakeHosts` class and + :class:`tui.curses_d.CursesDaemon` class. """ + make_mode = "" hostname = "" hosts_file = None make_cfg = {} mod_num = 0 + count = 0 eol = "" make_time = None @@ -50,10 +59,19 @@ class to retrieve configuration with. .. warning:: :attr:`parent` MUST NOT be set as `None`. """ + self.count = 0 self.make_cfg = parent.make_cfg self.hostname = parent.hostname - self.eol = parent.sys_eol - self.hosts_file = open("hosts", "wb") + make_path = parent.make_path + if parent.make_mode == "system": + self.eol = parent.sys_eol + self.hosts_file = open("hosts", "wb") + elif parent.make_mode == "ansi": + self.eol = "\r\n" + self.hosts_file = open(unicode(make_path), "wb") + elif parent.make_mode == "utf-8": + self.eol = "\n" + self.hosts_file = open(unicode(make_path), "wb") def make(self): """ @@ -86,10 +104,11 @@ def get_hosts(self, make_cfg): mods = RetrieveData.get_ids(mod_cfg) for mod_id in mods: self.mod_num += 1 + hosts, mod_name = RetrieveData.get_host(part_id, mod_id) if part_id == 0x02: - self.write_localhost_mod(part_id, mod_id) + self.write_localhost_mod(hosts) else: - self.write_common_mod(part_id, mod_id) + self.write_common_mod(hosts, mod_name) def write_head(self): """ @@ -113,38 +132,41 @@ def write_info(self): for line in info_lines: self.hosts_file.write("%s%s" % (line, self.eol)) - def write_common_mod(self, part_id, mod_id): + def write_common_mod(self, hosts, mod_name): """ - Write hosts entries in a module specified by `mod_id` from a part of - the data file to the new hosts file specified by `part_id`. + Write hosts entries :attr:`hosts` from a module named `hosts` in the + hosts data file.. - :param part_id: Index number of a part in the data file. - :type part_id: int - :param mod_id: Index number of a module in the data file. - :type mod_id: int + :param hosts: Hosts entries from a part in the data file. + :type hosts: list + :param mod_name: Name of a module from the data file. + :type mod_name: str """ - hosts, mod_name = RetrieveData.get_host(part_id, mod_id) self.hosts_file.write( "%s# Section Start: %s%s" % (self.eol, mod_name, self.eol)) for host in hosts: - self.hosts_file.write("%s %s%s" % (host[0], host[1], self.eol)) + ip = host[0] + if len(ip) < 16: + ip = ip.ljust(16) + self.hosts_file.write("%s %s%s" % (ip, host[1], self.eol)) + self.count += 1 self.hosts_file.write("# Section End: %s%s" % (mod_name, self.eol)) - def write_localhost_mod(self, part_id, mod_id): + def write_localhost_mod(self, hosts): """ - Write hosts entries in a localhost module specified by `mod_id` from a - part of the data file to the new hosts file specified by `part_id`. + Write localhost entries :attr:`hosts` into the hosts file. - :param part_id: Index number of a part in the data file. - :type part_id: int - :param mod_id: Index number of a module in the data file. - :type mod_id: int + :param hosts: Hosts entries from a part in the data file. + :type hosts: list """ - hosts, mod_name = RetrieveData.get_host(part_id, mod_id) self.hosts_file.write( "%s# Section Start: Localhost%s" % (self.eol, self.eol)) for host in hosts: if "#Replace" in host[1]: host = (host[0], self.hostname) - self.hosts_file.write("%s %s%s" % (host[0], host[1], self.eol)) - self.hosts_file.write("# Section End: Localhost%s" % self.eol) + ip = host[0] + if len(ip) < 16: + ip = ip.ljust(16) + self.hosts_file.write("%s %s%s" % (ip, host[1], self.eol)) + self.count += 1 + self.hosts_file.write("# Section End: Localhost%s" % self.eol) \ No newline at end of file From 062bb6d6dfbf8b44a2cf07ed91495f8c13817578 Mon Sep 17 00:00:00 2001 From: huhamhire Date: Tue, 21 Jan 2014 20:05:04 +0800 Subject: [PATCH 04/11] add customized hosts list support for gui --- __version__.py | 1 + gui/__list_trans.py | 6 ++++++ gui/_make.py | 9 ++++++--- gui/hostsutil.py | 1 + gui/pyqt/util_ui.ui | 13 +++++++++++++ gui/qdialog_d.py | 5 ++++- gui/qdialog_slots.py | 2 +- gui/qdialog_ui.py | 30 +++++++++++++++++++++++------- gui/style_rc.py | 4 ++-- gui/util_rc.py | 4 ++-- gui/util_ui.py | 8 ++++++-- tui/curses_ui.py | 5 +++-- util/makehosts.py | 22 ++++++++++++++++++++++ util/retrievedata.py | 6 +++++- 14 files changed, 95 insertions(+), 21 deletions(-) diff --git a/__version__.py b/__version__.py index 8ec75b6..cf7cba5 100644 --- a/__version__.py +++ b/__version__.py @@ -15,4 +15,5 @@ # ===================================================================== __version__ = "1.9.8" +__release__ = "beta" __revision__ = "$Id$" \ No newline at end of file diff --git a/gui/__list_trans.py b/gui/__list_trans.py index 058d819..6de1382 100644 --- a/gui/__list_trans.py +++ b/gui/__list_trans.py @@ -22,6 +22,9 @@ # __list_trans (list): A list containing names of function list items # for translator to translate. __list_trans = [ + _translate("Util", "customize", None), + _translate("Util", "google", None), + _translate("Util", "google-apis", None), _translate("Util", "google(cn)", None), _translate("Util", "google(hk)", None), _translate("Util", "google(us)", None), @@ -34,6 +37,9 @@ _translate("Util", "wikipedia", None), _translate("Util", "institutions", None), _translate("Util", "steam", None), + _translate("Util", "github", None), + _translate("Util", "dropbox", None), + _translate("Util", "wordpress", None), _translate("Util", "others", None), _translate("Util", "adblock-hostsx", None), _translate("Util", "adblock-mvps", None), diff --git a/gui/_make.py b/gui/_make.py index d72e52c..f20b3cb 100644 --- a/gui/_make.py +++ b/gui/_make.py @@ -23,14 +23,15 @@ class QSubMakeHosts(QtCore.QThread, MakeHosts): """ - QSubMakeHosts is a subclass of :class:`PyQt4.QtCore.QThread`. This class - contains methods to make a new hosts file for client. + QSubMakeHosts is a subclass of :class:`PyQt4.QtCore.QThread` and class + :class:`~util.makehosts.MakeHosts`. This class contains methods to make a + new hosts file for client. .. inheritance-diagram:: gui._make.QSubMakeHosts :parts: 1 .. note:: The instance of this class should be created in an individual - thread. And an instance of class should be set as :attr:`parent` + thread. And an instance of class should be set as :attr:`parent` here. :ivar PyQt4.QtCore.pyqtSignal info_trigger: An instance of @@ -128,5 +129,7 @@ def get_hosts(self, make_cfg): self.info_trigger.emit(mod_name, self.mod_num) if part_id == 0x02: self.write_localhost_mod(hosts) + elif part_id == 0x04: + self.write_customized() else: self.write_common_mod(hosts, mod_name) diff --git a/gui/hostsutil.py b/gui/hostsutil.py index 400dcac..e099654 100644 --- a/gui/hostsutil.py +++ b/gui/hostsutil.py @@ -103,6 +103,7 @@ def init_main(self): :class:`~tui.hostsutil.HostsUtil` class. """ self.ui.SelectMirror.clear() + self.set_version() # Set mirrors self.mirrors = CommonUtil.set_network("network.conf") self.set_mirrors() diff --git a/gui/pyqt/util_ui.ui b/gui/pyqt/util_ui.ui index 031c55c..87b2915 100644 --- a/gui/pyqt/util_ui.ui +++ b/gui/pyqt/util_ui.ui @@ -638,6 +638,19 @@ Powered by PyQT + + + + 380 + 20 + 250 + 25 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + SelectMirror diff --git a/gui/qdialog_d.py b/gui/qdialog_d.py index f446dab..0ad8418 100644 --- a/gui/qdialog_d.py +++ b/gui/qdialog_d.py @@ -275,7 +275,10 @@ def set_config_bytes(self, mode): else: localhost_word = 0x0008 selection[0x02] = localhost_word - ch_parts = (0x08, 0x20 if ip_flag else 0x10, 0x40) + ch_parts = [0x08, 0x20 if ip_flag else 0x10, 0x40] + # Set customized module if exists + if os.path.isfile(self.custom): + ch_parts.insert(0, 0x04) slices = self.slices[ip_flag] for i, part in enumerate(ch_parts): part_cfg = self._funcs[ip_flag][slices[i]:slices[i + 1]] diff --git a/gui/qdialog_slots.py b/gui/qdialog_slots.py index 42d24d5..fabb8d2 100644 --- a/gui/qdialog_slots.py +++ b/gui/qdialog_slots.py @@ -170,7 +170,7 @@ def on_Selection_changed(self, item): :type item: int """ ip_flag = self._ipv_id - func_id = self.listWidget().row(item) + func_id = self.ui.Functionlist.row(item) if self._funcs[ip_flag][func_id] == 0: self._funcs[ip_flag][func_id] = 1 else: diff --git a/gui/qdialog_ui.py b/gui/qdialog_ui.py index bbdefc1..6be8f33 100644 --- a/gui/qdialog_ui.py +++ b/gui/qdialog_ui.py @@ -20,13 +20,13 @@ from PyQt4 import QtCore, QtGui -from language import LangUtil -from util_ui import Ui_Util, _translate, _fromUtf8 - import sys sys.path.append("..") from util import RetrieveData, CommonUtil +from __version__ import __version__, __release__ +from language import LangUtil +from util_ui import Ui_Util, _translate, _fromUtf8 # Path to store language files LANG_DIR = "./gui/lang/" @@ -58,6 +58,8 @@ class QDialogUI(QtGui.QDialog, object): :ivar object ui: Form implementation declares layout of the main dialog which is generated from a UI file designed by `Qt Designer`. + :ivar str custom: File name of User Customized Hosts File. Customized + hosts would be able to select if this file exists. """ _cur_ver = "" _trans = None @@ -68,6 +70,8 @@ class QDialogUI(QtGui.QDialog, object): plat_flag = True ui = None + custom = "customize.hosts" + def __init__(self): """ Initialize a new instance of this class. Set the UI object and current @@ -198,6 +202,10 @@ def set_conn_status(self, status): self.set_label_color(self.ui.labelConnStat, color) self.set_label_text(self.ui.labelConnStat, stat) + def set_version(self): + version = "".join(['v', __version__,' ', __release__]) + self.set_label_text(self.ui.VersionLabel, version) + def set_info(self): """ Set the information of the current local data file. @@ -255,6 +263,12 @@ def set_func_list(self, new=0): if new: for ip in range(2): choice, defaults, slices = RetrieveData.get_choice(ip) + if os.path.isfile(self.custom): + choice.insert(0, [4, 1, 0, "customize"]) + defaults[0x04] = [1] + for i in range(len(slices)): + slices[i] += 1 + slices.insert(0, 0) self.choice[ip] = choice self.slices[ip] = slices funcs = [] @@ -282,6 +296,7 @@ def refresh_func_list(self): """ ip_flag = self._ipv_id self.ui.Functionlist.clear() + for f_id, func in enumerate(self.choice[self._ipv_id]): item = QtGui.QListWidgetItem() if self._funcs[ip_flag][f_id] == 1: @@ -312,9 +327,10 @@ def set_make_progress(self, mod_name, mod_num): total_mods_num = self._funcs[self._ipv_id].count(1) + 1 prog = 100 * mod_num / total_mods_num self.ui.Prog.setProperty("value", prog) + module = unicode(_translate("Util", mod_name, None)) message = unicode(_translate( "Util", "Applying module: %s(%s/%s)", None) - ) % (mod_name, mod_num, total_mods_num) + ) % (module, mod_num, total_mods_num) self.ui.Prog.setFormat(message) self.set_make_message(message) @@ -323,9 +339,9 @@ def set_message(self, title, message): Show a message box with a :attr:`message` and a :attr:`title`. :param title: Title of the message box to be displayed. - :type title: str + :type title: unicode :param message: Message in the message box. - :type message: str + :type message: unicode """ self.ui.FunctionsBox.setTitle(_translate("Util", title, None)) self.ui.Functionlist.clear() @@ -340,7 +356,7 @@ def set_make_message(self, message, start=0): hosts file in function list. :param message: Message to be displayed in the function list. - :type message: str + :type message: unicode :param start: A flag indicating whether the message is the first one in the making progress or not. Default value is `0`. diff --git a/gui/style_rc.py b/gui/style_rc.py index 3569b69..82c569b 100644 --- a/gui/style_rc.py +++ b/gui/style_rc.py @@ -2,8 +2,8 @@ # Resource object code # -# Created: 周一 12月 9 17:45:36 2013 -# by: The Resource Compiler for PyQt (Qt v4.8.4) +# Created: 周二 1月 21 15:46:41 2014 +# by: The Resource Compiler for PyQt (Qt v4.8.5) # # WARNING! All changes made in this file will be lost! diff --git a/gui/util_rc.py b/gui/util_rc.py index 8307540..ccfd1cc 100644 --- a/gui/util_rc.py +++ b/gui/util_rc.py @@ -2,8 +2,8 @@ # Resource object code # -# Created: 周一 12月 9 17:45:36 2013 -# by: The Resource Compiler for PyQt (Qt v4.8.4) +# Created: 周二 1月 21 15:46:41 2014 +# by: The Resource Compiler for PyQt (Qt v4.8.5) # # WARNING! All changes made in this file will be lost! diff --git a/gui/util_ui.py b/gui/util_ui.py index ed04c33..80517be 100644 --- a/gui/util_ui.py +++ b/gui/util_ui.py @@ -2,8 +2,8 @@ # Form implementation generated from reading ui file '../pyqt\util_ui.ui' # -# Created: Mon Dec 09 17:45:37 2013 -# by: PyQt4 UI code generator 4.10.2 +# Created: Tue Jan 21 15:46:43 2014 +# by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! @@ -251,6 +251,10 @@ def setupUi(self, Util): self.label = QtGui.QLabel(Util) self.label.setGeometry(QtCore.QRect(10, 390, 150, 16)) self.label.setObjectName(_fromUtf8("label")) + self.VersionLabel = QtGui.QLabel(Util) + self.VersionLabel.setGeometry(QtCore.QRect(380, 20, 250, 25)) + self.VersionLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.VersionLabel.setObjectName(_fromUtf8("VersionLabel")) self.labelIP.setBuddy(self.SelectMirror) self.labelMirror.setBuddy(self.SelectIP) diff --git a/tui/curses_ui.py b/tui/curses_ui.py index 87bf6cf..0b7c746 100644 --- a/tui/curses_ui.py +++ b/tui/curses_ui.py @@ -18,7 +18,7 @@ import sys sys.path.append("..") from util import CommonUtil -from __version__ import __version__ +from __version__ import __version__, __release__ class CursesUI(object): @@ -114,7 +114,8 @@ class CursesUI(object): :class:`~gui.hostsutil.HostsUtil` class. """ __title = "HOSTS SETUP UTILITY" - __copyleft = "v%s Copyleft 2011-2014, huhamhire-hosts Team" % __version__ + version = "".join(['v', __version__,' ', __release__]) + __copyleft = "%s Copyleft 2011-2014, huhamhire-hosts Team" % version _stdscr = None _item_sup = 0 diff --git a/util/makehosts.py b/util/makehosts.py index cb8be71..105bb88 100644 --- a/util/makehosts.py +++ b/util/makehosts.py @@ -12,6 +12,7 @@ __author__ = "huhamhire " +import os import time from retrievedata import RetrieveData @@ -28,6 +29,7 @@ class MakeHosts(object): .. seealso:: :attr:`make_mode` in :class:`~gui.qdialog_d.QDialogDaemon` class. + :ivar str custom: File name of User Customized Hosts file. :ivar str hostname: File Name of hosts file. :ivar file hosts_file: The hosts file to write hosts to. :ivar int mod_num: Total number of modules written to hosts file. @@ -41,6 +43,7 @@ class MakeHosts(object): :class:`tui.curses_d.CursesDaemon` class. """ make_mode = "" + custom = "" hostname = "" hosts_file = None make_cfg = {} @@ -62,6 +65,7 @@ class to retrieve configuration with. self.count = 0 self.make_cfg = parent.make_cfg self.hostname = parent.hostname + self.custom = parent.custom make_path = parent.make_path if parent.make_mode == "system": self.eol = parent.sys_eol @@ -98,6 +102,9 @@ def get_hosts(self, make_cfg): class. """ for part_id in sorted(make_cfg.keys()): + if part_id == 0x04: + self.write_customized() + continue mod_cfg = make_cfg[part_id] if not RetrieveData.chk_mutex(part_id, mod_cfg): return @@ -152,6 +159,21 @@ def write_common_mod(self, hosts, mod_name): self.count += 1 self.hosts_file.write("# Section End: %s%s" % (mod_name, self.eol)) + def write_customized(self): + """ + Write user customized hosts list into the hosts file if the customized + hosts file exists. + """ + if os.path.isfile(self.custom): + custom_file = open(unicode(self.custom), "r") + lines = custom_file.readlines() + self.hosts_file.write( + "%s# Section Start: Customized%s" % (self.eol, self.eol)) + for line in lines: + line = line.strip("\n") + self.hosts_file.write(line + self.eol) + self.hosts_file.write("# Section End: Customized%s" % self.eol) + def write_localhost_mod(self, hosts): """ Write localhost entries :attr:`hosts` into the hosts file. diff --git a/util/retrievedata.py b/util/retrievedata.py index 300192a..633bf5a 100644 --- a/util/retrievedata.py +++ b/util/retrievedata.py @@ -157,6 +157,8 @@ def get_host(cls, part_id, mod_id): * mod_name(`str`): Name of a specified module. :rtype: list, str """ + if part_id == 0x04: + return None, "customized" cls._cur.execute(""" SELECT part_name FROM parts WHERE part_id=:part_id; @@ -196,7 +198,7 @@ def get_choice(cls, flag_v6=False): * modules(`list`): Information of modules for users to select. * defaults(`dict`): Default selection config for selected parts. - * slices(`list`): Number of modules in each part. + * slices(`list`): Numbers of modules in each part. :rtype: list, dict, list """ ch_parts = (0x08, 0x20 if flag_v6 else 0x10, 0x40) @@ -268,6 +270,8 @@ def chk_mutex(cls, part_id, mod_cfg): :rtype: bool """ + if part_id == 0x04: + return True cls._cur.execute(""" SELECT mod_id, mutex FROM modules WHERE part_id=:part_id; From 2c230a6e38348e87d5e3baae0e7e240722eef79a Mon Sep 17 00:00:00 2001 From: huhamhire Date: Tue, 21 Jan 2014 21:25:56 +0800 Subject: [PATCH 05/11] add customized hosts list support for tui --- gui/qdialog_ui.py | 2 +- tui/curses_d.py | 5 ++++- tui/curses_ui.py | 4 ++++ tui/hostsutil.py | 8 ++++++++ util/makehosts.py | 5 ++--- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/gui/qdialog_ui.py b/gui/qdialog_ui.py index 6be8f33..dfcc01d 100644 --- a/gui/qdialog_ui.py +++ b/gui/qdialog_ui.py @@ -70,7 +70,7 @@ class QDialogUI(QtGui.QDialog, object): plat_flag = True ui = None - custom = "customize.hosts" + custom = "custom.hosts" def __init__(self): """ diff --git a/tui/curses_d.py b/tui/curses_d.py index 29939ff..4031cd3 100644 --- a/tui/curses_d.py +++ b/tui/curses_d.py @@ -483,7 +483,10 @@ def set_config_bytes(self): "Windows": 0x0001, "Linux": 0x0002, "Unix": 0x0002, "OS X": 0x0004}[self.platform] selection[0x02] = localhost_word - ch_parts = (0x08, 0x20 if ip_flag else 0x10, 0x40) + ch_parts = [0x08, 0x20 if ip_flag else 0x10, 0x40] + # Set customized module if exists + if os.path.isfile(self.custom): + ch_parts.insert(0, 0x04) slices = self.slices[ip_flag] for i, part in enumerate(ch_parts): part_cfg = self._funcs[ip_flag][slices[i]:slices[i + 1]] diff --git a/tui/curses_ui.py b/tui/curses_ui.py index 0b7c746..9585c3b 100644 --- a/tui/curses_ui.py +++ b/tui/curses_ui.py @@ -112,6 +112,9 @@ class CursesUI(object): .. seealso:: :attr:`filename` and :attr:`infofile` in :class:`~gui.hostsutil.HostsUtil` class. + + :ivar str custom: File name of User Customized Hosts File. Customized + hosts would be able to select if this file exists. """ __title = "HOSTS SETUP UTILITY" version = "".join(['v', __version__,' ', __release__]) @@ -148,6 +151,7 @@ class CursesUI(object): filename = "hostslist.data" infofile = "hostsinfo.json" + custom = "custom.hosts" def __init__(self): """ diff --git a/tui/hostsutil.py b/tui/hostsutil.py index 585c125..063323b 100644 --- a/tui/hostsutil.py +++ b/tui/hostsutil.py @@ -12,6 +12,8 @@ __author__ = "huhamhire " +import os + from zipfile import BadZipfile from curses_d import CursesDaemon @@ -145,6 +147,12 @@ def set_func_list(self): """ for ip in range(2): choice, defaults, slices = RetrieveData.get_choice(ip) + if os.path.isfile(self.custom): + choice.insert(0, [4, 1, 0, "customize"]) + defaults[0x04] = [1] + for i in range(len(slices)): + slices[i] += 1 + slices.insert(0, 0) self.choice[ip] = choice self.slices[ip] = slices funcs = [] diff --git a/util/makehosts.py b/util/makehosts.py index 105bb88..2fc1344 100644 --- a/util/makehosts.py +++ b/util/makehosts.py @@ -102,9 +102,6 @@ def get_hosts(self, make_cfg): class. """ for part_id in sorted(make_cfg.keys()): - if part_id == 0x04: - self.write_customized() - continue mod_cfg = make_cfg[part_id] if not RetrieveData.chk_mutex(part_id, mod_cfg): return @@ -114,6 +111,8 @@ def get_hosts(self, make_cfg): hosts, mod_name = RetrieveData.get_host(part_id, mod_id) if part_id == 0x02: self.write_localhost_mod(hosts) + elif part_id == 0x04: + self.write_customized() else: self.write_common_mod(hosts, mod_name) From 06b3eca04d5dd4442555cdab4bff7887ea110a61 Mon Sep 17 00:00:00 2001 From: huhamhire Date: Wed, 22 Jan 2014 13:07:15 +0800 Subject: [PATCH 06/11] update method to insert customized hosts list --- gui/language.py | 2 +- gui/qdialog_ui.py | 21 ++++++++++++--------- gui/style_rc.py | 2 +- gui/util_rc.py | 2 +- gui/util_ui.py | 2 +- tui/curses_ui.py | 5 +++-- util/makehosts.py | 13 ++++++++++++- util/retrievedata.py | 2 +- 8 files changed, 32 insertions(+), 17 deletions(-) diff --git a/gui/language.py b/gui/language.py index b76927e..4be7b42 100644 --- a/gui/language.py +++ b/gui/language.py @@ -98,7 +98,7 @@ def get_locale_by_language(cls, l_lang): .. note:: This is a `classmethod`. :param l_lang: Localized name of a specified language. - :type l_lang: str + :type l_lang: unicode :return: Locale tag of a specified language. :rtype: str """ diff --git a/gui/qdialog_ui.py b/gui/qdialog_ui.py index dfcc01d..d445c63 100644 --- a/gui/qdialog_ui.py +++ b/gui/qdialog_ui.py @@ -59,7 +59,8 @@ class QDialogUI(QtGui.QDialog, object): :ivar object ui: Form implementation declares layout of the main dialog which is generated from a UI file designed by `Qt Designer`. :ivar str custom: File name of User Customized Hosts File. Customized - hosts would be able to select if this file exists. + hosts would be able to select if this file exists. The default file + name is ``custom.hosts``. """ _cur_ver = "" _trans = None @@ -179,7 +180,7 @@ def set_label_text(self, label, text): :param label: Label on the main dialog. :type: :class:`PyQt4.QtGui.QLabel` :param text: Message to be set on the label. - :type text: str + :type text: unicode """ label.setText(_translate("Util", text, None)) @@ -203,7 +204,7 @@ def set_conn_status(self, status): self.set_label_text(self.ui.labelConnStat, stat) def set_version(self): - version = "".join(['v', __version__,' ', __release__]) + version = "".join(['v', __version__, ' ', __release__]) self.set_label_text(self.ui.VersionLabel, version) def set_info(self): @@ -216,7 +217,7 @@ def set_info(self): self.set_label_text(self.ui.labelVersionData, ver) build = info["Buildtime"] build = CommonUtil.timestamp_to_date(build) - self.set_label_text(self.ui.labelReleaseData, build) + self.set_label_text(self.ui.labelReleaseData, unicode(build)) def set_down_progress(self, progress, message): """ @@ -409,7 +410,7 @@ def warning_incorrect_datafile(self): "Incorrect Data file!\n" "Please use the \"Download\" key to \n" "fetch a new data file.", None)) - self.set_message(msg_title, msg) + self.set_message(unicode(msg_title), msg) self.ui.ButtonApply.setEnabled(False) self.ui.ButtonANSI.setEnabled(False) self.ui.ButtonUTF.setEnabled(False) @@ -423,7 +424,7 @@ def warning_no_datafile(self): "Data file not found!\n" "Please use the \"Download\" key to \n" "fetch a new data file.", None)) - self.set_message(msg_title, msg) + self.set_message(unicode(msg_title), msg) self.ui.ButtonApply.setEnabled(False) self.ui.ButtonANSI.setEnabled(False) self.ui.ButtonUTF.setEnabled(False) @@ -450,9 +451,11 @@ def question_apply(self): "This operation could not be reverted if \n" "you have not made a backup of your \n" "current hosts file.", None)) - choice = QtGui.QMessageBox.question(self, msg_title, msg, - QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, - QtGui.QMessageBox.No) + choice = QtGui.QMessageBox.question( + self, msg_title, msg, + QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, + QtGui.QMessageBox.No + ) if choice == QtGui.QMessageBox.Yes: return True else: diff --git a/gui/style_rc.py b/gui/style_rc.py index 82c569b..6ee4df0 100644 --- a/gui/style_rc.py +++ b/gui/style_rc.py @@ -2,7 +2,7 @@ # Resource object code # -# Created: 周二 1月 21 15:46:41 2014 +# Created: 周三 1月 22 13:03:07 2014 # by: The Resource Compiler for PyQt (Qt v4.8.5) # # WARNING! All changes made in this file will be lost! diff --git a/gui/util_rc.py b/gui/util_rc.py index ccfd1cc..b727075 100644 --- a/gui/util_rc.py +++ b/gui/util_rc.py @@ -2,7 +2,7 @@ # Resource object code # -# Created: 周二 1月 21 15:46:41 2014 +# Created: 周三 1月 22 13:03:07 2014 # by: The Resource Compiler for PyQt (Qt v4.8.5) # # WARNING! All changes made in this file will be lost! diff --git a/gui/util_ui.py b/gui/util_ui.py index 80517be..bafe7e2 100644 --- a/gui/util_ui.py +++ b/gui/util_ui.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file '../pyqt\util_ui.ui' # -# Created: Tue Jan 21 15:46:43 2014 +# Created: Wed Jan 22 13:03:09 2014 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! diff --git a/tui/curses_ui.py b/tui/curses_ui.py index 9585c3b..ad013ee 100644 --- a/tui/curses_ui.py +++ b/tui/curses_ui.py @@ -114,10 +114,11 @@ class CursesUI(object): :class:`~gui.hostsutil.HostsUtil` class. :ivar str custom: File name of User Customized Hosts File. Customized - hosts would be able to select if this file exists. + hosts would be able to select if this file exists. The default file + name is ``custom.hosts``. """ __title = "HOSTS SETUP UTILITY" - version = "".join(['v', __version__,' ', __release__]) + version = "".join(['v', __version__, ' ', __release__]) __copyleft = "%s Copyleft 2011-2014, huhamhire-hosts Team" % version _stdscr = None diff --git a/util/makehosts.py b/util/makehosts.py index 2fc1344..3f05ac2 100644 --- a/util/makehosts.py +++ b/util/makehosts.py @@ -170,7 +170,18 @@ def write_customized(self): "%s# Section Start: Customized%s" % (self.eol, self.eol)) for line in lines: line = line.strip("\n") - self.hosts_file.write(line + self.eol) + entry = line.split(" ", 1) + if line.startswith("#"): + self.hosts_file.write(line + self.eol) + elif len(entry) > 1: + ip = entry[0] + if len(ip) < 16: + ip = entry[0].ljust(16) + self.hosts_file.write( + "%s %s%s" % (ip, entry[1], self.eol) + ) + else: + pass self.hosts_file.write("# Section End: Customized%s" % self.eol) def write_localhost_mod(self, hosts): diff --git a/util/retrievedata.py b/util/retrievedata.py index 633bf5a..bd15bd8 100644 --- a/util/retrievedata.py +++ b/util/retrievedata.py @@ -158,7 +158,7 @@ def get_host(cls, part_id, mod_id): :rtype: list, str """ if part_id == 0x04: - return None, "customized" + return None, "customize" cls._cur.execute(""" SELECT part_name FROM parts WHERE part_id=:part_id; From 7a60a1816d82ad423926a2083565209fb6a7a7fd Mon Sep 17 00:00:00 2001 From: huhamhire Date: Wed, 22 Jan 2014 13:08:01 +0800 Subject: [PATCH 07/11] update language files --- gui/lang/de_DE.ts | 296 +++++++++++++++++++++++++--------------------- gui/lang/en_US.qm | Bin 4715 -> 5109 bytes gui/lang/en_US.ts | 187 ++++++++++++++++------------- gui/lang/zh_CN.qm | Bin 6306 -> 6660 bytes gui/lang/zh_CN.ts | 187 ++++++++++++++++------------- gui/lang/zh_TW.qm | Bin 6272 -> 6624 bytes gui/lang/zh_TW.ts | 187 ++++++++++++++++------------- 7 files changed, 487 insertions(+), 370 deletions(-) diff --git a/gui/lang/de_DE.ts b/gui/lang/de_DE.ts index ec90df1..723e529 100644 --- a/gui/lang/de_DE.ts +++ b/gui/lang/de_DE.ts @@ -1,161 +1,174 @@ - + Util - + + customize + + + + + google + + + + + google-apis + + + + google(cn) - + google(hk) - + google(us) - + google-apis(cn) - + google-apis(us) - + activation-helper - + facebook - + twitter - + youtube - + wikipedia - + institutions - + steam - - others + + github - - adblock-hostsx + + dropbox - - adblock-mvps + + wordpress - - adblock-mwsl + + others - - adblock-yoyo + + adblock-hostsx - - Backup hosts + + adblock-mvps - - Backup File(*.bak) + + adblock-mwsl - - Restore hosts + + adblock-yoyo - + [Error] - - Checking... + + Connecting... - - Operation completed + + Downloading: %s / %s - - Incorrect Data file! -Please use the "Download" key to -fetch a new data file. + + Checking... - + [OK] - + [Failed] - + Functions - + Applying module: %s(%s/%s) - + Progress - + Warning - + You do not have permissions to change the hosts file. Please run this program as Administrator/root @@ -163,25 +176,32 @@ so it can modify your hosts file. - + Error retrieving data from the server. Please try another server. - + + Incorrect Data file! +Please use the "Download" key to +fetch a new data file. + + + + Data file not found! Please use the "Download" key to fetch a new data file. - + Notice - + Are you sure you want to apply changes to the hosts file on your system? @@ -191,215 +211,225 @@ current hosts file. - + Data file is up-to-date. - + Complete - - Hosts Setup Utility + + Operation completed - - Config + + Export hosts - - Server + + hosts File - - IP Version + + Building hosts file... - - Status + + Copying new hosts file to +%s - - Connection + + Remove temporary file - - N/A + + Notice: %i hosts entries has + been applied in %ssecs. - - OS + + Operation Completed Successfully! - - Hosts Info + + Error - - Version + + Download Complete - - Release + + Backup hosts - - Latest + + Backup File(*.bak) - - Backup the hosts file of current system. + + Restore hosts - - Download data file + + Hosts Setup Utility - - Download the latest data file. + + Config - - Restore backup + + Server - - Restore a previous backup of hosts file. + + IP Version - - Apply hosts + + Status - - Apply changes to the hosts file. + + Connection - - Exit + + N/A - - Close this tool. + + OS - - Check update / Refresh + + Hosts Info - - Check the latest version of hosts data file. + + Version - - Save with ANSI + + Release - - Export to hosts file encoding by ANSI. + + Latest - - Save with UTF-8 + + Backup the hosts file of current system. - - Export to hosts file encoding by UTF-8. + + Download data file - - Copyleft (C) 2011-2014 <a href="https://hosts.huhamhire.com/"><span style="text-decoration: none;color: #b1b1b1;">huhamhire-hosts</span></a> + + Download the latest data file. - - Powered by PyQT + + Restore backup - - Connecting... + + Restore a previous backup of hosts file. - - Downloading: %s / %s + + Apply hosts - - Export hosts + + Apply changes to the hosts file. - - hosts File + + Exit - - Building hosts file... + + Close this tool. - - Copying new hosts file to -%s + + Check update / Refresh - - Remove temporary file + + Check the latest version of hosts data file. - - Notice: %i hosts entries has - been applied in %ssecs. + + Save with ANSI - - Operation Completed Successfully! + + Export to hosts file encoding by ANSI. - - Error + + Save with UTF-8 - - Download Complete + + Export to hosts file encoding by UTF-8. + + + + + Copyleft (C) 2011-2014 <a href="https://hosts.huhamhire.com/"><span style="text-decoration: none;color: #b1b1b1;">huhamhire-hosts</span></a> + + + + + Powered by PyQT diff --git a/gui/lang/en_US.qm b/gui/lang/en_US.qm index b5adf8277ab9bd1bc21954348e2ddcecdadc6d40..7cf3284afd0f16f7ad45b13a923ae364dce4522f 100644 GIT binary patch delta 488 zcmaE@@>P9;2;+>2qIyDtd<-T1$_xyw(F|3qYZ({>0w#v4aS1GA(tYxnfq`%O#9BWt zzWXfCFYaVu;5VIk)zSUI`b`WByk>0A;#7fjBHODI#S9FL_3Y7Vr3?%#=h?H~Oa>Yw z%07F_Y@j?V`jBZT)>n49?R2Tfprzj8!v|$OK zq7*04scw^XnSz-FZ8kSC&E!c^U~pzAWhiDSVaR95WyoZxVn}63VNhW30P;bi#Xxg` zHUTkba%pi%er{$}Dm#$J5?Yd(!^jL|@iDkC6aiHiFeCxV3b=aql%o8Cr2LA>y!`e$ zJPhtY!%Kk1mNF#4m9V8}mSmJBp_->M`8~gi0Fs*g{PdjE$%X=QlmGEcP0keHo7}>` zn^9%5gMf-CTp4#dSeb5OL1yu0Ljg`EH6ey@pnHmdz6k)5sX*T#`K3I+D5an%wYYe) Hj*vY7N|bVe delta 216 zcmeyW{#s>%2xG=XQ9U94Ees|7$_xyw(F|3qYZ(~$wI+tDG4VG{Z1v;f-O2L&;!Xwz zKK_Y!9ra(GC}v<_tY?o_D`j9{InSQ;W-?IfJ^Sn_vl$q8rn0XI`NzP(Fo7d1+Kz#N zNn~;=qlW^wx@Ce#S(Qm$P@GRu zAQEWOF+N2pP6h_vjLES~!A$&*Hg95@$uoI3zv1LR0$P*z3-V2#B(NLE7ML6>C_4Fq Q0PE)cf)^Pl9}zYL03tF!Bme*a diff --git a/gui/lang/en_US.ts b/gui/lang/en_US.ts index 93a1b25..bb10557 100644 --- a/gui/lang/en_US.ts +++ b/gui/lang/en_US.ts @@ -1,338 +1,337 @@ - - + Util - + google(cn) Google Web Service (CN) - + google(hk) Google Web Service (HK) - + google(us) Google Web Service (US) - + google-apis(cn) Google API Service (CN) - + google-apis(us) Google API Service (US) - + activation-helper - + facebook Facebook - + twitter twitter - + youtube YouTube - + wikipedia Wikipedia - + institutions Academy and Research institutions - + steam Steam - + others Other services - + adblock-hostsx - + adblock-mvps - + adblock-mwsl - + adblock-yoyo - + Backup hosts - + Backup File(*.bak) - + Restore hosts - + [Error] - + Checking... - + Operation completed - + [OK] - + [Failed] - + Functions - + Applying module: %s(%s/%s) - + Progress - + Warning - + Error retrieving data from the server. Please try another server. - + Notice - + Data file is up-to-date. - + Complete - + Hosts Setup Utility - + Config - + Server - + IP Version - + Status - + Connection - + N/A - + OS - + Hosts Info - + Version - + Release - + Latest - + Backup the hosts file of current system. - + Download data file - + Download the latest data file. - + Restore backup - + Restore a previous backup of hosts file. - + Apply hosts - + Apply changes to the hosts file. - + Exit - + Close this tool. - + Check update / Refresh - + Check the latest version of hosts data file. - + Save with ANSI - + Export to hosts file encoding by ANSI. - + Save with UTF-8 - + Export to hosts file encoding by UTF-8. - + Copyleft (C) 2011-2014 <a href="https://hosts.huhamhire.com/"><span style="text-decoration: none;color: #b1b1b1;">huhamhire-hosts</span></a> - + Powered by PyQT - + Connecting... - + Downloading: %s / %s - + Incorrect Data file! Please use the "Download" key to fetch a new data file. - + You do not have permissions to change the hosts file. Please run this program as Administrator/root @@ -340,14 +339,14 @@ so it can modify your hosts file. - + Data file not found! Please use the "Download" key to fetch a new data file. - + Are you sure you want to apply changes to the hosts file on your system? @@ -357,51 +356,81 @@ current hosts file. - + Export hosts - + hosts File - + Building hosts file... - + Copying new hosts file to %s - + Remove temporary file - + Notice: %i hosts entries has been applied in %ssecs. - + Operation Completed Successfully! - + Error - + Download Complete + + + google + Google Web Service + + + + google-apis + Google API Service + + + + customize + Customized Hosts + + + + github + GitHub + + + + dropbox + Dropbox + + + + wordpress + WordPress + diff --git a/gui/lang/zh_CN.qm b/gui/lang/zh_CN.qm index 69fcbedacc83f570fa04b6d3162ff0ef4f8e788a..76f19ae00052a0948790d104718830738f822eb9 100644 GIT binary patch delta 482 zcmZ2v*kUq4gmK11Q9U7X6^4?2Wd;V0)eKduYZ(~C(k6zgafuyc(tYxnfkBjYVyz#S zs58s+i#vh5-icQo-5;#q#K0hYi|tvQDg%QEE8D9R#S9Eg(d^M`r3?)0KiRY1Oa>Zb z%|3g|Y@oW8>}x{)F)%PZ;s}ejV_;zR;Mo4@Fi`%(WLHKH1Fmh^M}dmGxz%Nxfr`Sp z1BCJ!7`Vl`gREMC_FdujYQR3uvj>jLB;m-I&CCld zQHm2tADXPo6wD+Zw7H4NUpRoTR3pi}@m2IJKhGfXjtrnN3=C{Q%$ZzTT#}!gS(VBT znzhd%XQTq@c26u)`h7tx3hEj$k zxDvMX%#w`KBvkVxfJ*a$Fr6WXA(cUaAsk31rSk?YMADX@pPrLCxk^lPvaHxTMybhX z#H2*w(%k7_Y2Czv%;L>^#dZU|3^XJk=*Sd?03eylP|Q#aSIt?TUzAc%lv-RoIZMI< E09>z;;;!Xwz zk^YHy9ra(GC}v<_ie`^iD`j9{|H+>9W-?H@E&J>#vl$qKz1i1<{9|BXc*GGFZO6dC z>@hi&(L;e-UA7r07|tCal+VDxEzTWe)e1E4CijC~n}C{UO}@+M#w5x!S(QmmNO(V= zqCh0js2V;+DNdj&rpd8P!AxQbn>R7}3r~(0Gn`x@E - - + Util - + google(cn) Google Web服务(北京) - + google(hk) Google Web服务(香港) - + google(us) Google Web服务(美国) - + google-apis(cn) Google 应用程序服务(北京) - + google-apis(us) Google 应用程序服务(美国) - + activation-helper 屏蔽部分破解软件激活服务器 - + facebook Facebook - + twitter twitter - + youtube YouTube - + wikipedia 维基百科 - + institutions 教育科研机构 - + steam Steam 游戏平台 - + others 其他墙外站点 - + adblock-hostsx 广告屏蔽-hostsx 列表 - + adblock-mvps 广告屏蔽-mvps 列表 - + adblock-mwsl 广告屏蔽-mwsl 列表 - + adblock-yoyo 广告屏蔽-yoyo 列表 - + Backup hosts 备份 hosts 文件 - + Backup File(*.bak) 备份文件(*.bak) - + Restore hosts 还原备份的 hosts 文件 - + [Error] [错误] - + Checking... 正在连接... - + Export hosts 导出 hosts 文件 - + hosts File hosts 文件 @@ -131,12 +130,12 @@ %s - + Remove temporary file 清理临时文件 - + Operation completed 操作完成 @@ -148,12 +147,12 @@ %s秒内被插入到 hosts 文件中。 - + Operation Completed Successfully! 操作成功完成! - + Error 错误 @@ -167,37 +166,37 @@ fetch a new data file. 新的数据文件。 - + Download Complete 下载完成 - + [OK] [正常] - + [Failed] [失败] - + Functions 功能列表 - + Applying module: %s(%s/%s) 应用选定的模块: %s(%s/%s) - + Progress 操作进度 - + Warning 警告 @@ -213,7 +212,7 @@ so it can modify your hosts file. 工具。 - + Error retrieving data from the server. Please try another server. 在从服务器获取数据是发生错误。 @@ -229,7 +228,7 @@ fetch a new data file. 新的数据文件。 - + Notice 注意 @@ -248,184 +247,184 @@ current hosts file. 不可逆转。 - + Data file is up-to-date. 数据文件已经是最新版本。 - + Complete 完成 - + Building hosts file... 正在生成 hosts 文件... - + Hosts Setup Utility hosts 文件配置工具 - + Config 设置 - + Server 服务器 - + IP Version IP 协议版本 - + Status 状态 - + Connection 连接 - + N/A 无状态 - + OS 操作系统 - + Hosts Info 数据文件信息 - + Version 当前版本 - + Release 发布日期 - + Latest 最新版本 - + Backup the hosts file of current system. 备份当前系统的 hosts 文件。 - + Download data file 下载数据文件 - + Download the latest data file. 下载最新数据文件。 - + Restore backup 还原备份 - + Restore a previous backup of hosts file. 还原先前备份的 hosts 文件。 - + Apply hosts 更改 hosts - + Apply changes to the hosts file. 对 hosts 文件进行修改。 - + Exit 退出 - + Close this tool. 关闭本工具。 - + Check update / Refresh 检查更新/刷新 - + Check the latest version of hosts data file. 在线检查数据文件的最新版本。 - + Save with ANSI 保存为 ANSI 格式 - + Export to hosts file encoding by ANSI. 以 ANSI 的编码方式导出 hosts 文件。 - + Save with UTF-8 保存为 UTF-8 格式 - + Export to hosts file encoding by UTF-8. 以 UTF-8 的编码方式导出 hosts 文件。 - + Copyleft (C) 2011-2014 <a href="https://hosts.huhamhire.com/"><span style="text-decoration: none;color: #b1b1b1;">huhamhire-hosts</span></a> 公共版权 (C) 2011-2014 <a href="https://hosts.huhamhire.com/"><span style="text-decoration: none;color: #b1b1b1;">huhamhire-hosts</span></a> - + Powered by PyQT - + Connecting... 正在连接服务器... - + Downloading: %s / %s 正在下载: %s / %s - + Notice: %i hosts entries has been applied in %ssecs. 注意:共有 %i 条 hosts 条目在 %s秒内被插入到 hosts 文件中。 - + Incorrect Data file! Please use the "Download" key to fetch a new data file. @@ -434,7 +433,7 @@ fetch a new data file. 新的数据文件。 - + You do not have permissions to change the hosts file. Please run this program as Administrator/root @@ -445,7 +444,7 @@ so it can modify your hosts file. 工具。 - + Data file not found! Please use the "Download" key to fetch a new data file. @@ -454,7 +453,7 @@ fetch a new data file. 新的数据文件。 - + Are you sure you want to apply changes to the hosts file on your system? @@ -468,11 +467,41 @@ current hosts file. 不可逆转。 - + Copying new hosts file to %s 正在将新的 hosts 配置到目标路径 %s + + + google + Google Web服务 + + + + google-apis + Google 应用程序服务 + + + + customize + 用户自定义列表 + + + + github + GitHub + + + + dropbox + Dropbox + + + + wordpress + WordPress + diff --git a/gui/lang/zh_TW.qm b/gui/lang/zh_TW.qm index 5ef8d6b51b32acc61381433858ee0fae62e5c099..0d30797280007c1bea1c9ef2283103face4576f2 100644 GIT binary patch delta 471 zcmZoLd|*65gmK11Q9U7X28NP;Wd;V0tqfJGYZ(~CoF;~gfJp{U!zm;X`cC;#7h3TeepxiWwM~qS>R>N*Nf~|FdVknG7^W zntk?^*+BV;>}x{)F)%Q^;0TMhV_;x*;@JM_Fi`%?WLHKH1Fmh^M}dlrxz%Nxfr=uz z1BCJ!7`R!vgREMC_U+`JmdOE>Pv(BG3uviW$>g<+ZcL)DCVypA6B0@1Qxu21Es zQHm2tubQmO6wD;9x4DVQTsVNwzrIwXfwl2f7gHW<=sKV=3=C{Q%$ZzTT#}!gS(VBT znzhd%gQF|R826u)`h7tx3hEj$k zxDvMX%#w`KBvkVxCKrlH2q3A+&ri=uoh&b=Ihj>#9iznLKVlN1aB1#zu(WPsL1r;f xjof5zaqi9M#5#cfWC#bkr-&g1=&~Y)REA=PVz@5O^8BKdf}+&o;>jKo768NHar^)P delta 209 zcmaE0++a9CgfU~HsGgAM1%{G-Wd;V0tqfJGYZ(|s-6n>rF^Mjl*y_h6qRaC9;!Xwz zk@+!*(L;e-UA7r07|9(Vl+VDx&B`5Q)e1CkFZY98n}C`tCf{XrV-k5cS(QmmNO(D) zqCh0js1!a$DNZ2$YH}=7Fq7!N&6}9ag(tg<8BV@0E-<-3oO|+Dv2~LZ#056L7oW^H Id7Gpb08xlL@c;k- diff --git a/gui/lang/zh_TW.ts b/gui/lang/zh_TW.ts index ef3f111..30a9841 100644 --- a/gui/lang/zh_TW.ts +++ b/gui/lang/zh_TW.ts @@ -1,125 +1,124 @@ - - + Util - + google(cn) Google Web服務(大陸) - + google(hk) Google Web服務(香港) - + google(us) Google Web服務(美國) - + google-apis(cn) Google API服務(大陸) - + google-apis(us) Google API服務(美國) - + activation-helper 遮罩部分破解軟體啟動伺服器 - + facebook Facebook - + twitter twitter - + youtube YouTube - + wikipedia 維基百科 - + institutions 教育科研機構 - + steam Steam 遊戲平台 - + others 其他網站 - + adblock-hostsx 廣告攔截-hostsx 清單 - + adblock-mvps 廣告攔截-mvps 清單 - + adblock-mwsl 廣告攔截-mwsl 清單 - + adblock-yoyo 廣告攔截-yoyo 清單 - + Backup hosts 備份 hosts 檔 - + Backup File(*.bak) 備份檔(*.bak) - + Restore hosts 還原 hosts - + [Error] [錯誤] - + Checking... 正在連接伺服器... - + Export hosts 匯出 hosts 檔 - + hosts File hosts 檔 @@ -131,12 +130,12 @@ %s - + Remove temporary file 刪除暫存檔案 - + Operation completed 作業完成 @@ -148,12 +147,12 @@ %s秒内被插入到 hosts 文件中。 - + Operation Completed Successfully! 作業已成功完成 ! - + Error 錯誤 @@ -167,37 +166,37 @@ fetch a new data file. 一個新的資料檔案。 - + Download Complete 下載已完成 - + [OK] [好] - + [Failed] [失敗] - + Functions 功能清單 - + Applying module: %s(%s/%s) 應用選定的模組: %s(%s/%s) - + Progress 作業進度 - + Warning 警告 @@ -212,7 +211,7 @@ so it can modify your hosts file. 程式。 - + Error retrieving data from the server. Please try another server. 從伺服器中檢索資料時出錯。 @@ -228,7 +227,7 @@ fetch a new data file. 一個新的資料檔案。 - + Notice 消息 @@ -247,184 +246,184 @@ current hosts file. 不可逆轉。 - + Data file is up-to-date. 當前的資料檔案是最新的。 - + Complete 完成 - + Building hosts file... 正在創建 hosts 檔... - + Hosts Setup Utility hosts 設置實用程式 - + Config 配置 - + Server 伺服器 - + IP Version IP 協定版本 - + Status 狀態 - + Connection 連接狀態 - + N/A 不適用 - + OS 作業系統 - + Hosts Info 資料檔案狀態 - + Version 當前版本 - + Release 發佈日期 - + Latest 最新版本 - + Backup the hosts file of current system. 備份當前系統的 hosts 檔。 - + Download data file 下載資料檔案 - + Download the latest data file. 下載最新的資料檔案。 - + Restore backup 還原備份 - + Restore a previous backup of hosts file. 還原以前的備份的 hosts 檔。 - + Apply hosts 更改 hosts 檔 - + Apply changes to the hosts file. 將更改應用到主 hosts 檔。 - + Exit 退出 - + Close this tool. 關閉此程式。 - + Check update / Refresh 檢查更新 / 刷新 - + Check the latest version of hosts data file. 檢查 hosts 檔案的最新版本。 - + Save with ANSI 保存為 ANSI 格式 - + Export to hosts file encoding by ANSI. 匯出由 ANSI 編碼的 hosts 檔。 - + Save with UTF-8 保存為 UTF-8 格式 - + Export to hosts file encoding by UTF-8. 匯出由 UTF-8 編碼的 hosts 檔。 - + Copyleft (C) 2011-2014 <a href="https://hosts.huhamhire.com/"><span style="text-decoration: none;color: #b1b1b1;">huhamhire-hosts</span></a> 公共版權 (C) 2011-2014 <a href="https://hosts.huhamhire.com/"><span style="text-decoration: none;color: #b1b1b1;">huhamhire-hosts</span></a> - + Powered by PyQT - + Connecting... 正在連接... - + Downloading: %s / %s 正在下載: %s / %s - + Notice: %i hosts entries has been applied in %ssecs. 消息:共有 %i 条 hosts 条目在 %s秒内被插入到 hosts 文件中。 - + Incorrect Data file! Please use the "Download" key to fetch a new data file. @@ -433,7 +432,7 @@ fetch a new data file. 一個新的資料檔案。 - + You do not have permissions to change the hosts file. Please run this program as Administrator/root @@ -443,7 +442,7 @@ so it can modify your hosts file. 程式。 - + Data file not found! Please use the "Download" key to fetch a new data file. @@ -452,7 +451,7 @@ fetch a new data file. 一個新的資料檔案。 - + Are you sure you want to apply changes to the hosts file on your system? @@ -466,11 +465,41 @@ current hosts file. 不可逆轉。 - + Copying new hosts file to %s 將新的 hosts 檔案複製到 %s + + + google + Google Web服務 + + + + google-apis + Google API服務 + + + + customize + 使用者自訂清單 + + + + github + GitHub + + + + dropbox + Dropbox + + + + wordpress + Wordpress + From 464e8e1cda64457d8070126de90225afbc398d8e Mon Sep 17 00:00:00 2001 From: huhamhire Date: Wed, 22 Jan 2014 13:36:57 +0800 Subject: [PATCH 08/11] update doc and build script --- README.rst | 13 +++++++++++++ _build.py | 6 +++--- doc/dev/intro.rst | 18 ++++++++++++++++++ gui/qdialog_ui.py | 2 ++ tui/curses_ui.py | 6 ++++-- util/makehosts.py | 3 +++ 6 files changed, 43 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 9232147..8cdb8de 100644 --- a/README.rst +++ b/README.rst @@ -152,6 +152,19 @@ If current session is running with `cmd` on a non-english Windows system, command ``chcp 437`` is required by curses to set the default code page. +User Customized Hosts +===================== + +Users are allowed to add customized hosts list as an independent module to +make a hosts file. All you need to do is create a simple text file named +``custom.hosts`` in the working directory, and put your own hosts entries +into this file. Then you would find a `Customized Hosts` option in the +function list. + + * Non-ASCII characters are not recommended to be put into the + customized hosts file. + + Author/Maintainer ================= huhamhire ``_ diff --git a/_build.py b/_build.py index 3bdb592..300aaca 100644 --- a/_build.py +++ b/_build.py @@ -72,7 +72,7 @@ ]), (".", [ "LICENSE", - "README.md", + "README.rst", "network.conf", ]), ] @@ -90,7 +90,7 @@ "gui/theme/*.qss", "*/*.py", "LICENSE", - "README.md", + "README.rst", "network.conf", ] excludes = [ @@ -194,7 +194,7 @@ author_email=AUTHOR_EMAIL, license=LICENSE, url=URL, - zipfile="lib/shared.zip", + zipfile="lib/shared.lib", data_files=DATA_FILES, classifiers=CLASSIFIERS, ) diff --git a/doc/dev/intro.rst b/doc/dev/intro.rst index 92c95b2..d31f0e8 100644 --- a/doc/dev/intro.rst +++ b/doc/dev/intro.rst @@ -141,6 +141,24 @@ Text-based User Interface (TUI) Mode Windows system, command ``chcp 437`` is required by curses to set the default code page. + +.. _intro-customize: + +User Customized Hosts +--------------------- + +Users are allowed to add customized hosts list as an independent module to +make a hosts file. All you need to do is create a simple text file named +``custom.hosts`` in the working directory, and put your own hosts entries +into this file. Then you would find a `Customized Hosts` option in the +function list. + +.. warning:: Non-ASCII characters are not recommended to be put into the + customized hosts file. + +.. versionadded:: 1.9.8 + + .. note:: Specific user manual is not included in this documentation. For further information, please visit our `website `_. diff --git a/gui/qdialog_ui.py b/gui/qdialog_ui.py index d445c63..c1e9fac 100644 --- a/gui/qdialog_ui.py +++ b/gui/qdialog_ui.py @@ -61,6 +61,8 @@ class QDialogUI(QtGui.QDialog, object): :ivar str custom: File name of User Customized Hosts File. Customized hosts would be able to select if this file exists. The default file name is ``custom.hosts``. + + .. seealso:: :ref:`User Customized Hosts`. """ _cur_ver = "" _trans = None diff --git a/tui/curses_ui.py b/tui/curses_ui.py index ad013ee..3e0328b 100644 --- a/tui/curses_ui.py +++ b/tui/curses_ui.py @@ -110,12 +110,14 @@ class CursesUI(object): :ivar str infofile: Filename of the info file containing metadata of the hosts data file formatted in JSON. Default by "`hostslist.json`". - .. seealso:: :attr:`filename` and :attr:`infofile` in - :class:`~gui.hostsutil.HostsUtil` class. + .. seealso:: :attr:`filename` and :attr:`infofile` in + :class:`~gui.hostsutil.HostsUtil` class. :ivar str custom: File name of User Customized Hosts File. Customized hosts would be able to select if this file exists. The default file name is ``custom.hosts``. + + .. seealso:: :ref:`User Customized Hosts`. """ __title = "HOSTS SETUP UTILITY" version = "".join(['v', __version__, ' ', __release__]) diff --git a/util/makehosts.py b/util/makehosts.py index 3f05ac2..8f7a51d 100644 --- a/util/makehosts.py +++ b/util/makehosts.py @@ -30,6 +30,9 @@ class MakeHosts(object): :class:`~gui.qdialog_d.QDialogDaemon` class. :ivar str custom: File name of User Customized Hosts file. + + .. seealso:: :ref:`User Customized Hosts`. + :ivar str hostname: File Name of hosts file. :ivar file hosts_file: The hosts file to write hosts to. :ivar int mod_num: Total number of modules written to hosts file. From e2be4db031d81c154e7fb5875cd4bc477c493540 Mon Sep 17 00:00:00 2001 From: huhamhire Date: Wed, 22 Jan 2014 20:22:24 +0800 Subject: [PATCH 09/11] fix code page problem for tui on windows --- README.rst | 3 --- doc/dev/intro.rst | 4 ---- hoststool.py | 20 ++++++++++++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 8cdb8de..92cebc0 100644 --- a/README.rst +++ b/README.rst @@ -148,9 +148,6 @@ Text-based User Interface (TUI) Mode not, a warning message box would show up and then terminate current session. -If current session is running with `cmd` on a non-english Windows system, -command ``chcp 437`` is required by curses to set the default code page. - User Customized Hosts ===================== diff --git a/doc/dev/intro.rst b/doc/dev/intro.rst index d31f0e8..86f7758 100644 --- a/doc/dev/intro.rst +++ b/doc/dev/intro.rst @@ -137,10 +137,6 @@ Text-based User Interface (TUI) Mode .. seealso:: :class:`~hoststool.UtilLauncher`. -.. warning:: If current session is running with `cmd` on a non-english - Windows system, command ``chcp 437`` is required by curses to set the - default code page. - .. _intro-customize: diff --git a/hoststool.py b/hoststool.py index b23637c..505b8d3 100644 --- a/hoststool.py +++ b/hoststool.py @@ -16,6 +16,8 @@ __author__ = "huhamhire " +import os + from optparse import OptionParser import gui @@ -23,6 +25,10 @@ from __version__ import __version__ +import sys +sys.path.append("..") +from util import CommonUtil + class UtilLauncher(object): """ @@ -116,8 +122,22 @@ def launch_tui(cls): .. note:: This is a `classmethod`. """ + + # Set code page for Windows + system = CommonUtil.check_platform()[0] + cp = "437" + if system == "Windows": + chcp = os.popen("chcp") + cp = chcp.read().split()[-1] + chcp.close() + os.popen("chcp 437") + main = tui.HostsUtil() main.start() + # Restore the default code page for Windows + if system == "Windows": + os.popen("chcp " + cp) + if __name__ == "__main__": UtilLauncher.launch() \ No newline at end of file From b3fde3f6b227c3a983b46ecbea18988288a94c46 Mon Sep 17 00:00:00 2001 From: huhamhire Date: Fri, 24 Jan 2014 10:54:00 +0800 Subject: [PATCH 10/11] fix build script for mac --- _build.py | 4 ++-- res/mac/dmg/DS_Store_dmg | Bin 15364 -> 15364 bytes 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_build.py b/_build.py index 300aaca..a9cf3ff 100644 --- a/_build.py +++ b/_build.py @@ -235,7 +235,7 @@ from setuptools import setup # Set working directories WORK_DIR = SCRIPT_DIR + "work/" - RES_DIR = SCRIPT_DIR + "res/" + RES_DIR = SCRIPT_DIR + "res/mac/" APP_NAME = "HostsTool.app" APP_PATH = WORK_DIR + APP_NAME DIST_DIR = APP_PATH + "/Contents/" @@ -296,7 +296,7 @@ # Clean work directory after build os.remove(DIST_DIR + "Resources/applet.icns") shutil.copy2( - SCRIPT_DIR + "img/icons/hosts_utl.icns", + SCRIPT_DIR + "res/img/icons/hosts_utl.icns", DIST_DIR + "Resources/applet.icns") shutil.copy2(RES_DIR + "Info.plist", DIST_DIR + "Info.plist") shutil.rmtree(SCRIPT_DIR + "build/") diff --git a/res/mac/dmg/DS_Store_dmg b/res/mac/dmg/DS_Store_dmg index 7655ef6e8ba8745911c1607598c507db53e281f3..bd9d541a3a00f652fc43048ab86797b170355b18 100644 GIT binary patch literal 15364 zcmeHMU2Ggz6+YwL#JfpskAFg(#A;V^C5oC|&;HrFHdWSZCnTWA5jLqqQ=FNdS$pN( znbpqNZb_m#5)b?oAt51Eq7OV&5CIPX^3Vr_BH$qsC<#&@`cR1=As+ew6;Y%hwn+$G5_&t(xC2oFQ|Q1{5l0LqFh_er^eYLy9q7QE6mj@a#FG_q zLQ(vu!+*l>PD&}z@+ujS4D4kfIJ+m#)}4w`-+6vlzC(262ag~7CJLpDEw?FpylXV; zHP_R$ca)w;bl?8oSRB&VKhXEm;+nIy=;_{uTh?1Ia_zkCtr-F@IZnNeb>l+K+FDUZ z<{aD8Yqr($jccZbE|*@Y*`~8qb~bF&y|frKzECs0HQ%Xdh(Y2j>gbg#g~{THL^eHj z?L^{Au8=;F$WLajT~jF@JNn7&$)&|on>T(KP@sr3LW5nD{0MbKTdQn} zXrtG|Xn(H`wBtQ+@DSov2Zx474u9gv=+R@x$HtyoQHKq^vcB5lQO`Mbr&X?RSctIG zdbXjjTC??TXX zWykZJ#)>-N+g2R=e9L0H6$v?h#&JEDXF0gL^LnrMuVZJP zqkY_YAk_&e)wEZ4_WRec^8DRL_u9WQJ%$kViBCe?!_MKT{C&CCd;JaE9b|m>(TWSq z>!62@wg*1FXK4NS5)Dv_4AQAW>$FNOa%h8WGSS+EUd8h?CYBTD^i8W(tE}@dJ976|hc)m>wEvmjUa!$i znT?OYpYS(e9mKpGH?7TVrUl$mZ(gU%J>H(e?SOp#teFlNw7kCKx zzQDu44+KsCkBJycz@HXaLFYT7j|zN4yr$c5_l^7LSGZb6E^I0_N`a{#4qwF3h!Noi9cg#+9e8N34N1x%x8h?fuC>3IEOuh!g1u& zQ>XH?Q&Y*wVj-K%&X;GCvy+8Fa;{j=va^}=>C>59_)Oh@ZjAnNgrDzwWUqeA5ybgD zEFaF#?AL#xfJ08jtJUVT{fh1A6TWOJ`@pErz|S(u8p>6aFs70jFc{W3XRw6z-mdyV zi`R83#r_5?5U$iW(ViYsgTs1qT=W}M>%$WJ98BNGu5ZuUUGZm+i(woh? z#n+^(+os{XoN8IRncQmCJS#L!&uD4iC?B?PtvZ?4jG2iIPSx#fYKGarlTC?!i?MU& z;Wfj;bIzIPH4YZSndgrJcW0iziFVF5Zv;z$INOX0JP3SVV9qw0z?^ML0w;j43akO& zp+J<|!Mn$`L112gEJL@64vGHVS?HE%A3{G~D^K`5HMzwwfy#g`8!W#hjJVDus-pXS3C*d@gI{^kNm& z$zpr9_kxeUhK#l|-$y!Y&P;5IEzTNm2|a8HI~yS$GNm>bTXx;?H-8-9KiOh+9Z$r+tvSeSO2~zYzb4aZc=l%CH)zeH?g7~iqWAeMKbW8WdLc6CBeS|oI;A> z{fiXIfMnqRivcA%zc^n;%wn&!Cwkr=B~UJ-uyDWaK>H@R_**DwY)kwK@28(-j5dum z3vfy3?Leai^56e6K%W2Q`9J)n*8eFbJiGJy9YNu>%WL@Kd;UjoQX~VC0m*=5Kr$d1 fkPJu$Bm?T z2++7kI_LY&Ip6o4^Zm{_-#y1BBBj_hl0+I2g^-y>22s36;(pEtQb4vuKo#hdRR+hk zw`7k`d<1+1d<1+1d<1+1{?`z|H=9%FA(#54kARPWk3bIrjt?3#(}JYiE)}5zg?Ivh zs%RDoJU;+fN0YQ5>9$MJgQU2spsuPSpBRd(j&@DT6(rqusjE(ke0(T!WJSJE6frvN zYeJlqf=m6 z1N>zv{Y2exYAcbkYuB>*?1Yw1r?)1wYg4)8gqF!Bx3TsZ5S(gr|-}M~$b7ZLJ!h;VD9zHS@8IF#O9{tF%vEvV)h<@zj zE0K}1URhi1uvha|!|D_pU2`Qey4!lTsjr%Ijk<2HM22j*eYRq?&Uei9y1B7j2Vbf` zV=g=9ro+riB)Y3A41UoxzP#JC^mKc_c_H(Kj%l`@T2T39Ky^-8_9I(}-$#cgpo zaGN=lh_RtFmhIRVoQB)Eue>#K?AK>LM~7H=D8B1Myxm&eC;0v@^p`u;zC5%7KpA zFm>DH?=%p+nfv)S(dQxdX9cTuhK8*xAZ6c>iG|4Kp9a!8r%uK9sIi*R0q`~ z>M>PQPpY3)C)Ajla%}_@Y3mVhK$ohspa@m%Vlg3O?YoIRDVdv{T$j78#^~5U7es|0pP@L*Tashg|^v1<4n{KQDQJPosRakpddgro3oHz>jhx z(y&JKrr@y6!QYhp2>90}uYn(v{uaRJB(K~ix*=sE;NOr(eS3#!LXL}W7mYO+jYF@O zEo<$M53rgVNl5MckvCvz00R7RkmrzmB5JAVv)T`fghf2+J0Cduxsc0 z@zW6I`LQ3<(^HxGVlfp<6mywaIyIk&<>%%yvAKo0)O2Qg>U83{oWyEJQ>>s*j+-dA#Wl-i|qON znvDKlJ$Q#_wcCHSuWlcY@9WQV!ufX;V15W(WwLs79X|g?_VO>2L z@aH5y4E|ZkbA+l%o+H$z{f| z?{PVxCG@esw1dctjmC%h-!=c%|JPgNsCm%s!3Fka`4*fh05@ghmxtK9kmwTjKg> z?AK9_^y!44vjp2Z^lH$u`{b|p$qyd5TE?N Date: Fri, 24 Jan 2014 11:55:57 +0800 Subject: [PATCH 11/11] fix make hosts for current system issue --- util/makehosts.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/util/makehosts.py b/util/makehosts.py index 8f7a51d..c506f25 100644 --- a/util/makehosts.py +++ b/util/makehosts.py @@ -70,13 +70,14 @@ class to retrieve configuration with. self.hostname = parent.hostname self.custom = parent.custom make_path = parent.make_path - if parent.make_mode == "system": + self.make_mode = parent.make_mode + if self.make_mode == "system": self.eol = parent.sys_eol self.hosts_file = open("hosts", "wb") - elif parent.make_mode == "ansi": + elif self.make_mode == "ansi": self.eol = "\r\n" self.hosts_file = open(unicode(make_path), "wb") - elif parent.make_mode == "utf-8": + elif self.make_mode == "utf-8": self.eol = "\n" self.hosts_file = open(unicode(make_path), "wb")