示例#1
0
def untar_task(uploaded_task):
    if not uploaded_task.is_correct():
        return uploaded_task

    error_status = UploadedTaskDeployStatus(
        uploaded_task=uploaded_task,
        phase=UploadedTaskDeployStatus.PHASE_UNTAR,
    )

    uploaded_path = uploaded_task.path
    untarred_path, ext = splitext_all(uploaded_path)

    try:
        tar_file = tar_open(uploaded_task.path)
    except Exception, ex:
        error_status.message = 'Error opening tar file: %s' % str(ex)
        error_status.save()
        return uploaded_task
示例#2
0
文件: tasks.py 项目: Gfif/blackbox3
def untar_task(uploaded_task):
    if not uploaded_task.is_correct():
        return uploaded_task

    error_status = UploadedTaskDeployStatus(
        uploaded_task=uploaded_task,
        phase=UploadedTaskDeployStatus.PHASE_UNTAR,
    )

    uploaded_path = uploaded_task.path
    untarred_path, ext = splitext_all(uploaded_path)

    try:
        tar_file = tar_open(uploaded_task.path)
    except Exception, ex:
        error_status.message = 'Error opening tar file: %s' % str(ex)
        error_status.save()
        return uploaded_task
示例#3
0
def make_task(uploaded_task):

    if not uploaded_task.files_are_deployed():
        return uploaded_task

    error_status = UploadedTaskDeployStatus(
        uploaded_task=uploaded_task,
        phase=UploadedTaskDeployStatus.PHASE_MAKE_TASK,
    )

    task_json = None
    try:
        task_json_filename = path.join(uploaded_task.untarred_path, 'task',
                                       'task.json')
        task_json_file = file(task_json_filename, 'rb')
        task_json_str = task_json_file.read()
        task_json_file.close()
        task_json = json_loads(task_json_str)
    except Exception, ex:
        error_status.message = 'Error loading "task.json" file: %s' % str(ex)
        error_status.save()
        return uploaded_task
示例#4
0
文件: tasks.py 项目: Gfif/blackbox3
def make_task(uploaded_task):

    if not uploaded_task.files_are_deployed():
        return uploaded_task

    error_status = UploadedTaskDeployStatus(
        uploaded_task=uploaded_task,
        phase=UploadedTaskDeployStatus.PHASE_MAKE_TASK,
    )

    task_json = None
    try:
        task_json_filename = path.join(uploaded_task.untarred_path,
                                       'task',
                                       'task.json')
        task_json_file = file(task_json_filename, 'rb')
        task_json_str = task_json_file.read()
        task_json_file.close()
        task_json = json_loads(task_json_str)
    except Exception, ex:
        error_status.message = 'Error loading "task.json" file: %s' % str(ex)
        error_status.save()
        return uploaded_task
示例#5
0
文件: tasks.py 项目: Gfif/blackbox3
def move_files(uploaded_task):
    if not uploaded_task.is_untarred():
        return uploaded_task

    for task_file_obj in uploaded_task.files.all():
        try:
            sha1obj = sha1()
            task_file = file(task_file_obj.untarred_path, 'rb')
            chunk = task_file.read(4096)
            while len(chunk) > 0:
                sha1obj.update(chunk)
                chunk = task_file.read(4096)
            task_file.close()
            original_name, original_ext = splitext_all(
                task_file_obj.original_name
            )
            new_name = '%s_%s%s' % (
                original_name,
                sha1obj.hexdigest(),
                original_ext,
            )
            new_path = path.join(settings.UPLOADED_FILES_DIR, new_name)
            copyfile(task_file_obj.untarred_path, new_path)
            task_file_obj.relative_path = new_name
            task_file_obj.save()
        except Exception, ex:
            msg = 'Error copying file "{filename}": {reason}'.format(
                filename=task_file_obj.original_name,
                reason=str(ex),
            )
            error_status = UploadedTaskDeployStatus(
                uploaded_task=uploaded_task,
                phase=UploadedTaskDeployStatus.PHASE_MOVE_FILES,
            )
            error_status.message = msg
            error_status.save()
            return uploaded_task
示例#6
0
def move_files(uploaded_task):
    if not uploaded_task.is_untarred():
        return uploaded_task

    for task_file_obj in uploaded_task.files.all():
        try:
            sha1obj = sha1()
            task_file = file(task_file_obj.untarred_path, 'rb')
            chunk = task_file.read(4096)
            while len(chunk) > 0:
                sha1obj.update(chunk)
                chunk = task_file.read(4096)
            task_file.close()
            original_name, original_ext = splitext_all(
                task_file_obj.original_name)
            new_name = '%s_%s%s' % (
                original_name,
                sha1obj.hexdigest(),
                original_ext,
            )
            new_path = path.join(settings.UPLOADED_FILES_DIR, new_name)
            copyfile(task_file_obj.untarred_path, new_path)
            task_file_obj.relative_path = new_name
            task_file_obj.save()
        except Exception, ex:
            msg = 'Error copying file "{filename}": {reason}'.format(
                filename=task_file_obj.original_name,
                reason=str(ex),
            )
            error_status = UploadedTaskDeployStatus(
                uploaded_task=uploaded_task,
                phase=UploadedTaskDeployStatus.PHASE_MOVE_FILES,
            )
            error_status.message = msg
            error_status.save()
            return uploaded_task
示例#7
0
def format_checks(uploaded_task):
    if not uploaded_task.is_uploaded():
        return uploaded_task
    error_status = UploadedTaskDeployStatus(
        uploaded_task=uploaded_task,
        phase=UploadedTaskDeployStatus.PHASE_FORMAT_CHECK)
    untarred_path, ext = splitext_all(uploaded_task.path)
    supported_exts = ['.tar.gz', '.tar.bz2', '.tar']
    if ext not in supported_exts:
        msg = 'Unsupported format "{ext}". Should be one of {supported}.'
        msg = msg.format(ext=ext, supported=', '.join(supported_exts))
        error_status.message = msg
        error_status.save()
        return uploaded_task
    tar_file = None
    try:
        tar_file = tar_open(uploaded_task.path)
    except Exception, ex:
        error_status.message = 'Error opening tar file: %s' % str(ex)
        error_status.save()
        return uploaded_task
示例#8
0
文件: tasks.py 项目: Gfif/blackbox3
def format_checks(uploaded_task):
    if not uploaded_task.is_uploaded():
        return uploaded_task
    error_status = UploadedTaskDeployStatus(
        uploaded_task=uploaded_task,
        phase=UploadedTaskDeployStatus.PHASE_FORMAT_CHECK
    )
    untarred_path, ext = splitext_all(uploaded_task.path)
    supported_exts = ['.tar.gz', '.tar.bz2', '.tar']
    if ext not in supported_exts:
        msg = 'Unsupported format "{ext}". Should be one of {supported}.'
        msg = msg.format(ext=ext, supported=', '.join(supported_exts))
        error_status.message = msg
        error_status.save()
        return uploaded_task
    tar_file = None
    try:
        tar_file = tar_open(uploaded_task.path)
    except Exception, ex:
        error_status.message = 'Error opening tar file: %s' % str(ex)
        error_status.save()
        return uploaded_task
示例#9
0
文件: tasks.py 项目: Gfif/blackbox3
            new_name = '%s_%s%s' % (
                original_name,
                sha1obj.hexdigest(),
                original_ext,
            )
            new_path = path.join(settings.UPLOADED_IMAGES_DIR, new_name)
            copyfile(task_image_obj.untarred_path, new_path)
            task_image_obj.relative_path = new_name
            task_image_obj.save()
        except Exception, ex:
            msg = 'Error copying image file "{filename}": {reason}'.format(
                filename=task_image_obj.original_name,
                reason=str(ex),
            )
            error_status = UploadedTaskDeployStatus(
                uploaded_task=uploaded_task,
                phase=UploadedTaskDeployStatus.PHASE_MOVE_FILES,
            )
            error_status.message = msg
            error_status.save()
            return uploaded_task
    return uploaded_task


@shared_task
def email_docker_deployers(uploaded_task):
    if not uploaded_task.has_docker_images():
        return uploaded_task
    return uploaded_task


@shared_task
示例#10
0
            new_name = '%s_%s%s' % (
                original_name,
                sha1obj.hexdigest(),
                original_ext,
            )
            new_path = path.join(settings.UPLOADED_IMAGES_DIR, new_name)
            copyfile(task_image_obj.untarred_path, new_path)
            task_image_obj.relative_path = new_name
            task_image_obj.save()
        except Exception, ex:
            msg = 'Error copying image file "{filename}": {reason}'.format(
                filename=task_image_obj.original_name,
                reason=str(ex),
            )
            error_status = UploadedTaskDeployStatus(
                uploaded_task=uploaded_task,
                phase=UploadedTaskDeployStatus.PHASE_MOVE_FILES,
            )
            error_status.message = msg
            error_status.save()
            return uploaded_task
    return uploaded_task


@shared_task
def email_docker_deployers(uploaded_task):
    if not uploaded_task.has_docker_images():
        return uploaded_task
    return uploaded_task


@shared_task