예제 #1
0
def checkRepositoryEULA(name, repo):
    """ This function is to check the EULA file if provided.
        return True: no EULA or accepted
        return False: user declined the EULA
    """

    import tempfile
    import shutil
    import urlparse
    import urllib2 as u2
    import httplib
    from errors import CreatorError

    def _check_and_download_url(u2opener, url, savepath):
        try:
            if u2opener:
                f = u2opener.open(url)
            else:
                f = u2.urlopen(url)
        except u2.HTTPError, httperror:
            if httperror.code in (404, 503):
                return None
            else:
                raise CreatorError(httperror)
        except OSError, oserr:
            if oserr.errno == 2:
                return None
            else:
                raise CreatorError(oserr)
예제 #2
0
 def _check_and_download_url(u2opener, url, savepath):
     try:
         if u2opener:
             f = u2opener.open(url)
         else:
             f = u2.urlopen(url)
     except u2.HTTPError, httperror:
         if httperror.code in (404, 503):
             return None
         else:
             raise CreatorError(httperror)
예제 #3
0
def myurlgrab(url, filename, proxies, progress_obj=None):
    g = grabber.URLGrabber()
    if progress_obj is None:
        progress_obj = TextProgress()

    if url.startswith("file:/"):
        file = url.replace("file:", "")
        if not os.path.exists(file):
            raise CreatorError("URLGrabber error: can't find file %s" % file)
        runner.show(['cp', "-f", file, filename])
    else:
        try:
            filename = g.urlgrab(url=url,
                                 filename=filename,
                                 ssl_verify_host=False,
                                 ssl_verify_peer=False,
                                 proxies=proxies,
                                 http_headers=(('Pragma', 'no-cache'), ),
                                 quote=0,
                                 progress_obj=progress_obj)
        except grabber.URLGrabError, e:
            raise CreatorError("URLGrabber error: %s" % url)
예제 #4
0
                f = u2.urlopen(url)
        except u2.HTTPError, httperror:
            if httperror.code in (404, 503):
                return None
            else:
                raise CreatorError(httperror)
        except OSError, oserr:
            if oserr.errno == 2:
                return None
            else:
                raise CreatorError(oserr)
        except IOError, oserr:
            if hasattr(oserr, "reason") and oserr.reason.errno == 2:
                return None
            else:
                raise CreatorError(oserr)
        except u2.URLError, err:
            raise CreatorError(err)
        except httplib.HTTPException, e:
            raise CreatorError(e)

        # save to file
        licf = open(savepath, "w")
        licf.write(f.read())
        licf.close()
        f.close()

        return savepath

    def _pager_file(savepath):