Example #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
Example #2
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
Example #3
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
Example #4
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
Example #5
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
Example #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
Example #7
0
             phase=UploadedTaskDeployStatus.PHASE_MOVE_FILES,
         )
         error_status.message = msg
         error_status.save()
         return uploaded_task
 for task_image_obj in uploaded_task.images.all():
     try:
         sha1obj = sha1()
         task_image = file(task_image_obj.untarred_path, 'rb')
         chunk = task_image.read(4096)
         while len(chunk) > 0:
             sha1obj.update(chunk)
             chunk = task_image.read(4096)
         task_image.close()
         original_name, original_ext = splitext_all(
             task_image_obj.original_name
         )
         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),
         )
Example #8
0
             uploaded_task=uploaded_task,
             phase=UploadedTaskDeployStatus.PHASE_MOVE_FILES,
         )
         error_status.message = msg
         error_status.save()
         return uploaded_task
 for task_image_obj in uploaded_task.images.all():
     try:
         sha1obj = sha1()
         task_image = file(task_image_obj.untarred_path, 'rb')
         chunk = task_image.read(4096)
         while len(chunk) > 0:
             sha1obj.update(chunk)
             chunk = task_image.read(4096)
         task_image.close()
         original_name, original_ext = splitext_all(
             task_image_obj.original_name)
         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(