def merge(master, args, v4=False): ''' A master Metalink object with no <files> information and a list of files to merge together. ''' master = metalink.convert(master, 3) master.files = [] for item in args: xml = metalink.parsefile(item) for fileobj in xml.files: master.files.append(fileobj) if v4: master = metalink.convert(master, 4) return master.generate() return master.generate()
def build(xml, urls, output=None, localfile=None, download=True, do_ed2k=True, do_magnet=False, v4=False, pubdate=None): ''' urls - RFC 2396 encoded urls ''' if len(urls) > 0: url = urls[0] if localfile == None: localfile = os.path.basename(url) if download: print "Downloading file..." # download file here progress = ProgressBar(55) #print url, localfile urllib.urlretrieve(url, localfile, progress.download_update) progress.download_end() xmlfile = metalink.MetalinkFile(localfile, do_ed2k=do_ed2k, do_magnet=do_magnet) xml.files.append(xmlfile) xmlfile.scan_file(localfile) for item in urls: xmlfile.add_url(item) if pubdate: xml.pubdate = time.strftime(metalink.RFC822, time.gmtime(os.path.getmtime(localfile))) if not xml.validate(): for line in xml.errors: print line return print "Generating XML..." if output == None and v4: output = localfile + ".meta4" if output == None: output = localfile + ".metalink" if v4 or output.endswith(".meta4"): # convert to v4 xml = metalink.convert(xml, 4) handle = open(output, "wb") handle.write(xml.generate()) handle.close() return xml
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 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 sml.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 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 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