miga-base 1.3.10.0 → 1.3.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0239e39a0588b73d042da7d970925d2d93a5334c858453e032d51b0af760fa27'
4
- data.tar.gz: 81e6903e1feba6571d76fe5d113a60414bd0d3b1b3090d6e26367a93cf8d0da7
3
+ metadata.gz: e3a7f2c88342fa48b9b5a1485c3b371bdff02e2e5bf19af7c24ab9b19b3fd373
4
+ data.tar.gz: cffaf705081cb22a9c3834e91a6ed46ccd86d138433d65a4e78269c6698f73be
5
5
  SHA512:
6
- metadata.gz: d68e55d5335f3da03eb9cea737aad5fa21a7a272e3958db6130e7260387844c1bed92b0b2f655a5a5133772797212b717559da9701723c9885cc9ee7cffc962f
7
- data.tar.gz: 8d27c2f580106c0d1f74e6daaf1cb81ffd7c6fbabf86e7569342027ff9e09b1810c245ad560eff0179c3d06a88b2d1a087344c56e34a2d54c799004e2f6370c0
6
+ metadata.gz: '093441822af4f362f210d0bbb0b4ade917757a5a5ba6938dec60038fdbdb73f75b0a479d2c930e223a54e81fce0ba9ab83b7f42ccc6a77944f33b66b53ad91a8'
7
+ data.tar.gz: 688e9925740ac96b258dd25521c5c5d63be05c2f0ebdf82a0b669bac0bd0d5c4def96537bcd4e1d411aeb03e6662b631447a5ed748c7de6c3631ea23f0d1021b
@@ -29,7 +29,7 @@ module MiGA::Cli::Action::Download::Ncbi
29
29
  opt.on(
30
30
  '--ncbi-taxonomy-dump STRING',
31
31
  'Path to an NCBI Taxonomy dump directory to query instead of API calls'
32
- ) { |v| MiGA::RemoteDataset.use_ncbi_taxonomy_dump(v) }
32
+ ) { |v| cli[:ncbi_taxonomy_dump] = v }
33
33
  end
34
34
 
35
35
  def cli_name_modifiers(opt)
@@ -55,6 +55,11 @@ module MiGA::Cli::Action::Download::Ncbi
55
55
  end
56
56
 
57
57
  def remote_list
58
+ if cli[:ncbi_taxonomy_dump]
59
+ cli.say "Reading NCBI Taxonomy dump: #{cli[:ncbi_taxonomy_dump]}"
60
+ MiGA::RemoteDataset.use_ncbi_taxonomy_dump(cli[:ncbi_taxonomy_dump])
61
+ end
62
+
58
63
  if cli[:ncbi_list_json] && File.size?(cli[:ncbi_list_json])
59
64
  cli.say "Reusing remote list: #{cli[:ncbi_list_json]}"
60
65
  return MiGA::Json.parse(cli[:ncbi_list_json])
@@ -20,7 +20,10 @@ module MiGA::Dataset::Status
20
20
  old_status = metadata[:status]
21
21
  metadata[:status] =
22
22
  !active? ? 'inactive' : done_preprocessing? ? 'complete' : 'incomplete'
23
- self.save if save && (old_status.nil? || old_status != metadata[:status])
23
+ if save && (old_status.nil? || old_status != metadata[:status])
24
+ self.save
25
+ MiGA::MiGA.DEBUG "Status changed: #{old_status} -> #{metadata[:status]}"
26
+ end
24
27
  metadata[:status].to_sym
25
28
  end
26
29
  end
data/lib/miga/dataset.rb CHANGED
@@ -61,6 +61,7 @@ class MiGA::Dataset < MiGA::MiGA
61
61
  @project, @name, @metadata = project, name, nil
62
62
  metadata[:ref] = is_ref
63
63
  metadata[:type] ||= :empty
64
+ metadata[:status] ||= 'incomplete'
64
65
  @metadata_future = [
65
66
  File.join(project.path, 'metadata', "#{name}.json"),
66
67
  metadata
@@ -84,15 +85,18 @@ class MiGA::Dataset < MiGA::MiGA
84
85
  ##
85
86
  # Save any changes you've made in the dataset
86
87
  def save
87
- MiGA.DEBUG "Dataset.metadata: #{metadata.data}"
88
+ MiGA.DEBUG "Dataset.save: #{name}"
88
89
  metadata.save
89
90
  pull_hook :on_save
90
91
  end
91
92
 
92
93
  ##
93
- # Currently +save!+ is simply an alias of +save+, for compatibility with the
94
- # +Project+ interface
95
- alias :save! :save
94
+ # Forces a save even if nothing has changed in the metadata
95
+ def save!
96
+ MiGA.DEBUG "Dataset.save!: #{name}"
97
+ metadata.save!
98
+ pull_hook :on_save
99
+ end
96
100
 
97
101
  ##
98
102
  # Delete the dataset with all it's contents (including results) and returns
@@ -148,7 +152,7 @@ class MiGA::Dataset < MiGA::MiGA
148
152
  ##
149
153
  # Is this dataset active?
150
154
  def active?
151
- metadata[:inactive].nil? or !metadata[:inactive]
155
+ metadata[:inactive].nil? || !metadata[:inactive]
152
156
  end
153
157
 
154
158
  ##
data/lib/miga/metadata.rb CHANGED
@@ -26,12 +26,17 @@ class MiGA::Metadata < MiGA::MiGA
26
26
  # Path to the JSON file describing the metadata
27
27
  attr_reader :path
28
28
 
29
+ ##
30
+ # Hash (Integer) of the last saved data Hash (object)
31
+ attr_reader :saved_hash
32
+
29
33
  ##
30
34
  # Initiate a MiGA::Metadata object with description in +path+.
31
35
  # It will create it if it doesn't exist.
32
36
  def initialize(path, defaults = {})
33
37
  @data = nil
34
38
  @path = File.absolute_path(path)
39
+ @saved_hash = nil
35
40
  unless File.exist? path
36
41
  @data = {}
37
42
  defaults.each { |k, v| self[k] = v }
@@ -57,35 +62,41 @@ class MiGA::Metadata < MiGA::MiGA
57
62
  # Save the metadata into #path
58
63
  def save
59
64
  return if self[:never_save]
65
+ return if !saved_hash.nil? && saved_hash == data.hash
60
66
 
61
67
  MiGA::MiGA.DEBUG "Metadata.save #{path}"
68
+ path_tmp = "#{path}.tmp"
62
69
  self[:updated] = Time.now.to_s
70
+ @saved_hash = data.hash
63
71
  json = to_json
64
72
  wait_for_lock
65
73
  FileUtils.touch(lock_file)
66
- ofh = File.open("#{path}.tmp", 'w')
67
- ofh.puts json
68
- ofh.close
74
+ File.open(path_tmp, 'w') { |ofh| ofh.puts json }
69
75
 
70
- unless File.exist?("#{path}.tmp") && File.exist?(lock_file)
76
+ unless File.exist?(path_tmp) && File.exist?(lock_file)
71
77
  raise "Lock-racing detected for #{path}"
72
78
  end
73
79
 
74
- File.rename("#{path}.tmp", path)
80
+ File.rename(path_tmp, path)
75
81
  File.unlink(lock_file)
76
82
  end
77
83
 
84
+ ##
85
+ # Force +save+ even if nothing has changed since the last save
86
+ # or load. However, it doesn't save if +:never_save+ is true.
87
+ def save!
88
+ @saved_hash = nil
89
+ save
90
+ end
91
+
78
92
  ##
79
93
  # (Re-)load metadata stored in #path
80
94
  def load
81
- sleeper = 0.0
82
- while File.exist? lock_file
83
- sleeper += 0.1 if sleeper <= 10.0
84
- sleep(sleeper.to_i)
85
- end
95
+ wait_for_lock
86
96
  tmp = MiGA::Json.parse(path, additions: true)
87
97
  @data = {}
88
98
  tmp.each { |k, v| self[k] = v }
99
+ @saved_hash = data.hash
89
100
  end
90
101
 
91
102
  ##
data/lib/miga/project.rb CHANGED
@@ -67,7 +67,7 @@ class MiGA::Project < MiGA::MiGA
67
67
  ##
68
68
  # Save any changes persistently, regardless of +do_not_save+
69
69
  def save!
70
- metadata.save
70
+ metadata.save!
71
71
  pull_hook :on_save
72
72
  self.load
73
73
  end
@@ -20,6 +20,7 @@ class MiGA::RemoteDataset < MiGA::MiGA
20
20
  raise "Directory doesn't exist: #{path}" unless File.directory?(path)
21
21
 
22
22
  # Structure: { TaxID => ["name", "rank", parent TaxID] }
23
+ MiGA::MiGA.DEBUG "Loading NCBI Taxonomy dump: #{path}"
23
24
  @ncbi_taxonomy_names = {}
24
25
 
25
26
  # Read names.dmp
data/lib/miga/version.rb CHANGED
@@ -12,7 +12,7 @@ module MiGA
12
12
  # - String indicating release status:
13
13
  # - rc* release candidate, not released as gem
14
14
  # - [0-9]+ stable release, released as gem
15
- VERSION = [1.3, 10, 0].freeze
15
+ VERSION = [1.3, 10, 1].freeze
16
16
 
17
17
  ##
18
18
  # Nickname for the current major.minor version.
@@ -13,7 +13,7 @@ class MetadataTest < Test::Unit::TestCase
13
13
  File.unlink(md1.lock_file)
14
14
  end
15
15
  t1 = Time.new
16
- md1.save
16
+ md1.save!
17
17
  t2 = Time.new
18
18
  assert_path_not_exist(md1.lock_file)
19
19
  assert_ge(t2 - t1, 1.0)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miga-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.10.0
4
+ version: 1.3.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis M. Rodriguez-R