Source

photometry-labs / Rakefile

desc "Copy final PDFs to dist directory"
task :dist do
    HGREV = `hg tip --template "{rev}"`
    DISTDIR = 'dist'
    mkdir_p DISTDIR
    rm_f "#{DISTDIR}/*.pdf"
    FileList['*/*.pdf'].each do |f|
        cp(f, File.join(DISTDIR, "#{File.basename(f, '.pdf')}-r#{HGREV}.pdf"))
    end
end

desc "Make CSV file from raw spectrum files"
task :make_csv do
  if ENV['lab']:
    lab_no = ENV['lab']
    chdir lab_no
  else
    puts "Lab # is required"
    exit 1
  end
  SRC_DIR = "source"
  CSV_DIR = "source_csv"
  regexp = /\d{3}\.\d{6}\s+[-0-9]{1,3}\.\d+/
  mkdir_p "#{CSV_DIR}"
  FileList["#{SRC_DIR}/*"].each do |f|
    dest_f = "#{CSV_DIR}/#{File.basename(f)}.csv"
    sh "grep --color=no -P '#{regexp}' '#{f}' > '#{dest_f}'" do |ok, res|
        if ! ok
            puts "[skip] #{f}"
            rm dest_f
        end
    end
  end
end

task :default => :dist