File: wheneverize

package info (click to toggle)
ruby-whenever 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, trixie
  • size: 328 kB
  • sloc: ruby: 2,722; makefile: 2
file content (71 lines) | stat: -rwxr-xr-x 1,638 bytes parent folder | download
1
2
3
4
5
6
7
8
9
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env ruby

# This file is based heavily on Capistrano's `capify` command

require 'optparse'
require 'fileutils'

OptionParser.new do |opts|
  opts.banner = "Usage: #{File.basename($0)} [path]"

  begin
    opts.parse!(ARGV)
  rescue OptionParser::ParseError => e
    warn e.message
    puts opts
    exit 1
  end
end

unless ARGV.empty?
  if !File.exist?(ARGV.first)
    abort "`#{ARGV.first}' does not exist."
  elsif !File.directory?(ARGV.first)
    abort "`#{ARGV.first}' is not a directory."
  elsif ARGV.length > 1
    abort "Too many arguments; please specify only the directory to wheneverize."
  end
end

content = <<-FILE
# Use this file to easily define all of your cron jobs.
#
# It's helpful, but not entirely necessary to understand cron before proceeding.
# http://en.wikipedia.org/wiki/Cron

# Example:
#
# set :output, "/path/to/my/cron_log.log"
#
# every 2.hours do
#   command "/usr/bin/some_great_command"
#   runner "MyModel.some_method"
#   rake "some:great:rake:task"
# end
#
# every 4.days do
#   runner "AnotherModel.prune_old_records"
# end

# Learn more: http://github.com/javan/whenever
FILE

file = 'config/schedule.rb'
base = ARGV.empty? ? '.' : ARGV.shift

file = File.join(base, file)
if File.exist?(file)
  warn "[skip] `#{file}' already exists"
elsif File.exist?(file.downcase)
  warn "[skip] `#{file.downcase}' exists, which could conflict with `#{file}'"
else
  dir = File.dirname(file)
  if !File.exist?(dir)
    warn "[add] creating `#{dir}'"
    FileUtils.mkdir_p(dir)
  end
  puts "[add] writing `#{file}'"
  File.open(file, "w") { |f| f.write(content) }
end

puts "[done] wheneverized!"