Class: ExportTasks

Inherits:
Thor
  • Object
show all
Defined in:
lib/tasks/thorfile.rb

Instance Method Summary collapse

Instance Method Details

#packageObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tasks/thorfile.rb', line 42

def package
  require 'config/environment'

  package_path  = options.file || Rails.root.join('backup')
  FileUtils.mkdir_p(package_path) unless File.exist?(package_path)

  unless package_path.to_s =~ /\.zip\z/
    date      = DateTime.now.strftime("%Y-%m-%d")
    sequence  = Dir.glob(File.join(package_path, "dradis-export_#{date}_*.zip")).collect { |a| a.match(/_([0-9]+)\.zip\z/)[1].to_i }.max || 0
    package_path = File.join(package_path, "dradis-export_#{date}_#{sequence + 1}.zip")
  end

  detect_and_set_project_scope

  export_options = task_options.merge(plugin: Dradis::Plugins::Projects)
  Dradis::Plugins::Projects::Export::Package.new(export_options).
    export(filename: package_path)

  logger.info{ "Project package created at:\n\t#{ File.expand_path( package_path ) }" }
end

#templateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tasks/thorfile.rb', line 10

def template
  require 'config/environment'

  template_path = options.file || Rails.root.join('backup').to_s
  FileUtils.mkdir_p(template_path) unless File.exist?(template_path)

  unless template_path =~ /\.xml\z/
    date          = DateTime.now.strftime("%Y-%m-%d")
    sequence      = Dir.glob(File.join(template_path, "dradis-template_#{date}_*.xml")).collect do |a|
                      a.match(/_([0-9]+)\.xml\z/)[1].to_i
                    end.max || 0

    template_path = File.join(template_path, "dradis-template_#{date}_#{sequence + 1}.xml")
  end

  detect_and_set_project_scope

  exporter_class = Rails.application.config.dradis.projects.template_exporter
  export_options = task_options.merge(plugin: Dradis::Plugins::Projects)
  exporter       = exporter_class.new(export_options)

  File.open(template_path, 'w') { |f| f.write exporter.export() }

  logger.info { "Template file created at:\n\t#{ File.expand_path( template_path ) }" }
end