bibliotech 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 444a5754d4af68e747d403e3b05908eda8338bfd
4
- data.tar.gz: 6dd387a940620c2f3c509b3f5a46d39a5d928876
3
+ metadata.gz: 29396006a12015a3a5d1e6473d119743e05df2a6
4
+ data.tar.gz: 8cca90411e64dc5a4bcbf647e7a838be7ad9c4e1
5
5
  SHA512:
6
- metadata.gz: ff31dabedf2301badc381b7acae5bcab637385fd8f24c92597324fff64263a9ab68e2c4e716b110153a688ea693a6630207591561aa322964084841689e962e1
7
- data.tar.gz: c72c661fab2d7d72b62cf0b17bbb5393e5393a90d556d8462333640a42658d89d554bd62ae19441ea261134f9a8df4e294b3226a8b5a9612ec333d24805e7965
6
+ metadata.gz: bf5b1c8544ae1d3ac98a7dd67265a7ed7925b23781aa788958edd64d7c6bc19490cd015094941299f9c68a8b6d8662b7b984785946f1fa98811f0ca0bfe4cfde
7
+ data.tar.gz: 37607ddddabd0e2fc8c196b4e739d1d026c605d9741b8b8e291d20cf3e0dd3f71dc2d401345d5a8945a4b3d86859209332e4d816e11524c681355af709a1ba8a
@@ -9,7 +9,7 @@ backups:
9
9
  prefix: backup
10
10
  log:
11
11
  target: stderr
12
- level: debug
12
+ level: warn
13
13
 
14
14
  production:
15
15
  backups:
@@ -45,7 +45,7 @@ module BiblioTech
45
45
  parsed_time = Time::utc(*timespec)
46
46
  return FileRecord.new(File::join(path, file), parsed_time)
47
47
  else
48
- raise "File prefixed #{prefix} doesn't match #{prefix_timestamp_re.to_s}: #{File::join(path, file)}"
48
+ raise "File prefixed #{prefix} doesn't match #{prefix_timestamp_re.inspect}: #{File::join(path, file)}"
49
49
  end
50
50
  else
51
51
  if file !~ TIMESTAMP_REGEX
@@ -29,8 +29,23 @@ module BiblioTech
29
29
 
30
30
  def backup_needed?(time)
31
31
  most_recent = most_recent()
32
- return true if most_recent.nil?
33
- (time - most_recent.timestamp) > (frequency * 60)
32
+ log.info{ "backup_needed?: most_recent is #{most_recent.path rescue "<nil>"}" }
33
+ if most_recent.nil?
34
+ log.warn{ "backup_needed?: no backups yet -> YES" }
35
+ return true
36
+ end
37
+
38
+ difference = time - most_recent.timestamp
39
+ freq_seconds = frequency * 60
40
+ if difference >= freq_seconds
41
+ log.warn{ "backup_needed?: check time: #{time.inspect} most_recent timestamp: #{most_recent.timestamp.inspect}" }
42
+ log.warn{ "backup_needed?: delta: #{difference} frequency: #{freq_seconds} -> YES" }
43
+ return true
44
+ else
45
+ log.info{ "backup_needed?: check time: #{time.inspect} most_recent timestamp: #{most_recent.timestamp.inspect}" }
46
+ log.info{ "backup_needed?: delta: #{difference} frequency: #{freq_seconds} -> NO" }
47
+ return false
48
+ end
34
49
  end
35
50
 
36
51
  def list
@@ -59,9 +74,11 @@ module BiblioTech
59
74
  log.warn{ "No backup files in #{path} / #{name} !" }
60
75
  end
61
76
  list.each do |record|
62
- log.info{
63
- "#{record.path} #{record.timestamp} #{record.keep ? "kept: #{record.scheduled_by.inspect}" : "discarding"}"
64
- }
77
+ if record.keep
78
+ log.info{ "#{record.path} #{record.timestamp} kept: #{record.scheduled_by.inspect}" }
79
+ else
80
+ log.warn{ "#{record.path} #{record.timestamp} discarding" }
81
+ end
65
82
  end
66
83
  list.select do |record|
67
84
  !record.keep?
@@ -39,7 +39,7 @@ module BiblioTech
39
39
  attr_writer :hash
40
40
 
41
41
  def hash
42
- @hash ||= stringify_keys(valise.contents("config.yaml"))
42
+ @hash ||= stringify_keys(valise.exts(".yaml", ".yml").contents("config"))
43
43
  end
44
44
 
45
45
  def stringify_keys(hash) # sym -> string
@@ -2,8 +2,21 @@ require 'logger'
2
2
 
3
3
  module BiblioTech
4
4
  module Logging
5
+ class NullLogger < BasicObject
6
+ def method_missing(method, *args, &block)
7
+ end
8
+ end
9
+
5
10
  def self.logger
6
- return @logger
11
+ return (@logger || null_logger)
12
+ end
13
+
14
+ def self.null_logger
15
+ @null_logger ||=
16
+ begin
17
+ warn "Logging to a NullLogger (because logger didn't get set up)"
18
+ NullLogger.new
19
+ end
7
20
  end
8
21
 
9
22
  def self.logger=(value)
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'rails'
3
+ raise LoadError unless defined? Rails
4
+
5
+ module BiblioTech
6
+ class Railtie < Rails::Railtie
7
+ #XXX Consider adding Rails options for bibliotech
8
+ #Would probably need to be exclusive with config files
9
+ rake_tasks do
10
+ require 'bibliotech/rake_lib'
11
+
12
+ BiblioTech::Tasklib.new
13
+ end
14
+ end
15
+ end
16
+ rescue LoadError
17
+ end
@@ -23,10 +23,15 @@ module BiblioTech
23
23
  configured_state = to_hash
24
24
  configured_state.delete(:app)
25
25
  configured_state.delete(:config_path)
26
- case [config_path == app.config_path, configured_state == to_hash.delete(:config_path)]
27
- when [false, false]
26
+
27
+ case [config_path == app.config_path, configured_state == @default_state]
28
28
  when [true, true]
29
- raise "Cannot both change to config path and any other setting (sorry) - put configs in a file"
29
+ when [false, false]
30
+ raise "Won't both change config path and any other setting (sorry) - put configs in a file"
31
+ # The rationale here is that it would introduce two conflicting sets of
32
+ # configs, which would only enhance the level of confusion possible.
33
+ # XXX by that reasoning, if there are any non-default config files, we
34
+ # should reject Rakefile configs, but we don't
30
35
  when [true, false]
31
36
  app.config.hash.merge!(configured_state)
32
37
  when [false, true]
data/lib/bibliotech.rb CHANGED
@@ -5,3 +5,4 @@ require 'bibliotech/config'
5
5
  require 'bibliotech/command_generator'
6
6
  require 'bibliotech/command_runner'
7
7
  require 'bibliotech/compression'
8
+ require 'bibliotech/railtie' if defined?(Rails)
@@ -6,13 +6,14 @@ module BiblioTech
6
6
  describe Backups::Pruner do
7
7
  include FileSandbox
8
8
 
9
+ let :app do
10
+ App.new
11
+ end
12
+
9
13
  before :each do
10
14
  sandbox.new :directory => "db_backups"
11
15
  sandbox.new :file => '.bibliotech/config.yaml', :with_contents => "log:\n target: ../tmp/test.log"
12
- end
13
-
14
- let :app do
15
- App.new
16
+ app.log
16
17
  end
17
18
 
18
19
  let :schedule do
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rspec'
2
2
  require File.join(File.dirname(__FILE__), '..', 'lib', 'bibliotech')
3
3
 
4
+ Dir.mkdir('tmp') unless File.directory?('tmp')
4
5
  File.open('tmp/test.log', "w") do |logfile|
5
6
  logfile.truncate(0)
6
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibliotech
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Dorn
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-09 00:00:00.000000000 Z
12
+ date: 2015-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: caliph
@@ -101,6 +101,7 @@ files:
101
101
  - lib/bibliotech/backups/file_record.rb
102
102
  - lib/bibliotech/application.rb
103
103
  - lib/bibliotech/cli.rb
104
+ - lib/bibliotech/railtie.rb
104
105
  - lib/bibliotech.rb
105
106
  - bin/bibliotech
106
107
  - spec/spec_helper.rb
@@ -129,7 +130,7 @@ rdoc_options:
129
130
  - --main
130
131
  - doc/README
131
132
  - --title
132
- - bibliotech-0.3.3 Documentation
133
+ - bibliotech-0.4.0 Documentation
133
134
  require_paths:
134
135
  - lib/
135
136
  required_ruby_version: !ruby/object:Gem::Requirement