validations 0.0.3 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This script validates index files.
4
+ # There are two levels of validation:
5
+ # shallow - Tests instances for file existence and file attributes. Quick. Is a default.
6
+ # deep - In addition to shallow recalculates hash sum. Can take more time.
7
+ #
8
+ # Parameters:
9
+ # local_index - Path to index file that consists data about local files (located on the same device).
10
+ # remote_index - Path to index file that consists data about remote files.
11
+ # instance_check_level - Level of instance validation (shallow/deep), see explanations above.
12
+ #
13
+ # Currently implemented functionality:
14
+ # 1. Validation of local index file that consists content/instance data for files located on the same
15
+ # device
16
+ # Example of running:
17
+ # index_validator --local_index=$BBFS_INDEX
18
+ # index_validator --local_index=$BBFS_INDEX --instance_check_level='deep'
19
+ # 2. Validation that every content in the remote index has valid instance according to local index.
20
+ # Local instances corresponding to remote contents will be verified against file system.
21
+ # Example of running:
22
+ # index_validator --remote_index=$BACKUP/remote/master.data --local_index=$BBFS_INDEX
23
+ # index_validator --remote_index=$BACKUP/remote/master.data --local_index=$BBFS_INDEX --instance_check_level='deep'
24
+
25
+ # TODO test
26
+ # TODO help/usage should be printed on demand or when incorrectly used
27
+
28
+ require 'params'
29
+ require 'log'
30
+ require 'content_data'
31
+ require 'validations/index_validations'
32
+
33
+ Params.path('local_index', 'not set', 'Path to index file that consists data about local files (located on the same device)')
34
+ Params.path('remote_index', 'not set', 'Path to index file that consists data about remote files')
35
+
36
+ Params.init ARGV
37
+ Log.init
38
+
39
+ # TODO more easy way to define in what mode script should be run
40
+ # TODO more easy way to define whether parameter was set
41
+ def run
42
+ if File.file?(Params['remote_index']) && File.file?(Params['local_index'])
43
+ remote_index_validation
44
+ elsif File.file?(Params['local_index']) && !File.exists?(Params['remote_index'])
45
+ local_index_validation
46
+ else
47
+ err_msg = "Incorrect input: parameters missing"
48
+ puts err_msg
49
+ Log.error err_msg
50
+ wait_to_log
51
+ exit 1
52
+ end
53
+ end
54
+
55
+ def local_index_validation
56
+ index = ContentData::ContentData.new
57
+ index.from_file(Params['local_index'])
58
+
59
+ begin
60
+ if index.validate
61
+ valid_msg = "#{Params['local_index']} is valid"
62
+ Log.debug1 valid_msg
63
+ puts valid_msg
64
+ else
65
+ invalid_msg = "#{Params['local_index']} has problems.\n"\
66
+ "For more information see log #{Params['log_file_name']}"
67
+ Log.error invalid_msg
68
+ puts invalid_msg
69
+ end
70
+ rescue ArgumentError => err
71
+ puts err.message
72
+ Log.error err.message
73
+ Log.debug1 'Backtrace: '
74
+ err.backtrace.each { |a| Log.debug1 a }
75
+ wait_to_log
76
+ exit 1
77
+ end
78
+ end
79
+
80
+ def remote_index_validation
81
+ local_index = ContentData::ContentData.new
82
+ local_index.from_file(Params['local_index'])
83
+ remote_index = ContentData::ContentData.new
84
+ remote_index.from_file(Params['remote_index'])
85
+
86
+ begin
87
+ if Validations::IndexValidations.validate_remote_index remote_index, local_index
88
+ valid_msg = "All contents from #{Params['remote_index']} have valid instances on " \
89
+ "#{Params['local_index']}"
90
+ Log.debug1 valid_msg
91
+ puts valid_msg
92
+ else
93
+ invalid_msg = "#{Params['remote_index']} has contents absent or without valid instances on "\
94
+ "local index #{Params['local_index']}\n"\
95
+ "For more information see log #{Params['log_file_name']}."
96
+ Log.error invalid_msg
97
+ puts invalid_msg
98
+ end
99
+ rescue ArgumentError => err
100
+ puts err.message
101
+ Log.error err.message
102
+ Log.debug1 'Backtrace:'
103
+ err.backtrace.each { |a| Log.debug1 a }
104
+ wait_to_log
105
+ exit 1
106
+ end
107
+ end
108
+
109
+ # give a log system time to flush data
110
+ def wait_to_log
111
+ sleep(Params['log_param_max_elapsed_time_in_seconds_from_last_flush'] + 0.5)
112
+ end
113
+
114
+ # starts here
115
+ run
116
+ wait_to_log
117
+
@@ -1,3 +1,3 @@
1
1
  module Validations
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-17 00:00:00.000000000 Z
12
+ date: 2013-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: log
@@ -77,7 +77,8 @@ dependencies:
77
77
  version: '0'
78
78
  description: Used to validate ContentData objects.
79
79
  email: nukegluk@gmail.com
80
- executables: []
80
+ executables:
81
+ - index_validator
81
82
  extensions: []
82
83
  extra_rdoc_files: []
83
84
  files:
@@ -85,7 +86,8 @@ files:
85
86
  - lib/validations/index_validations.rb
86
87
  - lib/validations/version.rb
87
88
  - spec/validations/index_validations_spec.rb
88
- homepage: http://github.com/kolmanv/bbfs
89
+ - bin/index_validator
90
+ homepage: http://github.com/bbfsdev/bbfs
89
91
  licenses: []
90
92
  post_install_message:
91
93
  rdoc_options: []
@@ -105,10 +107,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
107
  version: '0'
106
108
  requirements: []
107
109
  rubyforge_project:
108
- rubygems_version: 1.8.25
110
+ rubygems_version: 1.8.24
109
111
  signing_key:
110
112
  specification_version: 3
111
113
  summary: Library for validating data.
112
114
  test_files:
113
115
  - spec/validations/index_validations_spec.rb
114
- has_rdoc: