pdfmd 1.6.3 → 1.7.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: a468c38125c3c8666a363e93f670707f27aa7d56
4
- data.tar.gz: d73bc27bf63fedeb9f8c8ae9b4f335c8243e6283
3
+ metadata.gz: 903c39b8e2c5945304816a802bc46238d6ca26af
4
+ data.tar.gz: 2e8c939877d8208e89ea22a209b678e3424eca72
5
5
  SHA512:
6
- metadata.gz: b1250781f28ee514c561386f98e79447798d9b46ee24a57a31874c24ecce53b2da6c920455ff3bf7ebbc6166624fd0c8f82933f83ca8cf255b8cb3c663c67cdb
7
- data.tar.gz: 4eb10eec863147e23945b9fc585d94dd557e3fa522ef4c8ed50948369529e8e189860fa0a6be51670d9fe3a672bac0f2024367129986991bfc724d649ff4a849
6
+ metadata.gz: b72e6437d000b61c92fc30ce92ab4f7f6dc43b3cd0cf3601a0472db67771102811a404bb81e6b8ceb276aae251df6002bdad14848035f56caaaba2b1ce3c5623
7
+ data.tar.gz: 9a525d5c2551199d19556958c87a3ffaf46769f11658a8c93a7db409e6ff715facb11932addb9e6d362c821a3d93ccb7b361306b253c273231a865bee4b13916
@@ -1,3 +1,9 @@
1
+ # Version 1.7.0
2
+ - Rename option in command 'edit' on the Shell now overwrites the hiera setting.
3
+ - The command 'show' supports multiple output formats.
4
+ - Added hiera support for parameter 'format' and 'tag' for the command 'show'.
5
+ - Added parameter 'includepdf' with Hiera for command 'show'.
6
+
1
7
  # Version 1.6.3
2
8
  - Added hiera option 'rename' for command 'edit'
3
9
 
@@ -59,7 +59,7 @@ require "i18n"
59
59
  require 'pathname'
60
60
  require 'logger'
61
61
 
62
- VERSION = '1.6.3'
62
+ VERSION = '1.7.0'
63
63
 
64
64
  # Include general usage methods
65
65
  require_relative('pdfmd/methods.rb')
@@ -69,14 +69,13 @@ class DOC < Thor
69
69
  #
70
70
  # Show the current metadata tags
71
71
  #
72
- # TODO: format output as JSON and YAML
73
72
  # TODO: Enable additional options
74
- # TODO: Add command to show current settings (from hiera)
75
73
  #
76
74
  desc 'show', 'Show metadata of a file'
77
75
  method_option :all, :type => :boolean, :aliases => '-a', :desc => 'Show all metatags', :default => false, :required => false
78
76
  method_option :tag, :type => :string, :aliases => '-t', :desc => 'Show specific tag(s), comma separated', :required => false
79
- #method_option :format, :type => :string, :aliases => '-f', :desc => 'Define output format', :required => false
77
+ method_option :format, :type => :string, :aliases => '-f', :desc => 'Define output format', :required => false
78
+ method_option :includepdf, :type => :boolean, :aliases => '-i', :desc => 'Include the filename in output', :required => false
80
79
  long_desc <<-LONGDESC
81
80
  == General
82
81
 
@@ -97,11 +96,36 @@ class DOC < Thor
97
96
 
98
97
  Relevant tags are Author,Creator, CreateDate, Title, Subject, Keywords.
99
98
 
99
+ This is the default action.
100
+
100
101
  --tag, -t
101
102
  \x5 Specify the metatag to show. The selected metatag must be one of the relevant tags. Other tags are ignored and nothing is returned.
102
103
 
103
104
  The value for the parameter is case insensitive: 'Author' == 'author'
104
105
 
106
+ Multiple Tags can be specificed, separated by a comma.
107
+
108
+ If multiple tags are specified in a different order than the default order, the specified order will be used. This has an impact on the order of the fields when e.g. the output is exported in CSV format.
109
+
110
+ Hiera parameter: tag
111
+
112
+ --format, -f
113
+
114
+ Specify a different output format.
115
+
116
+ Available formats are json,yaml,csv,hash
117
+
118
+ The default output format is a human readable format.
119
+
120
+ Hiera parameter: format
121
+
122
+ --includepdf, -i
123
+
124
+ Include the filename of the PDF document in the output if this option is set to true.
125
+ Per default the filename is not included.
126
+
127
+ Hiera parameter: includepdf (boolean)
128
+
105
129
  == Example
106
130
 
107
131
  # Show default metatags for a pdf document
@@ -116,12 +140,24 @@ class DOC < Thor
116
140
  # Show value for metatags 'Author','Title' for the file example.pdf
117
141
  \x5>CLI show -t author,title example.pdf
118
142
 
143
+ == Hiera
144
+
145
+ Here is an example configuration for hiera:
146
+
147
+ pdfmd::config
148
+ show:
149
+ format : yaml
150
+ tag : author,subject
151
+ includepdf: true
152
+
119
153
  LONGDESC
120
154
  def show(filename)
121
155
 
122
- ENV['PDFMD_FILENAME'] = filename
123
- ENV['PDFMD_TAGS'] = options[:tag]
124
- ENV['PDFMD_ALL'] = options[:all].to_s
156
+ ENV['PDFMD_FILENAME'] = filename
157
+ ENV['PDFMD_TAGS'] = options[:tag]
158
+ ENV['PDFMD_ALL'] = options[:all].to_s
159
+ ENV['PDFMD_FORMAT'] = options[:format]
160
+ ENV['PDFMD_INCLUDEPDF'] = options[:includepdf].to_s
125
161
  require_relative('./pdfmd/show.rb')
126
162
 
127
163
  end
@@ -242,7 +278,7 @@ class DOC < Thor
242
278
 
243
279
  LONGDESC
244
280
  method_option :tag, :type => :string, :aliases => '-t', :desc => 'Name of the Tag(s) to Edit', :default => false, :required => true
245
- method_option :rename, :type => :boolean, :aliases => '-r', :desc => 'Rename file after changing meta-tags', :default => false, :required => false
281
+ method_option :rename, :type => :boolean, :aliases => '-r', :desc => 'Rename file after changing meta-tags', :required => false
246
282
  method_option :log, :aliases => '-l', :type => :boolean, :desc => 'Enable logging'
247
283
  method_option :logfile, :aliases => '-p', :type => :string, :desc => 'Define path to logfile'
248
284
  def edit(filename)
@@ -17,6 +17,8 @@ hieraDefaults = queryHiera('pdfmd::config')
17
17
  # Rename or not
18
18
  if opt_rename == 'true'
19
19
  opt_rename = true
20
+ elsif opt_rename == 'false'
21
+ opt_rename = false
20
22
  elsif (not hieraDefaults['edit'].nil? and
21
23
  not hieraDefaults['edit']['rename'].nil? and
22
24
  hieraDefaults['edit']['rename'] == true)
@@ -0,0 +1,23 @@
1
+ The CSV output formatted follows the guidelines mentioned under https://en.wikipedia.org/wiki/Comma-separated_values.
2
+
3
+ # Field Names
4
+
5
+ There is no header line defining the fields for the CSV output.
6
+
7
+ The fields are in the following order:
8
+
9
+ 1. Author
10
+ 2. Creator
11
+ 3. CreateDate
12
+ 4. Title
13
+ 5. Subject
14
+ 6. Keywords
15
+
16
+ # Quotes
17
+ Double quotes in fields like 'keywords' are replaced by double double quotes:
18
+
19
+ '"Keyword1, Keyword2"' => '""Keyword1, Keyword2""'
20
+
21
+ # Field seperator
22
+ The comma is used as a field seperator.
23
+
@@ -5,6 +5,7 @@ case term
5
5
  when ''
6
6
  puts 'Available subjects:'
7
7
  puts '- author'
8
+ puts '- csv'
8
9
  puts '- createdate'
9
10
  puts '- hiera'
10
11
  puts '- keywords'
@@ -1,24 +1,162 @@
1
- filename = ENV.fetch('PDFMD_FILENAME')
2
- optTag = ENV['PDFMD_TAGS'] || nil
3
- optAll = ENV['PDFMD_ALL'] == 'true' ? true : nil
1
+ #
2
+ # Show function of pdfmd
3
+ #
4
+ filename = ENV.fetch('PDFMD_FILENAME')
5
+ optTag = ENV['PDFMD_TAGS'] || nil
6
+ optAll = ENV['PDFMD_ALL'] == 'true' ? true : nil
7
+ opt_format = ENV['PDFMD_FORMAT']
8
+ opt_includepdf = ENV['PDFMD_INCLUDEPDF']
9
+ hieraDefaults = queryHiera('pdfmd::config')
10
+
11
+ # Determine includepdf from Hiera if possible
12
+ if not opt_includepdf.nil? and
13
+ opt_includepdf == 'true'
14
+
15
+ opt_includepdf = true
16
+
17
+ elsif opt_includepdf.nil? and
18
+ not hieraDefaults['show'].nil? and
19
+ not hieraDefaults['show']['includepdf'].nil? and
20
+ hieraDefaults['show']['includepdf'] == true
21
+
22
+ opt_includepdf = true
23
+
24
+ else
25
+
26
+ opt_includepdf = false
27
+
28
+ end
29
+
30
+ # Determine format from Hiera if possible
31
+ if opt_format.nil? and
32
+ not hieraDefaults['show'].nil? and
33
+ not hieraDefaults['show']['format'].nil? and
34
+ hieraDefaults['show']['format'] != ''
35
+
36
+ opt_format = hieraDefaults['show']['format']
37
+
38
+ end
39
+
40
+
41
+ # Determine tags from Hiera if possible
42
+ if optTag.nil? and
43
+ not hieraDefaults['show'].nil? and
44
+ not hieraDefaults['show']['tag'].nil? and
45
+ hieraDefaults['show']['tag'] != ''
46
+
47
+ optTag = hieraDefaults['show']['tag']
48
+
49
+ end
4
50
 
5
51
  metadata = readMetadata(filename)
6
52
 
7
- # Output all metatags
8
53
  if optAll or optTag.nil?
9
54
 
10
- puts "Author : " + metadata['author'].to_s
11
- puts "Creator : " + metadata['creator'].to_s
12
- puts "CreateDate : " + metadata['createdate'].to_s
13
- puts "Subject : " + metadata['subject'].to_s
14
- puts "Title : " + metadata['title'].to_s
15
- puts "Keywords : " + metadata['keywords'].to_s
16
-
17
- elsif not optTag.nil? # Output specific tag(s)
55
+ # Sort the keys in the hash in a specific order, so it becomes predictable
56
+ sortedHash = Hash.new
57
+ sortedHash['author'] = metadata['author']
58
+ sortedHash['creator'] = metadata['creator']
59
+ sortedHash['createdate'] = metadata['createdate']
60
+ sortedHash['title'] = metadata['title']
61
+ sortedHash['subject'] = metadata['subject']
62
+ sortedHash['keywords'] = metadata['keywords']
63
+ metadata = sortedHash
18
64
 
65
+ tags = metadata.keys.join(',').split(',')
66
+ else
19
67
  tags = optTag.split(',')
20
- tags.each do |tag|
21
- puts metadata[tag.downcase]
68
+ end
69
+
70
+ # Format the output according to the spefications.
71
+ # Default output is for Human readable
72
+ #
73
+ case opt_format
74
+ when /yaml/i
75
+
76
+ # Format the output as YAML
77
+
78
+ require 'yaml'
79
+ yamlData = Hash.new
80
+ tags.each do |tagname|
81
+ yamlData[tagname] = metadata[tagname.downcase]
82
+ end
83
+
84
+ # Include the filename if required
85
+ if opt_includepdf
86
+ fullHash = Hash.new
87
+ fullHash[filename] = yamlData
88
+ puts fullHash.to_yaml
89
+ else
90
+ puts yamlData.to_yaml
91
+ end
92
+
93
+ when /hash/i
94
+
95
+ # Format the output as Ruby Hash
96
+
97
+ hashData = Hash.new
98
+ tags.each do |tagname|
99
+ hashData[tagname] = metadata[tagname.downcase]
100
+ end
101
+
102
+ # Include filename if required
103
+ if opt_includepdf
104
+ fullHash = Hash.new
105
+ fullHash[filename] = hashData
106
+ puts fullHash
107
+ else
108
+ puts hashData
109
+ end
110
+
111
+ when /csv/i
112
+
113
+ # Format the output as CSV data (or what could be interpreted as something
114
+ # similar
115
+
116
+ # Format the fields as CSV
117
+ csvData = Hash.new
118
+ tags.each do |tagname|
119
+ csvData[tagname] = '"' + metadata[tagname.downcase].to_s.gsub(/"/,'""') + '"'
120
+ end
121
+
122
+ # Include the filename if required
123
+ if opt_includepdf
124
+ # Hash to array and joined to CSV compatible string
125
+ puts "\"#{filename}\"," + csvData.values.join(',')
126
+ else
127
+ # Hash to array and joined to CSV compatible string
128
+ puts csvData.values.join(',')
129
+ end
130
+
131
+
132
+ when /json/i
133
+
134
+ # Format the output as JSON
135
+
136
+ require 'json'
137
+ jsonData = Hash.new
138
+ tags.each do |tagname|
139
+ jsonData[tagname] = metadata[tagname.downcase]
140
+ end
141
+
142
+ # Include the filename if required
143
+ if opt_includepdf
144
+ fullHash = Hash.new
145
+ fullHash[filename] = jsonData
146
+ puts fullHash.to_json
147
+ else
148
+ puts jsonData.to_json
149
+ end
150
+
151
+ else
152
+
153
+ # Default output for humans to read
154
+ if opt_includepdf
155
+ puts 'File: ' + filename
156
+ end
157
+ tags.each do |key,tag|
158
+ puts key.capitalize + ': ' + metadata[key.downcase]
22
159
  end
23
160
 
24
161
  end
162
+
@@ -1,14 +1,14 @@
1
1
  # Standard Show
2
2
  # Test 001
3
3
  initTmpDir
4
- commandparameter = ' show '
4
+ commandparameter = ' show -i false --format standard --all'
5
5
  showContent = `#{PDFMD} #{commandparameter} #{TARGETPDF}`.chomp
6
- expectedContent = 'Author : Example Author
7
- Creator : Writer
8
- CreateDate : 1970:01:01 00:00:00
9
- Subject : Test Subject
10
- Title : Test Dokument
11
- Keywords : Some Keywords, Author, some feature, Customernumber 1111111, Kundenummer 1111111'
6
+ expectedContent = 'Author: Example Author
7
+ Creator: Writer
8
+ Createdate: 1970:01:01 00:00:00
9
+ Title: Test Dokument
10
+ Subject: Test Subject
11
+ Keywords: Some Keywords, Author, some feature, Customernumber 1111111, Kundenummer 1111111'
12
12
  if showContent == expectedContent
13
13
  result = 'OK'
14
14
  else
@@ -19,9 +19,9 @@ $testResults = { '001' => {:result => result, :command => commandparameter }}
19
19
  # Show single tags
20
20
  # Test 002
21
21
  initTmpDir
22
- commandparameter = ' show -t author'
22
+ commandparameter = ' show -t author --format standard'
23
23
  showContent = `#{PDFMD} #{commandparameter} #{TARGETPDF}`.chomp
24
- expectedContent = 'Example Author'
24
+ expectedContent = 'Author: Example Author'
25
25
  if showContent == expectedContent
26
26
  result = 'OK'
27
27
  else
@@ -32,10 +32,10 @@ $testResults.store('002', {:result => result, :command => commandparameter })
32
32
  # Test 003
33
33
  # Show multiple tags
34
34
  initTmpDir
35
- commandparameter = ' show -t author,subject'
35
+ commandparameter = ' show -t author,subject --format standard'
36
36
  showContent = `#{PDFMD} #{commandparameter} #{TARGETPDF}`.chomp
37
- expectedContent = 'Example Author
38
- Test Subject'
37
+ expectedContent = 'Author: Example Author
38
+ Subject: Test Subject'
39
39
  if showContent == expectedContent
40
40
  result = 'OK'
41
41
  else
@@ -43,3 +43,57 @@ else
43
43
  end
44
44
  $testResults.store('003', {:result => result, :command => commandparameter })
45
45
 
46
+ # Test 004
47
+ # Show output as YAML format
48
+ initTmpDir
49
+ commandparameter = ' show -t author,subject -f yaml'
50
+ showContent = `#{PDFMD} #{commandparameter} #{TARGETPDF}`.chomp
51
+ expectedContent = '---
52
+ author: Example Author
53
+ subject: Test Subject'
54
+ if showContent == expectedContent
55
+ result = 'OK'
56
+ else
57
+ result = 'failed'
58
+ end
59
+ $testResults.store('004', {:result => result, :command => commandparameter })
60
+
61
+ # Test 005
62
+ # Show output as JSON format
63
+ initTmpDir
64
+ commandparameter = ' show -f json -a'
65
+ showContent = `#{PDFMD} #{commandparameter} #{TARGETPDF}`.chomp
66
+ expectedContent = '{"author":"Example Author","creator":"Writer","createdate":"1970:01:01 00:00:00","title":"Test Dokument","subject":"Test Subject","keywords":"Some Keywords, Author, some feature, Customernumber 1111111, Kundenummer 1111111"}'
67
+ if showContent == expectedContent
68
+ result = 'OK'
69
+ else
70
+ result = 'failed'
71
+ end
72
+ $testResults.store('005', {:result => result, :command => commandparameter })
73
+
74
+ # Test 006
75
+ # Show output as CSV format
76
+ initTmpDir
77
+ commandparameter = ' show -t author,subject -f csv -a'
78
+ showContent = `#{PDFMD} #{commandparameter} #{TARGETPDF}`.chomp
79
+ expectedContent = '"Example Author","Writer","1970:01:01 00:00:00","Test Dokument","Test Subject","Some Keywords, Author, some feature, Customernumber 1111111, Kundenummer 1111111"'
80
+ if showContent == expectedContent
81
+ result = 'OK'
82
+ else
83
+ result = 'failed'
84
+ end
85
+ $testResults.store('006', {:result => result, :command => commandparameter })
86
+
87
+ # Test 007
88
+ # Show output as Hash format
89
+ initTmpDir
90
+ commandparameter = ' show -t author,subject -f hash -a'
91
+ showContent = `#{PDFMD} #{commandparameter} #{TARGETPDF}`.chomp
92
+ expectedContent = '{"author"=>"Example Author", "creator"=>"Writer", "createdate"=>"1970:01:01 00:00:00", "title"=>"Test Dokument", "subject"=>"Test Subject", "keywords"=>"Some Keywords, Author, some feature, Customernumber 1111111, Kundenummer 1111111"}'
93
+ if showContent == expectedContent
94
+ result = 'OK'
95
+ else
96
+ result = 'failed'
97
+ end
98
+ $testResults.store('007', {:result => result, :command => commandparameter })
99
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Roos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-17 00:00:00.000000000 Z
11
+ date: 2015-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -112,6 +112,7 @@ files:
112
112
  - lib/pdfmd/edit.rb
113
113
  - lib/pdfmd/explain.author.md
114
114
  - lib/pdfmd/explain.createdate.md
115
+ - lib/pdfmd/explain.csv.md
115
116
  - lib/pdfmd/explain.hiera.md
116
117
  - lib/pdfmd/explain.keywords.md
117
118
  - lib/pdfmd/explain.rb