예제 #1
0
파일: daemon.py 프로젝트: ccoss/koji
def incremental_upload(session, fname, fd, path, retries=5, logger=None):
    if not fd:
        return

    while True:
        offset = fd.tell()
        contents = fd.read(65536)
        size = len(contents)
        if size == 0:
            break

        data = base64.encodestring(contents)
        digest = md5_constructor(contents).hexdigest()
        del contents

        tries = 0
        while True:
            if session.uploadFile(path, fname, size, digest, offset, data):
                break

            if tries <= retries:
                tries += 1
                time.sleep(10)
                continue
            else:
                if logger:
                    logger.error("Error uploading file %s to %s at offset %d" % (fname, path, offset))
                else:
                    sys.stderr.write("Error uploading file %s to %s at offset %d\n" % (fname, path, offset))
                break
예제 #2
0
def incremental_upload(session, fname, fd, path, retries=5, logger=None):
    if not fd:
        return

    if logger is None:
        logger = logging.getLogger('koji.daemon')

    if session.opts.get('use_fast_upload'):
        fast_incremental_upload(session, fname, fd, path, retries, logger)
        return

    while True:
        offset = fd.tell()
        contents = fd.read(65536)
        size = len(contents)
        if size == 0:
            break

        data = base64.encodestring(contents)
        digest = md5_constructor(contents).hexdigest()
        del contents

        tries = 0
        while True:
            if session.uploadFile(path, fname, koji.encode_int(size), digest, koji.encode_int(offset), data):
                break

            if tries <= retries:
                tries += 1
                time.sleep(10)
                continue
            else:
                logger.error("Error uploading file %s to %s at offset %d" % (fname, path, offset))
                break
예제 #3
0
def incremental_upload(session, fname, fd, path, retries=5, logger=None):
    if not fd:
        return

    if logger is None:
        logger = logging.getLogger('koji.daemon')

    if session.opts.get('use_fast_upload'):
        fast_incremental_upload(session, fname, fd, path, retries, logger)
        return

    while True:
        offset = fd.tell()
        contents = fd.read(65536)
        size = len(contents)
        if size == 0:
            break

        data = base64.encodestring(contents)
        digest = md5_constructor(contents).hexdigest()
        del contents

        tries = 0
        while True:
            if session.uploadFile(path, fname, koji.encode_int(size), digest, koji.encode_int(offset), data):
                break

            if tries <= retries:
                tries += 1
                time.sleep(10)
                continue
            else:
                logger.error("Error uploading file %s to %s at offset %d" % (fname, path, offset))
                break
예제 #4
0
파일: daemon.py 프로젝트: msharbiani1/koji
def incremental_upload(session, fname, fd, path, retries=5, logger=None):
    if not fd:
        return

    while True:
        offset = fd.tell()
        contents = fd.read(65536)
        size = len(contents)
        if size == 0:
            break

        data = base64.encodestring(contents)
        digest = md5_constructor(contents).hexdigest()
        del contents

        tries = 0
        while True:
            if session.uploadFile(path, fname, size, digest, offset, data):
                break

            if tries <= retries:
                tries += 1
                time.sleep(10)
                continue
            else:
                if logger:
                    logger.error("Error uploading file %s to %s at offset %d" % (fname, path, offset))
                else:
                    sys.stderr.write("Error uploading file %s to %s at offset %d\n" % (fname, path, offset))
                break
예제 #5
0
파일: util.py 프로젝트: imcleod/koji
def _genToken(environ, tstamp=None):
    if 'koji.currentLogin' in environ and environ['koji.currentLogin']:
        user = environ['koji.currentLogin']
    else:
        return ''
    if tstamp == None:
        tstamp = _truncTime()
    return md5_constructor(user + str(tstamp) + environ['koji.options']['Secret'].value).hexdigest()[-8:]
예제 #6
0
파일: util.py 프로젝트: auth-scc/koji
def _genToken(req, tstamp=None):
    if hasattr(req, 'currentLogin') and req.currentLogin:
        user = req.currentLogin
    else:
        return ''
    if tstamp == None:
        tstamp = _truncTime()
    return md5_constructor(user + str(tstamp) + req.get_options()['Secret']).hexdigest()[-8:]
예제 #7
0
def _genToken(req, tstamp=None):
    if hasattr(req, 'currentLogin') and req.currentLogin:
        user = req.currentLogin
    else:
        return ''
    if tstamp == None:
        tstamp = _truncTime()
    return md5_constructor(user + str(tstamp) +
                           req.get_options()['Secret']).hexdigest()[-8:]
예제 #8
0
파일: util.py 프로젝트: solooboroten/koji
def _genToken(environ, tstamp=None):
    if 'koji.currentLogin' in environ and environ['koji.currentLogin']:
        user = environ['koji.currentLogin']
    else:
        return ''
    if tstamp == None:
        tstamp = _truncTime()
    return md5_constructor(
        user + str(tstamp) +
        environ['koji.options']['Secret'].value).hexdigest()[-8:]
예제 #9
0
def download_archive(build, archive, topurl, quiet=False, noprogress=False):
    "Wrapper around download_file, do additional checks for archive files"

    pi = koji.PathInfo(topdir=topurl)
    if archive['btype'] == 'maven':
        url = os.path.join(pi.mavenbuild(build), pi.mavenfile(archive))
        path = pi.mavenfile(archive)
    elif archive['btype'] == 'win':
        url = os.path.join(pi.winbuild(build), pi.winfile(archive))
        path = pi.winfile(archive)
    elif archive['btype'] == 'image':
        url = os.path.join(pi.imagebuild(build), archive['filename'])
        path = archive['filename']
    else:
        # non-legacy types are more systematic
        directory = pi.typedir(build, archive['btype'])
        url = os.path.join(directory, archive['filename'])
        path = archive['filename']

    download_file(url,
                  path,
                  quiet=quiet,
                  noprogress=noprogress,
                  filesize=archive['size'])

    # check size
    if os.path.getsize(path) != archive['size']:
        os.unlink(path)
        error("Downloaded rpm %s size does not match db size, deleting" % path)

    # check checksum/checksum_type
    if archive['checksum_type'] == koji.CHECKSUM_TYPES['md5']:
        hash = md5_constructor()
    elif archive['checksum_type'] == koji.CHECKSUM_TYPES['sha1']:
        hash = hashlib.sha1()  # nosec
    elif archive['checksum_type'] == koji.CHECKSUM_TYPES['sha256']:
        hash = hashlib.sha256()
    else:
        # shouldn't happen
        error("Unknown checksum type: %s" % archive['checksum_type'])
    with open(path, "rb") as f:
        while True:
            chunk = f.read(1024**2)
            hash.update(chunk)
            if not chunk:
                break
    if hash.hexdigest() != archive['checksum']:
        os.unlink(path)
        error("Downloaded archive %s doesn't match checksum, deleting" % path)