pluto-models 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +1 -14
- data/README.md +3 -55
- data/lib/pluto/connecter.rb +5 -14
- data/lib/pluto/models.rb +54 -31
- data/lib/pluto/models/feed.rb +5 -2
- data/lib/pluto/models/forward.rb +20 -0
- data/lib/pluto/models/item.rb +4 -2
- data/lib/pluto/models/site.rb +4 -2
- data/lib/pluto/models/subscription.rb +4 -2
- data/lib/pluto/models/utils.rb +4 -2
- data/lib/pluto/schema.rb +1 -0
- data/lib/pluto/version.rb +1 -1
- data/test/helper.rb +13 -0
- data/test/test_helpers.rb +18 -3
- metadata +3 -16
- data/config/pluto.index.yml +0 -23
- data/lib/pluto/fetcher.rb +0 -292
- data/lib/pluto/formatter.rb +0 -81
- data/lib/pluto/installer.rb +0 -58
- data/lib/pluto/lister.rb +0 -42
- data/lib/pluto/manifest_helpers.rb +0 -51
- data/lib/pluto/models/activity.rb +0 -8
- data/lib/pluto/refresher.rb +0 -130
- data/lib/pluto/subscriber.rb +0 -102
- data/lib/pluto/tasks/env.rake +0 -25
- data/lib/pluto/tasks/setup.rake +0 -40
- data/lib/pluto/tasks/stats.rake +0 -10
- data/lib/pluto/tasks/update.rake +0 -24
- data/lib/pluto/updater.rb +0 -50
data/lib/pluto/lister.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
module Pluto
|
2
|
-
|
3
|
-
class Lister
|
4
|
-
|
5
|
-
include LogUtils::Logging
|
6
|
-
|
7
|
-
include ManifestHelper
|
8
|
-
|
9
|
-
def initialize( opts )
|
10
|
-
@opts = opts
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :opts
|
14
|
-
|
15
|
-
def list
|
16
|
-
home = Env.home
|
17
|
-
## replace home w/ ~ (to make out more readable (shorter))
|
18
|
-
## e.g. use gsub( home, '~' )
|
19
|
-
|
20
|
-
puts ''
|
21
|
-
puts 'Installed template packs in search path'
|
22
|
-
|
23
|
-
installed_template_manifest_patterns.each_with_index do |pattern,i|
|
24
|
-
puts " [#{i+1}] #{pattern.gsub(home,'~')}"
|
25
|
-
end
|
26
|
-
puts ' include:'
|
27
|
-
|
28
|
-
manifests = installed_template_manifests
|
29
|
-
if manifests.empty?
|
30
|
-
puts " -- none --"
|
31
|
-
else
|
32
|
-
manifests.each do |manifest|
|
33
|
-
pakname = manifest[0].gsub('.txt','')
|
34
|
-
manifestpath = manifest[1].gsub(home,'~')
|
35
|
-
puts "%16s (%s)" % [pakname,manifestpath]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end # method list
|
39
|
-
|
40
|
-
end # class Lister
|
41
|
-
|
42
|
-
end # module Pluto
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module Pluto
|
2
|
-
|
3
|
-
module ManifestHelper
|
4
|
-
|
5
|
-
## shared methods for handling manifest lookups
|
6
|
-
##
|
7
|
-
# note: required attribs (in host class) include:
|
8
|
-
# - opts.config_path
|
9
|
-
|
10
|
-
def installed_template_manifest_patterns
|
11
|
-
|
12
|
-
# 1) search . # that is, working/current dir
|
13
|
-
# 2) search <config_dir>
|
14
|
-
# 3) search <gem>/templates
|
15
|
-
|
16
|
-
###
|
17
|
-
# Note
|
18
|
-
# -- for now - no longer ship w/ builtin template packs
|
19
|
-
# - download on demand if needed
|
20
|
-
|
21
|
-
builtin_patterns = [
|
22
|
-
## "#{Pluto.root}/templates/*.txt"
|
23
|
-
]
|
24
|
-
config_patterns = [
|
25
|
-
## "#{File.expand_path(opts.config_path)}/*.txt",
|
26
|
-
"#{File.expand_path(opts.config_path)}/*/*.txt"
|
27
|
-
]
|
28
|
-
current_patterns = [
|
29
|
-
## "*.txt",
|
30
|
-
"*/*.txt",
|
31
|
-
"node_modules/*/*.txt", # note: add support for npm installs - use/make slideshow required in name? for namespace in the future???
|
32
|
-
]
|
33
|
-
|
34
|
-
patterns = []
|
35
|
-
patterns += current_patterns
|
36
|
-
patterns += config_patterns
|
37
|
-
patterns += builtin_patterns
|
38
|
-
end
|
39
|
-
|
40
|
-
def installed_template_manifests
|
41
|
-
excludes = [
|
42
|
-
"Manifest.txt",
|
43
|
-
"*/Manifest.txt"
|
44
|
-
]
|
45
|
-
|
46
|
-
Pakman::Finder.new.find_manifests( installed_template_manifest_patterns, excludes )
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
end # module Manifest
|
51
|
-
end # module Slideshow
|
data/lib/pluto/refresher.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
module Pluto
|
2
|
-
|
3
|
-
class Refresher
|
4
|
-
|
5
|
-
include LogUtils::Logging
|
6
|
-
|
7
|
-
include Models
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@worker = Fetcher.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def debug=(value) @debug = value; end
|
14
|
-
def debug?() @debug || false; end
|
15
|
-
|
16
|
-
|
17
|
-
def update_sites( opts={} ) # update all site configs
|
18
|
-
if debug?
|
19
|
-
## turn on logging for sql too
|
20
|
-
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
21
|
-
@worker.debug = true # also pass along worker debug flag if set
|
22
|
-
end
|
23
|
-
|
24
|
-
# -- log update activity
|
25
|
-
Activity.create!( text: "update sites (#{Site.count})" )
|
26
|
-
|
27
|
-
#### - hack - use order(:id) instead of .all - avoids rails/activerecord 4 warnings
|
28
|
-
|
29
|
-
Site.order(:id).each do |site|
|
30
|
-
update_site_worker( site ) if site.url.present? # note: only update if (source) url present
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
def update_feeds( opts={} ) # update all feeds
|
36
|
-
if debug?
|
37
|
-
## turn on logging for sql too
|
38
|
-
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
39
|
-
@worker.debug = true # also pass along worker debug flag if set
|
40
|
-
end
|
41
|
-
|
42
|
-
# -- log update activity
|
43
|
-
Activity.create!( text: "update feeds (#{Feed.count})" )
|
44
|
-
|
45
|
-
#### - hack - use order(:id) instead of .all - avoids rails/activerecord 4 warnings
|
46
|
-
|
47
|
-
Feed.order(:id).each do |feed|
|
48
|
-
update_feed_worker( feed )
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
def update_feeds_for( site_key, opts={} )
|
54
|
-
if debug?
|
55
|
-
## turn on logging for sql too
|
56
|
-
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
57
|
-
@worker.debug = true # also pass along worker debug flag if set
|
58
|
-
end
|
59
|
-
|
60
|
-
# -- log update activity
|
61
|
-
Activity.create!( text: "update feeds >#{site_key}<" )
|
62
|
-
|
63
|
-
site = Site.find_by_key!( site_key )
|
64
|
-
|
65
|
-
site.feeds.each do |feed|
|
66
|
-
update_feed_worker( feed )
|
67
|
-
end
|
68
|
-
|
69
|
-
end # method update_feeds
|
70
|
-
|
71
|
-
|
72
|
-
private
|
73
|
-
def update_site_worker( site_rec )
|
74
|
-
site_config = @worker.site_by_rec_if_modified( site_rec )
|
75
|
-
|
76
|
-
# on error or if http-not modified etc. skip update/processing
|
77
|
-
return if site_config.nil?
|
78
|
-
|
79
|
-
subscriber = Subscriber.new
|
80
|
-
subscriber.debug = debug? ? true : false # pass along debug flag
|
81
|
-
|
82
|
-
site_key = site_rec.key
|
83
|
-
subscriber.update_subscriptions_for( site_key, site_config )
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
def update_feed_worker( feed_rec )
|
88
|
-
feed = @worker.feed_by_rec_if_modified( feed_rec )
|
89
|
-
|
90
|
-
# on error or if http-not modified etc. skip update/processing
|
91
|
-
return if feed.nil?
|
92
|
-
|
93
|
-
## fix/todo: reload feed_red - fetched date updated etc.
|
94
|
-
## check if needed for access to fetched date
|
95
|
-
|
96
|
-
|
97
|
-
## todo/check: move feed_rec update to the end (after item updates??)
|
98
|
-
|
99
|
-
# update feed attribs e.g.
|
100
|
-
# generator
|
101
|
-
# published_at,built_at,touched_at,fetched_at
|
102
|
-
# summary,title2
|
103
|
-
|
104
|
-
## fix:
|
105
|
-
## weird rss exception error on windows w/ dates
|
106
|
-
# e.g. /lib/ruby/1.9.1/rss/rss.rb:37:in `w3cdtf': wrong number of arguments (1 for 0) (ArgumentError)
|
107
|
-
#
|
108
|
-
# move to_datetime to feedutils!! if it works
|
109
|
-
## todo: move this comments to feedutils??
|
110
|
-
|
111
|
-
|
112
|
-
feed_rec.debug = debug? ? true : false # pass along debug flag
|
113
|
-
## fix/todo: pass debug flag as opts - debug: true|false !!!!!!
|
114
|
-
feed_rec.save_from_struct!( feed ) # todo: find a better name - why? why not??
|
115
|
-
|
116
|
-
|
117
|
-
# update cached value last published for item
|
118
|
-
last_item_rec = feed_rec.items.latest.limit(1).first # note limit(1) will return relation/arrar - use first to get first element or nil from ary
|
119
|
-
if last_item_rec.present?
|
120
|
-
if last_item_rec.published?
|
121
|
-
feed_rec.update_attributes!( last_published: last_item_rec.published )
|
122
|
-
else # try touched
|
123
|
-
feed_rec.update_attributes!( last_published: last_item_rec.touched )
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end # method update_feed_worker
|
127
|
-
|
128
|
-
end # class Refresher
|
129
|
-
|
130
|
-
end # module Pluto
|
data/lib/pluto/subscriber.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
module Pluto
|
2
|
-
|
3
|
-
class Subscriber
|
4
|
-
|
5
|
-
include LogUtils::Logging
|
6
|
-
|
7
|
-
include Models
|
8
|
-
|
9
|
-
def debug=(value) @debug = value; end
|
10
|
-
def debug?() @debug || false; end
|
11
|
-
|
12
|
-
|
13
|
-
def update_subscriptions( config, opts={} )
|
14
|
-
# !!!! -- depreciated API - remove - do NOT use anymore
|
15
|
-
puts "*** warn - [Pluto::Subscriber] depreciated API -- use update_subscriptions_for( site_key )"
|
16
|
-
update_subscriptions_for( 'planet', config, opts ) # default to planet site_key
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
def update_subscriptions_for( site_key, config, opts={} )
|
21
|
-
site_attribs = {
|
22
|
-
title: config['title'] || config['name'], # support either title or name
|
23
|
-
url: config['source'] || config['url'] # support source or url for source url for auto-update (optional)
|
24
|
-
}
|
25
|
-
|
26
|
-
logger.debug "site_attribs: #{site_attribs.inspect}"
|
27
|
-
|
28
|
-
site_rec = Site.find_by_key( site_key )
|
29
|
-
if site_rec.nil?
|
30
|
-
site_rec = Site.new
|
31
|
-
site_attribs[ :key ] = site_key
|
32
|
-
|
33
|
-
## use object_id: site.id and object_type: Site
|
34
|
-
## change - model/table/schema!!!
|
35
|
-
Activity.create!( text: "new site >#{site_key}< - #{site_attribs[ :title ]}" )
|
36
|
-
end
|
37
|
-
site_rec.update_attributes!( site_attribs )
|
38
|
-
|
39
|
-
# -- log update activity
|
40
|
-
Activity.create!( text: "update subscriptions >#{site_key}<" )
|
41
|
-
|
42
|
-
# clean out subscriptions and add again
|
43
|
-
logger.debug "before site.subscriptions.delete_all - count: #{site_rec.subscriptions.count}"
|
44
|
-
site_rec.subscriptions.destroy_all # note: use destroy_all NOT delete_all (delete_all tries by default only nullify)
|
45
|
-
logger.debug "after site.subscriptions.delete_all - count: #{site_rec.subscriptions.count}"
|
46
|
-
|
47
|
-
config.each do |key, value|
|
48
|
-
|
49
|
-
## todo: downcase key - why ??? why not???
|
50
|
-
|
51
|
-
# skip "top-level" feed keys e.g. title, etc. or planet planet sections (e.g. planet,defaults)
|
52
|
-
next if ['title','title2','name',
|
53
|
-
'source', 'url',
|
54
|
-
'include','includes','exclude','excludes',
|
55
|
-
'feeds',
|
56
|
-
'planet','defaults'].include?( key )
|
57
|
-
|
58
|
-
### todo/check:
|
59
|
-
## check value - must be hash
|
60
|
-
# check if url or feed_url present
|
61
|
-
# that is, check for required props/key-value pairs
|
62
|
-
|
63
|
-
feed_key = key.to_s.dup
|
64
|
-
feed_hash = value
|
65
|
-
|
66
|
-
# todo/fix: use title from feed?
|
67
|
-
# e.g. fill up auto_title, auto_url, etc.
|
68
|
-
|
69
|
-
feed_attribs = {
|
70
|
-
feed_url: feed_hash[ 'feed' ] || feed_hash[ 'feed_url' ],
|
71
|
-
url: feed_hash[ 'link' ] || feed_hash[ 'url' ],
|
72
|
-
title: feed_hash[ 'title' ] || feed_hash[ 'name' ],
|
73
|
-
title2: feed_hash[ 'title2' ],
|
74
|
-
includes: feed_hash[ 'includes' ] || feed_hash[ 'include' ],
|
75
|
-
excludes: feed_hash[ 'excludes' ] || feed_hash[ 'exclude' ]
|
76
|
-
}
|
77
|
-
|
78
|
-
puts "Updating feed subscription >#{feed_key}< - >#{feed_attribs[:feed_url]}<..."
|
79
|
-
|
80
|
-
feed_rec = Feed.find_by_key( feed_key )
|
81
|
-
if feed_rec.nil?
|
82
|
-
feed_rec = Feed.new
|
83
|
-
feed_attribs[ :key ] = feed_key
|
84
|
-
|
85
|
-
## use object_id: feed.id and object_type: Feed
|
86
|
-
## change - model/table/schema!!!
|
87
|
-
## todo: add parent_action_id - why? why not?
|
88
|
-
Activity.create!( text: "new feed >#{feed_key}< - #{feed_attribs[ :title ]}" )
|
89
|
-
end
|
90
|
-
|
91
|
-
feed_rec.update_attributes!( feed_attribs )
|
92
|
-
|
93
|
-
# add subscription record
|
94
|
-
# note: subscriptions get cleaned out on update first (see above)
|
95
|
-
site_rec.subscriptions.create!( feed_id: feed_rec.id )
|
96
|
-
end
|
97
|
-
|
98
|
-
end # method update_subscriptions
|
99
|
-
|
100
|
-
end # class Subscriber
|
101
|
-
|
102
|
-
end # module Pluto
|
data/lib/pluto/tasks/env.rake
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
task :env do
|
4
|
-
LogUtils::Logger.root.level = :debug
|
5
|
-
|
6
|
-
Pluto.connect!
|
7
|
-
end
|
8
|
-
|
9
|
-
|
10
|
-
#########
|
11
|
-
# for debugging
|
12
|
-
|
13
|
-
desc 'pluto - debug site setup'
|
14
|
-
task :site => :env do
|
15
|
-
site = Pluto::Models::Site.first # FIX: for now assume one planet per DB (fix later; allow planet key or similar)
|
16
|
-
if site.present?
|
17
|
-
puts "site found:"
|
18
|
-
pp site
|
19
|
-
else
|
20
|
-
puts "no site found"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
### todo: add new task :sites
|
25
|
-
|
data/lib/pluto/tasks/setup.rake
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
desc 'pluto -=- setup/update feed subscriptions'
|
4
|
-
task :setup => :env do
|
5
|
-
|
6
|
-
## check if PLANET key passed in
|
7
|
-
if ENV['PLANET'].present?
|
8
|
-
key = ENV['PLANET']
|
9
|
-
puts "setup planet for key >#{key}<"
|
10
|
-
else
|
11
|
-
puts 'no PLANET=key passed along; try defaults'
|
12
|
-
# try pluto.yml or planet.yml if exist
|
13
|
-
|
14
|
-
if File.exists?( './pluto.ini' ) || File.exists?( './pluto.yml' ) # check if pluto.yml exists, if yes add/use it
|
15
|
-
key ='pluto'
|
16
|
-
elsif File.exists?( './planet.ini' ) || File.exists?( './planet.yml' ) # check if planet.yml exists, if yes add/use it
|
17
|
-
key = 'planet'
|
18
|
-
else
|
19
|
-
puts '*** note: no arg passed in; no pluto.ini|yml or planet.ini|yml found in working folder'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
config_path = "./#{key}.ini"
|
25
|
-
if File.exists?( config_path )
|
26
|
-
config = INI.load_file( config_path )
|
27
|
-
else ## assume .yml
|
28
|
-
config_path = "./#{key}.yml"
|
29
|
-
config = YAML.load_file( config_path )
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
puts "dump planet setup settings >#{config_path}<:"
|
34
|
-
pp config
|
35
|
-
|
36
|
-
# note: allow multiple planets (sites) for a single install
|
37
|
-
Pluto::Subscriber.new.update_subscriptions_for( key, config )
|
38
|
-
|
39
|
-
puts 'Done.'
|
40
|
-
end
|
data/lib/pluto/tasks/stats.rake
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
desc 'pluto - show planet (feed) stats'
|
4
|
-
task :stats => :env do
|
5
|
-
puts "stats:"
|
6
|
-
puts " Feeds: #{Pluto::Models::Feed.count}"
|
7
|
-
puts " Items: #{Pluto::Models::Item.count}"
|
8
|
-
puts " Sites: #{Pluto::Models::Site.count}"
|
9
|
-
puts " Subscriptions: #{Pluto::Models::Subscription.count}"
|
10
|
-
end
|
data/lib/pluto/tasks/update.rake
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
desc 'pluto -=- update planet (site configs)'
|
4
|
-
task :update_sites => :env do
|
5
|
-
|
6
|
-
Pluto.update_sites # update all site configs if source (url) present/specified
|
7
|
-
|
8
|
-
puts 'Done (Update Sites).'
|
9
|
-
end
|
10
|
-
|
11
|
-
|
12
|
-
desc 'pluto -=- update planet (feeds)'
|
13
|
-
task :update_feeds => :env do
|
14
|
-
|
15
|
-
Pluto.update_feeds
|
16
|
-
|
17
|
-
puts 'Done (Update Feeds).'
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
desc 'pluto -=- update planet (site configs + feeds)'
|
22
|
-
task :update => [:update_sites, :update_feeds] do
|
23
|
-
puts 'Done.'
|
24
|
-
end
|
data/lib/pluto/updater.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module Pluto
|
2
|
-
|
3
|
-
class Updater
|
4
|
-
|
5
|
-
include LogUtils::Logging
|
6
|
-
|
7
|
-
### fix!!!!!: change config to text - yes/no - why? why not??
|
8
|
-
# or pass along struct
|
9
|
-
# - with hash and text and format(e.g. ini/yml) as fields???
|
10
|
-
#
|
11
|
-
# - why? - we need to get handle on md5 digest/hash plus on plain text, ideally to store in db
|
12
|
-
## - pass along unparsed text!! - not hash struct
|
13
|
-
# - will get saved in db plus we need to generate md5 hash
|
14
|
-
# - add filename e.g. ruby.ini|ruby.conf|ruby.yml as opt ??
|
15
|
-
# or add config format as opt e.g. ini or yml?
|
16
|
-
|
17
|
-
def initialize( opts, config )
|
18
|
-
@opts = opts
|
19
|
-
@config = config
|
20
|
-
end
|
21
|
-
|
22
|
-
attr_reader :opts, :config
|
23
|
-
|
24
|
-
def run( arg )
|
25
|
-
arg = arg.downcase.gsub('.ini','').gsub('.yml','') # remove file extension if present
|
26
|
-
|
27
|
-
update_for( arg )
|
28
|
-
end
|
29
|
-
|
30
|
-
def update_for( site_key )
|
31
|
-
###################
|
32
|
-
# step 1) update subscriptions
|
33
|
-
subscriber = Subscriber.new
|
34
|
-
|
35
|
-
# pass along debug/verbose setting/switch
|
36
|
-
subscriber.debug = true if opts.verbose?
|
37
|
-
subscriber.update_subscriptions_for( site_key, config )
|
38
|
-
|
39
|
-
##############################
|
40
|
-
# step 2) update feeds
|
41
|
-
refresher = Refresher.new
|
42
|
-
|
43
|
-
# pass along debug/verbose setting/switch
|
44
|
-
refresher.debug = true if opts.verbose?
|
45
|
-
refresher.update_feeds_for( site_key )
|
46
|
-
end # method run
|
47
|
-
|
48
|
-
end # class Updater
|
49
|
-
|
50
|
-
end # module Pluto
|