def onAddURL(self, evt): if self.txtctrl_url.GetValue() != "": url = self.txtctrl_url.GetValue() loc = self.txtctrl_loc.GetValue() pref = self.txtctrl_pref.GetValue() conns = self.combo_maxconn.GetValue() self.addurl(metalink.Resource(url, "", loc, pref, conns))
def save(self): # Generate the file mlfile = self.ml mlfile.filename = self.txtctrl_filename.GetValue() mlfile.identity = self.txtctrl_identity.GetValue() mlfile.publisher_name = self.txtctrl_pub_name.GetValue() mlfile.publisher_url = self.txtctrl_pub_url.GetValue() mlfile.copyright = self.txtctrl_copy.GetValue() mlfile.description = self.txtctrl_desc.GetValue() mlfile.license_name = self.combo_license_name.GetValue() if mlfile.license_name == 'Unknown': mlfile.license_name = "" mlfile.license_url = self.txtctrl_license_url.GetValue() mlfile.size = self.txtctrl_size.GetValue() mlfile.version = self.txtctrl_version.GetValue() self.mlfile.os = self.combo_os.GetValue() if self.mlfile.os == 'Unknown': self.mlfile.os = "" self.mlfile.language = self.txtctrl_lang.GetValue() self.mlfile.maxconnections = self.combo_maxconn_total.GetValue() mlfile.origin = "" self.mlfile.hashlist['md5'] = self.txtctrl_md5.GetValue() self.mlfile.hashlist['sha1'] = self.txtctrl_sha1.GetValue() self.mlfile.hashlist['sha256'] = self.txtctrl_sha256.GetValue() self.mlfile.clear_res() item = -1 while True: item = self.filelist.GetNextItem(item, wx.LIST_NEXT_ALL, wx.LIST_STATE_DONTCARE) if item == -1: break url = self.filelist.GetItem(item, 0).GetText() loc = self.filelist.GetItem(item, 1).GetText() pref = self.filelist.GetItem(item, 2).GetText() conns = self.filelist.GetItem(item, 3).GetText() res = metalink.Resource(url, "default", loc, pref, conns) if not res.validate(): for e in res.errors: answer = wx.MessageBox(e + " Continue anyway?", "Confirm", wx.ICON_ERROR | wx.OK | wx.CANCEL, self) if answer != wx.OK: return self.mlfile.add_res(res) ml = self.ml if self.filename.endswith("meta4"): ml = metalink.convert(self.ml, 4) if not ml.validate(): for e in ml.errors: answer = wx.MessageBox(e + " Continue anyway?", "Confirm", wx.ICON_ERROR | wx.OK | wx.CANCEL, self) if answer != wx.OK: return ml.errors = [] try: text = ml.generate() except Exception, e: wx.MessageBox(str(e), "Error!", wx.ICON_ERROR) return
def onBtnChange(self, evt): if self.txtctrl_url.GetValue() != "": url = self.txtctrl_url.GetValue() loc = self.txtctrl_loc.GetValue() pref = self.txtctrl_pref.GetValue() conns = self.combo_maxconn.GetValue() res = metalink.Resource(url, "", loc, pref, conns) if not res.validate(): for e in res.errors: answer = wx.MessageBox(e + " Change it anyway?", "Confirm", wx.ICON_ERROR | wx.OK | wx.CANCEL, self) if answer != wx.OK: return item = self.filelist.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED); self.filelist.SetStringItem(item, 0, res.url) self.filelist.SetStringItem(item, 1, res.location) self.filelist.SetStringItem(item, 2, res.preference) self.filelist.SetStringItem(item, 3, res.maxconnections) self.clear_urlfields()
def save(self): # Generate the file mlfile = self.ml mlfile.filename = self.txtctrl_filename.GetValue() mlfile.identity = self.txtctrl_identity.GetValue() mlfile.publisher_name = self.txtctrl_pub_name.GetValue() mlfile.publisher_url = self.txtctrl_pub_url.GetValue() mlfile.copyright = self.txtctrl_copy.GetValue() mlfile.description = self.txtctrl_desc.GetValue() mlfile.license_name = self.combo_license_name.GetValue() if mlfile.license_name == 'Unknown': mlfile.license_name = "" mlfile.license_url = self.txtctrl_license_url.GetValue() mlfile.size = self.txtctrl_size.GetValue() mlfile.version = self.txtctrl_version.GetValue() self.mlfile.os = self.combo_os.GetValue() if self.mlfile.os == 'Unknown': self.mlfile.os = "" self.mlfile.language = self.txtctrl_lang.GetValue() self.mlfile.maxconnections = self.combo_maxconn_total.GetValue() mlfile.origin = "" self.mlfile.hashlist['md5'] = self.txtctrl_md5.GetValue() self.mlfile.hashlist['sha1'] = self.txtctrl_sha1.GetValue() self.mlfile.hashlist['sha256'] = self.txtctrl_sha256.GetValue() self.mlfile.clear_res() item = -1 while True: item = self.filelist.GetNextItem(item, wx.LIST_NEXT_ALL, wx.LIST_STATE_DONTCARE) if item == -1: break url = self.filelist.GetItem(item, 0).GetText() loc = self.filelist.GetItem(item, 1).GetText() pref = self.filelist.GetItem(item, 2).GetText() conns = self.filelist.GetItem(item, 3).GetText() res = metalink.Resource(url, "default", loc, pref, conns) if not res.validate(): for e in res.errors: answer = wx.MessageBox(e + " Continue anyway?", "Confirm", wx.ICON_ERROR | wx.OK | wx.CANCEL, self) if answer != wx.OK: return self.mlfile.add_res(res) ml = self.ml if self.filename.endswith("meta4"): ml = metalink.convert(self.ml, 4) if not ml.validate(): for e in ml.errors: answer = wx.MessageBox(e + " Continue anyway?", "Confirm", wx.ICON_ERROR | wx.OK | wx.CANCEL, self) if answer != wx.OK: return ml.errors = [] #try: text = ml.generate() #except Exception, e: # wx.MessageBox(str(e), "Error!", wx.ICON_ERROR) # return outfilename = self.filename # Warn about overwrites if os.path.isfile(self.filename) and self.new_file: answer = wx.MessageBox( "There already exists a file named " + os.path.basename(outfilename) + ". Overwrite file?", "Confirm", wx.OK | wx.CANCEL | wx.ICON_QUESTION, self) if answer != wx.OK: return # Save the file try: fp = open(outfilename, "w") except IOError: wx.MessageBox("Could not open output file!", "Error!", wx.ICON_ERROR) return try: fp.write(text) fp.close() except IOError, e: wx.MessageBox(str(e), "Error!", wx.ICON_ERROR) return
def onBtnScan(self, evt): filename = wx.FileSelector("Choose a file to scan") if filename != "": config = wx.ConfigBase.Get() config.SetPath("/Scanning") use_md5 = config.ReadBool("use_md5_checksums", use_md5_default) use_sha1 = config.ReadBool("use_sha1_checksums", use_sha1_default) use_sha256 = config.ReadBool("use_sha256_checksums", use_sha256_default) use_chunks = config.ReadBool("use_chunk_checksums", use_chunks_default) max_chunks = config.ReadInt("max_chunk_checksums", max_chunks_default) size_chunks = config.ReadInt("min_chunk_size", chunk_size_default) old_filename = self.mlfile.filename progressdlg = wx.ProgressDialog( "Scanning file...", "Please wait while Metalink Editor scans the selected file. This can take some time for very large files.", 100, self, wx.PD_AUTO_HIDE | wx.PD_APP_MODAL | wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME | wx.PD_ESTIMATED_TIME) success = self.mlfile.scan_file(filename, use_chunks, max_chunks, size_chunks, progressdlg) progressdlg.Destroy() if not success: return self.txtctrl_size.SetValue(str(self.mlfile.size)) self.txtctrl_filename.SetValue(self.mlfile.filename) md5val = "" if use_md5: md5val = self.mlfile.hashlist['md5'] self.txtctrl_md5.SetValue(md5val) sha1val = "" if use_sha1: sha1val = self.mlfile.hashlist['sha1'] self.txtctrl_sha1.SetValue(sha1val) sha256val = "" if use_sha256: sha256val = self.mlfile.hashlist['sha256'] self.txtctrl_sha256.SetValue(sha256val) if self.mlfile.hashlist['sha256'] == "": self.txtctrl_sha256.Enable(False) # No support for SHA-256 # Update URLs num_urls = self.filelist.GetItemCount() new_filename = self.mlfile.filename if num_urls > 0 and new_filename != old_filename: answer = wx.MessageBox( "Would you like to update your URLs, so that they use the new filename instead of the old?", "Update mirrors?", wx.ICON_QUESTION | wx.YES_NO, self) if answer == wx.YES: print "\nUpdating mirrors with the new filename." print "Changing", old_filename, "to", new_filename + "." item = -1 while True: item = self.filelist.GetNextItem( item, wx.LIST_NEXT_ALL, wx.LIST_STATE_DONTCARE) if item == -1: break url = self.filelist.GetItem(item, 0).GetText() #if old_filename == "": url = os.path.dirname(url) + "/" + new_filename self.filelist.SetStringItem(item, 0, url) #else: # pos = url.rfind(old_filename) # if pos != -1: # print "Updated", url # url = url[:pos] + new_filename # self.filelist.SetStringItem(item, 0, url) item = -1 while True: item = self.filelist.GetNextItem(item, wx.LIST_NEXT_ALL, wx.LIST_STATE_DONTCARE) if item == -1: break url = self.filelist.GetItem(item, 0).GetText() if url.startswith("ed2k://"): # remove ed2k links, they add themselves back in later self.filelist.DeleteItem(item) if url.startswith("magnet:"): # remove magnet links, they add themselves back in later self.filelist.DeleteItem(item) # add ed2k and magnet link to GUI for this file if self.mlfile.ed2k != "": self.addurl(metalink.Resource(self.mlfile.ed2k)) if self.mlfile.magnet != "": self.addurl(metalink.Resource(self.mlfile.magnet)) self.filename = filename + ".metalink" self.new_file = True self.locked = True self.update()