cirneco 0.7.3 → 0.7.4

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: fbfad88c2c54f5051b560e08c5e4b8bf712a0ddf
4
- data.tar.gz: 6eb1e706e6fdb0315b2c1605d38da5239bcedfaf
3
+ metadata.gz: a82c5b7e10ab13eabc1913ab86f856bf1d28ee68
4
+ data.tar.gz: 38c61337cd19f6623ad835182baccaf2607f260f
5
5
  SHA512:
6
- metadata.gz: 76547c8dfa55b15f623d9bd083a3f1dabb40f41262d41943e3766ff04e7d6e1d48409cc68bc2556e60b105a61437e061890da2b61bb59dad6bd2606a073824e5
7
- data.tar.gz: 552148f8314551d7bae6bce5f35031b3708df2e3ad19c400d8ce4b8777d4e76a6c4e9ce5d94923efa212d78303922f37e6a7f1dd1a6a4c8fff4ecc9bffe008e5
6
+ metadata.gz: 2dbc92ffc86523a271cb1c69e2af2778f56bf2b0ca4c61714f3825fcbc84ee52ce7af2b42cd9edd1ead906e9a2620feda76de8dfec622698b74b2ab8a7910cf1
7
+ data.tar.gz: 00c3050b139c651521e9e1d0c0a454002f0fff2ff5f5b1a018a0e8aefcc4a258a009c2c7a03c332c1bb762dbc3176a941d8bdce961b7680a056f5c2d6b8967e1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cirneco (0.7.3)
4
+ cirneco (0.7.4)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  base32-crockford-checksum (~> 0.2.2)
7
7
  bergamasco (~> 0.3)
data/README.md CHANGED
@@ -87,9 +87,14 @@ Generate a random DOI in the format `xxxx-xxxy` where `y` is the checksum
87
87
  cirneco doi generate
88
88
  ```
89
89
 
90
+ Decode DOI
91
+ ```
92
+ cirneco doi decode 10.5072/0000-03VC
93
+ ```
94
+
90
95
  Check DOI for valid checksum
91
96
  ```
92
- cirneco doi check 10.5555/1234
97
+ cirneco doi check 10.5072/0000-03VC
93
98
  ```
94
99
 
95
100
  Mint a DOI with metadata from a markdown file with YAML frontmatter
@@ -102,6 +107,16 @@ Mint DOIs with metadata for all markdown files in a folder
102
107
  cirneco doi mint /source/posts
103
108
  ```
104
109
 
110
+ Mint a DOI and hide metadata from a markdown file with YAML frontmatter
111
+ ```
112
+ cirneco doi mint_and_hide /source/posts/cool-dois.html.md
113
+ ```
114
+
115
+ Mint DOIs and hide metadata for all markdown files in a folder
116
+ ```
117
+ cirneco doi mint_and_hide /source/posts
118
+ ```
119
+
105
120
  Hide DOI metadata for a markdown file with YAML frontmatter
106
121
  ```
107
122
  cirneco doi hide /source/posts/cool-dois.html.md
data/lib/cirneco/doi.rb CHANGED
@@ -54,6 +54,17 @@ module Cirneco
54
54
  end
55
55
  end
56
56
 
57
+ desc "decode DOI", "decode DOI encoded using Crockford base32 algorithm"
58
+ def decode(doi)
59
+ number = decode_doi(doi)
60
+
61
+ if number > 0
62
+ puts "DOI #{doi} was encoded with #{number}"
63
+ else
64
+ puts "DOI #{doi} could not be decoded"
65
+ end
66
+ end
67
+
57
68
  desc "check DOI", "check DOI using Crockford base32 checksum"
58
69
  def check(doi)
59
70
  if decode_doi(doi) > 0
@@ -63,7 +74,7 @@ module Cirneco
63
74
  end
64
75
  end
65
76
 
66
- desc "mint DOCUMENTS", "mint documents"
77
+ desc "mint DOCUMENT", "mint document"
67
78
  method_option :sitepath, :default => ENV['SITE_SITEPATH']
68
79
  method_option :authorpath, :default => ENV['SITE_AUTHORPATH']
69
80
  method_option :referencespath, :default => ENV['SITE_REFERENCESPATH']
@@ -84,7 +95,28 @@ module Cirneco
84
95
  puts response
85
96
  end
86
97
 
87
- desc "hide DOCUMENTS", "hide documents"
98
+ desc "mint and hide DOCUMENT", "mint and hide document"
99
+ method_option :sitepath, :default => ENV['SITE_SITEPATH']
100
+ method_option :authorpath, :default => ENV['SITE_AUTHORPATH']
101
+ method_option :referencespath, :default => ENV['SITE_REFERENCESPATH']
102
+ method_option :csl, :default => ENV['SITE_CSLPATH']
103
+ method_option :number, :type => :numeric, :aliases => '-n'
104
+ method_option :username, :default => ENV['MDS_USERNAME']
105
+ method_option :password, :default => ENV['MDS_PASSWORD']
106
+ method_option :prefix, :default => ENV['PREFIX']
107
+ method_option :sandbox, :type => :boolean, :force => false
108
+ def mint_and_hide(filepath)
109
+
110
+ if File.directory?(filepath)
111
+ response = mint_and_hide_dois_for_all_files(filepath, options)
112
+ else
113
+ response = mint_and_hide_doi_for_file(filepath, options)
114
+ end
115
+
116
+ puts response
117
+ end
118
+
119
+ desc "hide DOCUMENT", "hide document"
88
120
  method_option :sitepath, :default => ENV['SITE_SITEPATH']
89
121
  method_option :authorpath, :default => ENV['SITE_AUTHORPATH']
90
122
  method_option :referencespath, :default => ENV['SITE_REFERENCESPATH']
data/lib/cirneco/utils.rb CHANGED
@@ -44,6 +44,23 @@ module Cirneco
44
44
  "DOI #{new_metadata["doi"]} minted for #{filename}"
45
45
  end
46
46
 
47
+ # currently only supports markdown files with YAML header
48
+ def mint_and_hide_doi_for_file(filepath, options={})
49
+ filename = File.basename(filepath)
50
+ return "File #{filename} ignored: not a markdown file" unless File.extname(filepath) == ".md"
51
+
52
+ old_metadata = Bergamasco::Markdown.read_yaml_for_doi_metadata(filepath)
53
+ return "DOI #{old_metadata["doi"]} not changed for #{filename}" if old_metadata["doi"] && old_metadata["published"]
54
+
55
+ metadata = generate_metadata_for_work(filepath, options)
56
+ work = post_and_hide_metadata_for_work(metadata, options)
57
+
58
+ # return "Errors for DOI #{metadata["doi"]}:\n#{work.validation_errors}" if work.validation_errors.present?
59
+
60
+ new_metadata = Bergamasco::Markdown.update_file(filepath, "doi" => metadata["doi"], "published" => false)
61
+ "DOI #{new_metadata["doi"]} minted and hidden for #{filename}"
62
+ end
63
+
47
64
  # currently only supports markdown files with YAML header
48
65
  # DOIs are never deleted, but we can remove the metadata from the DataCite index
49
66
  def hide_doi_for_file(filepath, options={})
@@ -68,6 +85,12 @@ module Cirneco
68
85
  end.join("\n")
69
86
  end
70
87
 
88
+ def mint_and_hide_dois_for_all_files(folderpath, options={})
89
+ Dir.glob("#{folderpath}/*.md").map do |filepath|
90
+ mint_and_hide_doi_for_file(filepath, options)
91
+ end.join("\n")
92
+ end
93
+
71
94
  def hide_dois_for_all_files(folderpath, options={})
72
95
  Dir.glob("#{folderpath}/*.md").map do |filepath|
73
96
  hide_doi_for_file(filepath, options)
@@ -194,6 +217,19 @@ module Cirneco
194
217
  work.put_doi(metadata["doi"], options.merge(url: metadata["url"]))
195
218
  end
196
219
 
220
+ def post_and_hide_metadata_for_work(metadata, options={})
221
+ work = Cirneco::Work.new(metadata)
222
+ return work.validation_errors if work.validation_errors.present?
223
+
224
+ response = work.post_metadata(work.data, options)
225
+ return response unless response.status == 201
226
+
227
+ response = work.put_doi(metadata["doi"], options.merge(url: metadata["url"]))
228
+ return response unless response.status == 201
229
+
230
+ work.delete_metadata(metadata["doi"], options)
231
+ end
232
+
197
233
  def hide_metadata_for_work(metadata, options={})
198
234
  work = Cirneco::Work.new(metadata)
199
235
  return work.validation_errors if work.validation_errors.present?
@@ -1,3 +1,3 @@
1
1
  module Cirneco
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
3
3
  end
data/spec/doi_spec.rb CHANGED
@@ -55,6 +55,10 @@ describe Cirneco::Doi do
55
55
  expect { subject.generate }.to output("No PREFIX provided. Use --prefix option or PREFIX ENV variable\n").to_stdout
56
56
  end
57
57
 
58
+ it 'decodes a doi' do
59
+ expect { subject.decode doi }.to output("DOI #{doi} was encoded with 123\n").to_stdout
60
+ end
61
+
58
62
  it 'checks a doi' do
59
63
  expect { subject.check doi }.to output("Checksum for #{doi} is valid\n").to_stdout
60
64
  end
@@ -76,6 +80,11 @@ describe Cirneco::Doi do
76
80
  expect { subject.hide filepath }.to output("DOI 10.5072/0000-03VC hidden for #{filename}\n").to_stdout
77
81
  end
78
82
 
83
+ it 'mints and hides a doi' do
84
+ subject.options = { csl: csl, bibliography: bibliography }
85
+ expect { subject.mint_and_hide filepath }.to output("DOI 10.5072/0000-03VC minted and hidden for #{filename}\n").to_stdout
86
+ end
87
+
79
88
  it 'mints dois for contents of a folder' do
80
89
  subject.options = { csl: csl, bibliography: bibliography }
81
90
  expect { subject.mint fixture_path }.to output("DOI 10.5072/0000-03VC minted for #{filename}\n").to_stdout
@@ -86,6 +95,11 @@ describe Cirneco::Doi do
86
95
  expect { subject.hide fixture_path }.to output("DOI 10.5072/0000-03VC hidden for #{filename}\n").to_stdout
87
96
  end
88
97
 
98
+ it 'mints and hides dois for contents of a folder' do
99
+ subject.options = { csl: csl, bibliography: bibliography }
100
+ expect { subject.mint_and_hide fixture_path }.to output("DOI 10.5072/0000-03VC minted and hidden for #{filename}\n").to_stdout
101
+ end
102
+
89
103
  it 'should ignore non-markdown file for mint file' do
90
104
  filename = 'cool-dois.yml'
91
105
  expect { subject.mint fixture_path + filename }.to output("File #{filename} ignored: not a markdown file\n").to_stdout
data/spec/utils_spec.rb CHANGED
@@ -56,6 +56,13 @@ describe Cirneco::DataCenter, vcr: true, :order => :defined do
56
56
  expect(response).to eq("DOI 10.5072/0000-03VC hidden for cool-dois.html.md")
57
57
  end
58
58
 
59
+ it 'should mint and hide for file' do
60
+ filepath = fixture_path + 'cool-dois.html.md'
61
+ number = 123
62
+ response = subject.mint_and_hide_doi_for_file(filepath, number: number, csl: csl, bibliography: bibliography)
63
+ expect(response).to eq("DOI 10.5072/0000-03VC minted and hidden for cool-dois.html.md")
64
+ end
65
+
59
66
  it 'should mint for all files' do
60
67
  number = 123
61
68
  response = subject.mint_dois_for_all_files(fixture_path, number: number, csl: csl, bibliography: bibliography)
@@ -68,6 +75,12 @@ describe Cirneco::DataCenter, vcr: true, :order => :defined do
68
75
  expect(response).to eq("DOI 10.5072/0000-03VC hidden for cool-dois.html.md")
69
76
  end
70
77
 
78
+ it 'should mint and hide for all files' do
79
+ number = 123
80
+ response = subject.mint_and_hide_dois_for_all_files(fixture_path, number: number, csl: csl, bibliography: bibliography)
81
+ expect(response).to eq("DOI 10.5072/0000-03VC minted and hidden for cool-dois.html.md")
82
+ end
83
+
71
84
  it 'should ignore non-markdown file for mint file' do
72
85
  filepath = fixture_path + 'cool-dois.yml'
73
86
  response = subject.mint_doi_for_file(filepath)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cirneco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner