Пример #1
0
    def getContentFromUrl(self, progress_dlg):

        co.log("fetch '%s'.." % self.url)

        if co.httpExists(self.url):

            if progress_dlg:
                progress_dlg.Update(10),
            try:
                cnt = []
                up = 10
                url_o = urllib.urlopen(self.url)
                while True:
                    c = url_o.read(1024)
                    if not c:
                        break
                    cnt.append(c)
                    up += 1
                    if up < 60:
                        if progress_dlg:
                            progress_dlg.Update(up),
                cnt = "".join(cnt)
                if progress_dlg:
                    progress_dlg.Update(60),
            except Exception:
                co.debugErr()
                return ""

            self.last_fetch_dt = datetime.datetime.now()

        else:
            cnt = u"### URL无法访问! ###".encode("utf-8")

        return cnt
Пример #2
0
    def OnImport(self, event):

        dlg = ui.Dlg_Import(self)
        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.m_filePicker.GetPath()
            url = dlg.m_textCtrl_url.GetValue()

            content = None
            if dlg.m_notebook.GetSelection() != 1:
                # 本地
                if os.path.isfile(path):
                    content = open(path).read()

                else:
                    wx.MessageBox(u"%s 不是有效的文件路径!" % path, caption=u"出错啦!")

            else:
                # 在线
                if co.httpExists(url):
                    content = urllib.urlopen(url).read()

                else:
                    wx.MessageBox(u"URL %s 无法访问!" % url, caption=u"出错啦!")

            if content and wx.MessageBox(u"导入档案会替换现有设置及数据,确定要导入吗?",
                    caption=u"警告",
                    style=wx.OK | wx.CANCEL) == wx.OK:
                self.importHosts(content)

        dlg.Destroy()
Пример #3
0
    def OnImport(self, event):

        dlg = ui.Dlg_Import(self)
        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.m_filePicker.GetPath()
            url = dlg.m_textCtrl_url.GetValue()

            content = None
            if dlg.m_notebook.GetSelection() != 1:
                # 本地
                if os.path.isfile(path):
                    content = open(path).read()

                else:
                    wx.MessageBox(u"%s 不是有效的文件路径!" % path, caption=u"出错啦!")

            else:
                # 在线
                if co.httpExists(url):
                    content = urllib.urlopen(url).read()

                else:
                    wx.MessageBox(u"URL %s 无法访问!" % url, caption=u"出错啦!")

            if content and wx.MessageBox(u"导入档案会替换现有设置及数据,确定要导入吗?",
                                         caption=u"警告",
                                         style=wx.OK | wx.CANCEL) == wx.OK:
                self.importHosts(content)

        dlg.Destroy()
Пример #4
0
    def getContentFromUrl(self, progress_dlg):

        co.log("fetch '%s'.." % self.url)

        if co.httpExists(self.url):

            if progress_dlg:
                progress_dlg.Update(10),
            try:
                cnt = []
                up = 10
                url_o = urllib.urlopen(self.url)
                while True:
                    c = url_o.read(1024)
                    if not c:
                        break
                    cnt.append(c)
                    up += 1
                    if up < 60:
                        if progress_dlg:
                            progress_dlg.Update(up),
                cnt = "".join(cnt)
                if progress_dlg:
                    progress_dlg.Update(60),
            except Exception:
                co.debugErr()
                return ""

            self.last_fetch_dt = datetime.datetime.now()

        else:
            cnt = u"### URL无法访问! ###".encode("utf-8")

        return cnt
Пример #5
0
    def read(self):

        if not self.url:
            c = open(self.path, "rb").read().strip() if os.path.isfile(self.path) else ""

        else:
            c = urllib2.urlopen(self.url).read().strip() if co.httpExists(self.url) else ""

        #        c = co.decode(c)
        self.setContent(c, save=False)
Пример #6
0
    def read(self):

        if not self.url:
            c = open(self.path, "rb").read().strip() if os.path.isfile(
                self.path) else ""

        else:
            c = urllib2.urlopen(self.url).read().strip() if co.httpExists(
                self.url) else ""

#        c = co.decode(c)
        self.setContent(c, save=False)