示例#1
0
    def dl_task(task):
        src = task.inputs[0]
        tgt = task.outputs[0]
        url = src.read().strip()
        try:
            web = urlopen(url)
            tgt.write(web.read(),'wb')
        except Exception:
            import traceback
            traceback.print_exc()
            msg.error(tgen.worch.format("[{package}_dlpatch] problem downloading [{patch_urlfile}]"))
            raise

        checksum = tgen.worch.patch_checksum
        if not checksum:
            return
        hasher_name, ref = checksum.split(":")
        import hashlib, os
        # FIXME: check the hasher method exists. check for typos.
        hasher = getattr(hashlib, hasher_name)()
        hasher.update(tgt.read('rb'))
        data= hasher.hexdigest()
        if data != ref:
            msg.error(tgen.worch.format("[{package}_dlpatch] invalid checksum:\nref: %s\nnew: %s" %\
                                        (ref, data)))
            try:
                os.remove(tgt.abspath())
            except IOError: 
                pass
            return 1
        return
示例#2
0
 def dl_task(task):
     src = task.inputs[0]
     tgt = task.outputs[0]
     url = src.read().strip()
     try:
         web = urlopen(url)
         tgt.write(web.read(),'wb')
     except Exception:
         import traceback
         traceback.print_exc()
         info.ctx.fatal("[%s] problem downloading [%s]" % (info.format('{package}_dlpatch'), url))