Class: Course::Assessment::Question::Programming::Python::PythonPackageService

Inherits:
LanguagePackageService
  • Object
show all
Defined in:
app/services/course/assessment/question/programming/python/python_package_service.rb

Instance Method Summary collapse

Instance Method Details

#extract_meta(attachment, template_files) ⇒ Object


28
29
30
31
32
33
34
35
36
# File 'app/services/course/assessment/question/programming/python/python_package_service.rb', line 28

def extract_meta(attachment, template_files)
  return @meta if @meta.present? && attachment == @attachment

  # attachment will be nil if the question is not autograded, in that case the meta data will be
  # generated from the template files in the database.
  return generate_non_autograded_meta(template_files) if attachment.nil?

  extract_autograded_meta(attachment)
end

#generate_package(old_attachment) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/course/assessment/question/programming/python/python_package_service.rb', line 13

def generate_package(old_attachment)
  return nil if @test_params.blank?

  @tmp_dir = Dir.mktmpdir
  @old_meta = old_attachment.present? ? extract_meta(old_attachment, nil) : nil
  data_files_to_keep = old_attachment.present? ? find_data_files_to_keep(old_attachment) : []
  @meta = generate_meta(data_files_to_keep)

  return nil if @meta == @old_meta

  @attachment = generate_zip_file(data_files_to_keep)
  FileUtils.remove_entry @tmp_dir if @tmp_dir.present?
  @attachment
end

#submission_templatesObject


4
5
6
7
8
9
10
11
# File 'app/services/course/assessment/question/programming/python/python_package_service.rb', line 4

def submission_templates
  [
    {
      filename: 'template.py',
      content: @test_params[:submission] || ''
    }
  ]
end