class ExportTasks

Public Instance Methods

package() click to toggle source
# 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
template() click to toggle source
# 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