示例#1
0
文件: posts.py 项目: bohwaz/wordmobi
 def view_image(self, img):
     if os.path.isfile(img):
         local = True
     else:
         local = False
         
     if local:
         viewer = Content_handler(self.refresh)
         try:
             viewer.open(img)
         except:
             note(LABELS.loc.pt_err_cant_open % img,"error") 
     else:
         local_file = "img_" + time.strftime("%Y%m%d_%H%M%S", time.localtime())
         local_file = os.path.join(DEFDIR, "cache", local_file)
         d = img.rfind(".")
         if d >= 0:
             local_file = local_file + img[d:]
             self.lock_ui(LABELS.loc.pt_info_downld_img % img)
             try:
                 urlprx = UrllibProxy(BLOG.get_proxy())
                 urlprx.urlretrieve(img, local_file)
             except:
                 note(LABELS.loc.pt_err_cant_downld % img,"error")
                 self.unlock_ui()
                 return
             self.unlock_ui()
             viewer = Content_handler(self.refresh)
             try:
                 viewer.open(local_file)
             except:
                 note(LABELS.loc.pt_err_cant_open % img,"error") 
         else:
             note(LABELS.loc.pt_err_unknown_ext % img,"error")
示例#2
0
    def upgrade(self):
        self.lock_ui(LABELS.loc.wm_info_check_updt)
        
        url = "http://code.google.com/p/wordmobi/wiki/LatestVersion"
        local_file = "web_" + time.strftime("%Y%m%d_%H%M%S", time.localtime()) + ".html"
        local_file = os.path.join(DEFDIR, "cache", local_file)

        try:
            urlprx = UrllibProxy(BLOG.get_proxy())
            urlprx.urlretrieve(url, local_file)
        except:
            note(LABELS.loc.wm_err_upd_page % url,"error")
            ok = False
        else:
            ok = True

        if ok:
            html = open(local_file).read()
            soup = BeautifulSoup( html )
            addrs = soup.findAll('a')
            version = ""
            file_url = ""
            file_url_py19 = ""
            for addr in addrs:
                if addr.contents[0] == "latest_wordmobi_version":
                    version = addr["href"]
                elif addr.contents[0] == "wordmobi_sis_url":
                    file_url = addr["href"]
                elif addr.contents[0] == "wordmobi_sis_url_py19":
                    file_url_py19 = addr["href"]

            if version and file_url and file_url_py19:
                version = version[version.rfind("/")+1:]
                num_rem_ver = self.ver2num(version)
                num_loc_ver = self.ver2num(VERSION)
                if (num_loc_ver >= num_rem_ver) and (VERSION.find('RC') == -1):
                    # RC versions gives to the user the upgrading decision
                    note(LABELS.loc.wm_info_ver_is_updt, "info")
                else:
                    yn = popup_menu( [LABELS.loc.gm_yes,LABELS.loc.gm_no],
                                     LABELS.loc.wm_pmenu_download % (version) )
                    if yn is not None:
                        if yn == 0:
                            if float(e32.pys60_version[:3]) >= 1.9:
                                furl = file_url_py19
                            else:
                                furl = file_url
                            sis_name = furl[furl.rfind("/")+1:]
                            local_file = os.path.join(DEFDIR, "updates", sis_name)

                            self.set_title( LABELS.loc.wm_info_downloading )
                            try:
                                urlprx = UrllibProxy(BLOG.get_proxy())
                                urlprx.urlretrieve(furl, local_file)
                            except:
                                note(LABELS.loc.wm_err_downld_fail % sis_name, "error")
                            else:
                                msg = LABELS.loc.wm_info_downld_ok % (sis_name,DEFDIR)
                                note( msg , "info")

            else:
                note(LABELS.loc.wm_err_upd_info,"error")
                
        self.set_title( u"Wordmobi" )
        self.unlock_ui()
        self.refresh()