public
Fork of adamwiggins/scanty
Description: trying to turn scanty into a microblog
Homepage: http://www.least-significant-bit.com/
Clone URL: git://github.com/joahking/scanty.git
scanty / Rakefile
100644 87 lines (72 sloc) 1.991 kb
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# we are deploying with capistrano you don't need rake start/stop tasks
# for details check Capfile
#TODO remove these unneeded tasks
port = 3030
 
desc "Start the app server"
task :start => :stop do
  puts "Starting the blog"
  system "ruby main.rb -p #{port} > access.log 2>&1 &"
end
 
# code lifted from rush
def process_alive(pid)
  ::Process.kill(0, pid)
  true
rescue Errno::ESRCH
  false
end
 
def kill_process(pid)
  ::Process.kill('TERM', pid)
 
  5.times do
    return if !process_alive(pid)
    sleep 0.5
    ::Process.kill('TERM', pid) rescue nil
  end
 
  ::Process.kill('KILL', pid) rescue nil
rescue Errno::ESRCH
end
 
desc "Stop the app server"
task :stop do
  m = `netstat -lptn | grep 0.0.0.0:#{port}`.match(/LISTEN\s*(\d+)/)
  if m
    pid = m[1].to_i
    puts "Killing old server #{pid}"
    kill_process(pid)
  end
end
 
task :environment do
  require 'main'
  DB = Sequel.connect(sequel_db_uri)
end
 
task :import => :environment do
  url = ENV['URL'] or raise "No url specified, use URL="
 
  require 'rest_client'
  posts = YAML.load RestClient.get(url)
 
  posts.each do |post|
    DB[:posts] << post
  end
end
 
file 'config/config.yml' => 'config/config.yml.sample' do
  system 'cp config/config.yml.sample config/config.yml'
end
 
desc "copies the config.yml.sample to config/config.yml"
task :config => 'config/config.yml'
 
# you have dumped your feather articles to articles.yml with:
# File.open('articles.yml', 'w') do |f|
# f.puts Article.all.collect { |a|
# { :created_at => a.published_at,
# :body => a.content,
# :published => a.published,
# :title => a.title, :tags => a.tags }
# }.to_yaml
# end
# then import them
desc "import from feather posts yml, indicate yaml location with YAML=..."
task :feather => :environment do
  posts = YAML.load_file ENV['YAML']
 
  posts.each do |post|
    if post[:published]
      post.delete(:published)
      Scanty::Post.create post.merge(:slug => Scanty::Post.make_slug(post[:title]))
    end
  end
end