petasos 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/petasos/location.rb +50 -41
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f8a7a7547d0f7abd9458a88a04c49a00e5b7b09a872d94727f47c39f4e9e941
4
- data.tar.gz: 0a2ae19945687b6e4ca55c898d03ce2dca5c0e6da95ec6ab1d14f78f2a8026e6
3
+ metadata.gz: b7bd8aa04cae7535d319a4b2d9141e2f40bb95b8342613541fe605022735c9b3
4
+ data.tar.gz: d418dabaf63b7a0b6b2777cd30a3a333bcbc2ee59a60cbd63ceceda9cb78485d
5
5
  SHA512:
6
- metadata.gz: 23e7481f06bebcb2835342cee3afbb5fa18e0dce5e6401b03b2965cb5898ee7e225b7002622938e9aba45919ea88d0ab4d3c1abd582c591231ee90c0d1203584
7
- data.tar.gz: 97ad57afb7f8447919379d405952c810fd04a7c480a7aa1a215adc2f83779815ef5298be5ac7b7042d2bd1f07afe1f63d3c391c5fc208de3c74abd7915abeed4
6
+ metadata.gz: 51ad7a4fb5de50153261a857597836cb302c1f6f8263ab850e25dfac91a1b3c8dab751e4222da75c597f259360d9cf7894dc9185fc7034c8046d98e0068cdccb
7
+ data.tar.gz: 7acb74142c0bf285cad8d715505fb27625dd18ec90cab3f9763c7068ca393bbbb8a01fbd840ce3070721dd323be0ead3b4a1a6fc122154924ae5df4227de3d70
@@ -13,13 +13,20 @@ class Petasos::Location
13
13
  end
14
14
 
15
15
  def run
16
- # delete exports file if completed file exists
17
- FileList.new(File.join(Dir.pwd, "exports_#{@config["name"]}*.yaml")).each do |export_file_path|
18
- completed_export_file_path = "completed-" + export_file_path
19
- `rm #{export_file_path}` if File.file?(completed_export_file_path)
20
- end
21
-
22
16
  pools.each do |pool|
17
+ # delete exports file if completed file exists
18
+ FileList.new(File.join(Dir.pwd, "exports_#{@config["name"]}_#{pool["name"]}_*.yaml")).each do |export_file_path|
19
+ completed_export_file_path = File.join(File.dirname(export_file_path), "completed-" + File.basename(export_file_path))
20
+ if File.file?(completed_export_file_path)
21
+ completed_files = YAML.load_file(completed_export_file_path)
22
+
23
+ process_lifecycle_hooks("after_export", pool, completed_files)
24
+ end
25
+ `mkdir -p logs`
26
+ `mv #{export_file_path} logs/`
27
+ `mv #{completed_export_file_path} logs/`
28
+ end
29
+
23
30
  # get all filenames in this location that belong to this pool
24
31
  current_files = current_pool_files(pool)
25
32
 
@@ -35,43 +42,43 @@ class Petasos::Location
35
42
  create_file_export_list(pool, new_files.to_a) if new_files.length > 0
36
43
  end
37
44
 
38
- # "after_seen" hooks
39
- if File.file?("petasos_after-seen.rb")
40
- require "./petasos_after-seen"
41
- # after seen for all files
42
- if defined?(after_seen_all)
43
- new_files.each do |file|
44
- after_seen_all(file)
45
- end
46
- end
45
+ process_lifecycle_hooks("after_seen", pool, new_files)
47
46
 
48
- # after seen for every file in this location
49
- location_hook = "after_seen_#{methodize(config["name"])}"
50
- if eval("defined?(#{location_hook})")
51
- new_files.each do |file|
52
- eval("#{location_hook}(\"#{file}\")")
53
- end
54
- end
47
+ # update list of seen files
48
+ # unless the location opts out
49
+ # or the pool opts out
50
+ unless config["disable_seen"] or pool["disable_seen"]
51
+ update_seen_pool_files(pool, seen_pool_files + new_files)
52
+ end
53
+ end
54
+ end
55
55
 
56
- # after seen for every file in this pool
57
- pool_hook = "after_seen_#{methodize(pool["name"])}"
58
- if eval("defined?(#{pool_hook})")
59
- new_files.each do |file|
60
- eval("#{pool_hook}(\"#{file}\")")
61
- end
62
- end
56
+ def process_lifecycle_hooks(hook_prefix, pool, files)
57
+ if File.file?("petasos_after-hooks.rb")
58
+ require "./petasos_after-hooks"
59
+ end
63
60
 
64
- # after seen for every file in this pool in this location
65
- location_and_pool_hook = "after_seen_#{methodize(config["name"])}_#{methodize(pool["name"])}"
66
- if eval("defined?(#{location_and_pool_hook})")
67
- new_files.each do |file|
68
- eval("#{location_and_pool_hook}(\"#{file}\")")
69
- end
70
- end
71
- end
61
+ # after seen for every file in this pool in this location
62
+ location_and_pool_hook = "#{hook_prefix}_#{methodize(config["name"])}_#{methodize(pool["name"])}"
63
+ check_if_defined_and_eval(location_and_pool_hook, files)
72
64
 
73
- # update list of seen files
74
- update_seen_pool_files(pool, seen_pool_files + new_files)
65
+ # after seen for every file in this pool
66
+ pool_hook = "#{hook_prefix}_#{methodize(pool["name"])}"
67
+ check_if_defined_and_eval(pool_hook, files)
68
+
69
+ # after seen for every file in this location
70
+ location_hook = "#{hook_prefix}_#{methodize(config["name"])}"
71
+ check_if_defined_and_eval(location_hook, files)
72
+
73
+ # after seen for all files
74
+ check_if_defined_and_eval("#{hook_prefix}_all", files)
75
+ end
76
+
77
+ def check_if_defined_and_eval(lifecycle_hook, files)
78
+ if eval("defined?(#{lifecycle_hook})")
79
+ files.each do |file|
80
+ eval("#{lifecycle_hook}(\"#{file}\")")
81
+ end
75
82
  end
76
83
  end
77
84
 
@@ -125,8 +132,10 @@ class Petasos::Location
125
132
 
126
133
  def initialize_all_seen_pool_files
127
134
  pools.each do |pool|
128
- yaml_path = "seen_#{config["name"]}_#{pool["name"]}.yaml"
129
- write_yaml(yaml_path, []) unless File.file?(yaml_path)
135
+ unless config["disable_seen"] or pool["disable_seen"]
136
+ yaml_path = "seen_#{config["name"]}_#{pool["name"]}.yaml"
137
+ write_yaml(yaml_path, []) unless File.file?(yaml_path)
138
+ end
130
139
  end
131
140
  end
132
141
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: petasos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Myers