def run(): # Command line parser options. parser = optparse.OptionParser(usage="usage: %prog [options] directory") #parser.add_option("-o", dest="output", metavar="FILE", help=_("Apache style access file to")) (options, args) = parser.parse_args() if len(args) <= 0: print "ERROR: Specify a directory." parser.print_help() return text = "" for filename in os.listdir(args[0]): if filename.endswith(".metalink") or filename.endswith(".meta4"): fullname = os.path.join(args[0], filename) xml = metalink.parsefile(fullname, 4) for fileobj in xml.files: text += "SetEnvIf Request_URI \"/%s$\" %s\n" % ( fileobj.filename.replace( ".", "\."), fileobj.filename.replace(".", "_")) i = 1 for res in fileobj.resources: text += "SetEnvIf Request_URI \"/%s$\" link%d=%s\n" % ( fileobj.filename.replace(".", "\."), i, res.url) if res.type == "": pri = "" if res.priority != "": pri = "; pri=%s" % res.priority text += "Header %s add Link \"<%%{link%d}e>; rel=\\\"duplicate\\\"%s\" env=%s\n" % ( HTTPSTATUS, i, pri, fileobj.filename.replace(".", "_")) else: text += "Header %s add Link \"<%%{link%d}e>; rel=\\\"describedby\\\"\" env=%s\n" % ( HTTPSTATUS, i, fileobj.filename.replace(".", "_")) i += 1 keys = [] for key in fileobj.hashlist.keys(): keys.append(key) text += "SetEnvIf Request_URI \"/%s$\" %s=%s\n" % ( fileobj.filename.replace(".", "\."), key.replace("-", ""), binascii.b2a_base64( binascii.unhexlify(fileobj.hashlist[key]))) #if "md5" in keys: # text += "Header %s set Content-MD5 %%{md5}e env=%s\n" % (HTTPSTATUS, fileobj.filename.replace(".", "_")) if len(keys) != 0: hashtext = "" for key in keys: hashtext += "%s=%%{%s}e," % (lookup(key), key.replace("-", "")) hashtext = hashtext[:-1] text += "Header %s set Digest %s env=%s\n\n" % ( HTTPSTATUS, hashtext, fileobj.filename.replace( ".", "_")) print text
def onMenuOpen(self, evt): filename = wx.FileSelector( "Choose metalink file to load", "", "", ".metalink", "All files (*.*)|*.*|Metalink files (*.metalink)|*.metalink|Metalink4 files (*.meta4)|*.meta4", wx.OPEN) if filename != "": try: self.ml = metalink.parsefile(filename) self.mlfile = self.ml.files[0] except Exception, e: wx.MessageBox(str(e), "Error!", wx.ICON_ERROR) return self.txtctrl_filename.SetValue(self.mlfile.filename) self.txtctrl_identity.SetValue(self.ml.identity) self.txtctrl_pub_name.SetValue(self.ml.publisher_name) self.txtctrl_pub_url.SetValue(self.ml.publisher_url) self.txtctrl_copy.SetValue(self.ml.copyright) self.txtctrl_desc.SetValue(self.ml.description) self.combo_license_name.SetValue(self.ml.license_name) self.txtctrl_license_url.SetValue(self.ml.license_url) self.txtctrl_size.SetValue(str(self.mlfile.size)) self.txtctrl_version.SetValue(self.ml.version) self.combo_os.SetValue(self.mlfile.os) self.txtctrl_lang.SetValue(self.mlfile.language) self.combo_maxconn_total.SetValue(self.mlfile.maxconnections) try: self.txtctrl_md5.SetValue(self.mlfile.hashlist['md5']) except KeyError: pass try: self.txtctrl_sha1.SetValue(self.mlfile.hashlist['sha1']) except KeyError: pass try: self.txtctrl_sha256.SetValue(self.mlfile.hashlist['sha256']) except KeyError: pass self.txtctrl_url.Clear() self.txtctrl_loc.Clear() self.txtctrl_pref.Clear() self.init_filelist() for res in self.mlfile.resources: num_items = self.filelist.GetItemCount() self.filelist.InsertStringItem(num_items, res.url) self.filelist.SetStringItem(num_items, 1, res.location) self.filelist.SetStringItem(num_items, 2, res.preference) self.filelist.SetStringItem(num_items, 3, res.maxconnections) if len(self.mlfile.pieces) > 0 or self.txtctrl_md5.GetValue( ) != "" or self.txtctrl_sha1.GetValue( ) != "" or self.txtctrl_sha256.GetValue() != "": self.locked = True else: self.locked = False self.new_file = False self.filename = filename print "\nLoaded file:", filename self.update()
def onMenuOpen(self, evt): filename = wx.FileSelector("Choose metalink file to load", "", "", ".metalink", "All files (*.*)|*.*|Metalink files (*.metalink)|*.metalink|Metalink4 files (*.meta4)|*.meta4", wx.OPEN) if filename != "": try: self.ml = metalink.parsefile(filename) self.mlfile = self.ml.files[0] except Exception, e: wx.MessageBox(str(e), "Error!", wx.ICON_ERROR) return self.txtctrl_filename.SetValue(self.mlfile.filename) self.txtctrl_identity.SetValue(self.ml.identity) self.txtctrl_pub_name.SetValue(self.ml.publisher_name) self.txtctrl_pub_url.SetValue(self.ml.publisher_url) self.txtctrl_copy.SetValue(self.ml.copyright) self.txtctrl_desc.SetValue(self.ml.description) self.combo_license_name.SetValue(self.ml.license_name) self.txtctrl_license_url.SetValue(self.ml.license_url) self.txtctrl_size.SetValue(str(self.mlfile.size)) self.txtctrl_version.SetValue(self.ml.version) self.combo_os.SetValue(self.mlfile.os) self.txtctrl_lang.SetValue(self.mlfile.language) self.combo_maxconn_total.SetValue(self.mlfile.maxconnections) try: self.txtctrl_md5.SetValue(self.mlfile.hashlist['md5']) except KeyError: pass try: self.txtctrl_sha1.SetValue(self.mlfile.hashlist['sha1']) except KeyError: pass try: self.txtctrl_sha256.SetValue(self.mlfile.hashlist['sha256']) except KeyError: pass self.txtctrl_url.Clear() self.txtctrl_loc.Clear() self.txtctrl_pref.Clear() self.init_filelist() for res in self.mlfile.resources: num_items = self.filelist.GetItemCount() self.filelist.InsertStringItem(num_items, res.url) self.filelist.SetStringItem(num_items, 1, res.location) self.filelist.SetStringItem(num_items, 2, res.preference) self.filelist.SetStringItem(num_items, 3, res.maxconnections) if len(self.mlfile.pieces) > 0 or self.txtctrl_md5.GetValue() != "" or self.txtctrl_sha1.GetValue() != "" or self.txtctrl_sha256.GetValue() != "": self.locked = True else: self.locked = False self.new_file = False self.filename = filename print "\nLoaded file:", filename self.update()
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 run(): # Command line parser options. parser = optparse.OptionParser(usage = "usage: %prog [options] directory") #parser.add_option("-o", dest="output", metavar="FILE", help=_("Apache style access file to")) (options, args) = parser.parse_args() if len(args) <= 0: print "ERROR: Specify a directory." parser.print_help() return text = "" for filename in os.listdir(args[0]): if filename.endswith(".metalink") or filename.endswith(".meta4"): fullname = os.path.join(args[0], filename) xml = metalink.parsefile(fullname, 4) for fileobj in xml.files: text += "SetEnvIf Request_URI \"/%s$\" %s\n" % (fileobj.filename.replace(".","\."), fileobj.filename.replace(".", "_")) i = 1 for res in fileobj.resources: text += "SetEnvIf Request_URI \"/%s$\" link%d=%s\n" % (fileobj.filename.replace(".","\."), i, res.url) if res.type == "": pri = "" if res.priority != "": pri = "; pri=%s" % res.priority text += "Header %s add Link \"<%%{link%d}e>; rel=\\\"duplicate\\\"%s\" env=%s\n" % (HTTPSTATUS, i, pri, fileobj.filename.replace(".", "_")) else: text += "Header %s add Link \"<%%{link%d}e>; rel=\\\"describedby\\\"\" env=%s\n" % (HTTPSTATUS, i, fileobj.filename.replace(".", "_")) i += 1 keys = [] for key in fileobj.hashlist.keys(): keys.append(key) text += "SetEnvIf Request_URI \"/%s$\" %s=%s\n" % (fileobj.filename.replace(".","\."), key.replace("-", ""), binascii.b2a_base64(binascii.unhexlify(fileobj.hashlist[key]))) #if "md5" in keys: # text += "Header %s set Content-MD5 %%{md5}e env=%s\n" % (HTTPSTATUS, fileobj.filename.replace(".", "_")) if len(keys) != 0: hashtext = "" for key in keys: hashtext += "%s=%%{%s}e," % (lookup(key), key.replace("-","")) hashtext = hashtext[:-1] text += "Header %s set Digest %s env=%s\n\n" % (HTTPSTATUS, hashtext, fileobj.filename.replace(".", "_")) print text
def run(): # Command line parser options. parser = optparse.OptionParser(usage = "usage: %prog [options] urls") parser.add_option("--open", dest="open", help="Metalink file to open and modify") parser.add_option("-o", dest="output", help="Binary file name") parser.add_option("-d", dest="download", action="store_true", help="Don't download the file again") parser.add_option("--merge", "-m", dest="merge", action="store_true", help="Use merge mode, urls are .metalink files to merge") parser.add_option("--clear_urls", dest="clear_urls", action="store_true", help="Remove any existing urls when opening a file") parser.add_option("-4", dest="v4", action="store_true", help="Force output to Metalink v4") parser.add_option("-i", dest="identity", help="Identity") parser.add_option("-v", dest="version", help="Version Number") #parser.add_option("--os", dest="os", help="Operating System") parser.add_option("--publisher-name", dest="publisher_name", help="Publisher Name") parser.add_option("--publisher-url", dest="publisher_url", help="Publisher URL") parser.add_option("-c", "--copyright", dest="copyright", help="Copyright") parser.add_option("--description", dest="description", help="Description") parser.add_option("--license-name", dest="license_name", help="License Name") parser.add_option("--license-url", dest="license_url", help="License URL") #parser.add_option("--magnet", dest="magnet", action="store_false", help="Do not add a magnet URL") parser.add_option("--ed2k", dest="ed2k", action="store_false", help="Do not add a ed2k URL") #parser.add_option("-l", "--language", dest="language", help="The language the file is in, per ISO-639/3166. \"en-US\" for Standard American English") #parser.add_option("--maxconn", dest="maxconn_total", help="Maximum number of connections for downloading") parser.add_option("--origin", dest="origin", help="URL for the finished metalink file to check for updates") #parser.add_option("--logo", dest="logo", help="URL for a related logo") parser.add_option("-p", dest="pubdateflag", action="store_true", help="Set publication date to modified time") #parser.add_option("-s", "--size", dest="size", help="File size") parser.set_defaults(identity=None,version=None,os=None,publisher_name=None,publisher_url=None,copyright=None,description=None,license_name=None,license_url=None,language=None,maxconn_total=None,origin=None,magnet=False,ed2k=True,v4=False) (options, args) = parser.parse_args() if len(args) <= 0: print "ERROR: Specify a URL." parser.print_help() return # if options.pubdate: # options.pubdate = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) xml = metalink.Metalink() #options.ed2k, options.magnet) if options.open != None: xml = metalink.parsefile(options.open) if options.clear_urls: xml.clear_res() for option in dir(options): if not option.startswith("_") and getattr(options, option) != None: try: getattr(xml, option) except AttributeError: continue setattr(xml, option, getattr(options, option)) if options.merge != None: if len(args) < 2: print "ERROR: You should specify at least two files to merge." parser.print_help() return print merge(xml, args, options.v4) return download = True if options.download: download = False build(xml, args, None, options.output, download, options.ed2k, options.magnet, options.v4, options.pubdateflag)
def run(): # Command line parser options. parser = optparse.OptionParser(usage="usage: %prog [options] urls") parser.add_option("--open", dest="open", help="Metalink file to open and modify") parser.add_option("-o", dest="output", help="Binary file name") parser.add_option("-d", dest="download", action="store_true", help="Don't download the file again") parser.add_option("--merge", "-m", dest="merge", action="store_true", help="Use merge mode, urls are .metalink files to merge") parser.add_option("--clear_urls", dest="clear_urls", action="store_true", help="Remove any existing urls when opening a file") parser.add_option("-4", dest="v4", action="store_true", help="Force output to Metalink v4") parser.add_option("-i", dest="identity", help="Identity") parser.add_option("-v", dest="version", help="Version Number") #parser.add_option("--os", dest="os", help="Operating System") parser.add_option("--publisher-name", dest="publisher_name", help="Publisher Name") parser.add_option("--publisher-url", dest="publisher_url", help="Publisher URL") parser.add_option("-c", "--copyright", dest="copyright", help="Copyright") parser.add_option("--description", dest="description", help="Description") parser.add_option("--license-name", dest="license_name", help="License Name") parser.add_option("--license-url", dest="license_url", help="License URL") #parser.add_option("--magnet", dest="magnet", action="store_false", help="Do not add a magnet URL") parser.add_option("--ed2k", dest="ed2k", action="store_false", help="Do not add a ed2k URL") #parser.add_option("-l", "--language", dest="language", help="The language the file is in, per ISO-639/3166. \"en-US\" for Standard American English") #parser.add_option("--maxconn", dest="maxconn_total", help="Maximum number of connections for downloading") parser.add_option( "--origin", dest="origin", help="URL for the finished metalink file to check for updates") #parser.add_option("--logo", dest="logo", help="URL for a related logo") #parser.add_option("-d", dest="pubdate", action="store_true", help="Set publication date to now") #parser.add_option("-s", "--size", dest="size", help="File size") parser.set_defaults(identity=None, version=None, os=None, publisher_name=None, publisher_url=None, copyright=None, description=None, license_name=None, license_url=None, language=None, maxconn_total=None, origin=None, magnet=False, ed2k=True, v4=False) (options, args) = parser.parse_args() if len(args) <= 0: print "ERROR: Specify a URL." parser.print_help() return #if options.pubdate: # RFC 822 format # options.pubdate = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) xml = metalink.Metalink() #options.ed2k, options.magnet) if options.open != None: xml = metalink.parsefile(options.open) if options.clear_urls: xml.clear_res() for option in dir(options): if not option.startswith("_") and getattr(options, option) != None: try: getattr(xml, option) except AttributeError: continue setattr(xml, option, getattr(options, option)) if options.merge != None: if len(args) < 2: print "ERROR: You should specify at least two files to merge." parser.print_help() return print merge(xml, args, options.v4) return download = True if options.download: download = False build(xml, args, None, options.output, download, options.ed2k, options.magnet, options.v4)