pdfmd 1.3.2 → 1.4.0
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 +5 -13
- data/bin/pdfmd +139 -16
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ODE4Nzk2YTQ3NWE0MTQzNWRkMTYxNmI4YmRlNTUwOTk5YTAyNmQxMg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: de090beed3dac1f418ba19c76a6d2854bbd4812b
|
4
|
+
data.tar.gz: 60cdc9d02a4da98e8c86098a6db26b93a15c00e0
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NzEzN2FkYTVhZDE5ZDU3MDgyY2M3MzcxNjkwNjE5NjczZWQwY2E1ODA3ZDNi
|
11
|
-
MjhkODhlMWIyNDRhNGJkYzJlMzI0YTExYjBkZWUwZjhjYjA3ZWQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
M2U4OGNhZGEzOTIwMWY2MzM5NDNjMTEwODhkOGZhYWU1MmQ5YzU4YjhiNjRk
|
14
|
-
ZDQ2YzJhMDA0YzcxNTdmMjczNWE2MTQ4MDIxN2YzODcyNWY0ZDYyYTJiZWI3
|
15
|
-
ZDQ5Mjc2Y2MxMmNmNDc5NTMzMTBhYTIzNDcxM2I0YTg0MDM3YjU=
|
6
|
+
metadata.gz: 420de8f357b24fa83bfca65a8d973c108f38f2652c0bb1925c3098f8b72bc07066facc2f3a24bc95c392e8051c58286d917df02002d86c0a7c638389187cd7b0
|
7
|
+
data.tar.gz: 49b3cdf928a3a5728cf1fd660c10d807195990f182bc6398662295f038d5936bfeba9678890e820725fff506be4db56ed1cb91127d5b62234058f5c42ba7e3c1
|
data/bin/pdfmd
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# == Version 1.3
|
3
3
|
#
|
4
|
-
# == File:
|
4
|
+
# == File: pdfmd.rb
|
5
5
|
#
|
6
6
|
# Show and edit Metadata of PDF files and rename the files accordingly.
|
7
7
|
#
|
@@ -21,9 +21,9 @@
|
|
21
21
|
#
|
22
22
|
# === Usage
|
23
23
|
#
|
24
|
-
# $ ./
|
24
|
+
# $ ./pdfmd <action> <parameter> file
|
25
25
|
#
|
26
|
-
# $ ./
|
26
|
+
# $ ./pdfmd help <action>
|
27
27
|
#
|
28
28
|
# An overview about the actions can be seen when running the script without
|
29
29
|
# any parameters
|
@@ -62,7 +62,8 @@ require "i18n"
|
|
62
62
|
require 'pathname'
|
63
63
|
require 'logger'
|
64
64
|
|
65
|
-
VERSION = '1.
|
65
|
+
VERSION = '1.4.0'
|
66
|
+
|
66
67
|
#
|
67
68
|
# Function to read the metadata from a given file
|
68
69
|
# hash readMetadata(string)
|
@@ -98,6 +99,30 @@ def readMetadata(pathFile = false)
|
|
98
99
|
return metadata
|
99
100
|
end
|
100
101
|
|
102
|
+
|
103
|
+
#
|
104
|
+
# Query Hiera installation
|
105
|
+
# I don't give a sh** about cross platform at this point.
|
106
|
+
#
|
107
|
+
# Return the hash of the hiera values or false (if no hiera is found)
|
108
|
+
#
|
109
|
+
def queryHiera(keyword,facts = 'UNSET')
|
110
|
+
|
111
|
+
# Set default facts
|
112
|
+
facts == 'UNSET' ? facts = "fqdn=#{`hostname`}" : ''
|
113
|
+
|
114
|
+
# If hiera isn't found, return false
|
115
|
+
# otherwise return the hash
|
116
|
+
if !system('which hiera > /dev/null 2>&1')
|
117
|
+
puts 'Cannot find "hiera" command in $path.'
|
118
|
+
return false
|
119
|
+
else
|
120
|
+
return eval(`hiera #{keyword} #{facts}`)
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
|
101
126
|
#
|
102
127
|
# Set Keywords Preface based on title and subject
|
103
128
|
# If subject matches a number/character combination and contains no spaces,
|
@@ -418,6 +443,7 @@ class DOC < Thor
|
|
418
443
|
puts 'Available subjects:'
|
419
444
|
puts '- author'
|
420
445
|
puts '- createdate'
|
446
|
+
puts '- hiera'
|
421
447
|
puts '- keywords'
|
422
448
|
puts '- subject'
|
423
449
|
puts '- title'
|
@@ -449,6 +475,23 @@ class DOC < Thor
|
|
449
475
|
puts ' '
|
450
476
|
puts ' When writing Invoices with their numbers, these will be automatically be '
|
451
477
|
puts ' picked up and can be integrated in the filename, e.g. "Invoicenumber 12334'
|
478
|
+
when 'hiera'
|
479
|
+
puts 'Information about hiera: https://docs.puppetlabs.com/hiera/1/index.html'
|
480
|
+
puts ''
|
481
|
+
puts 'Installation:'
|
482
|
+
puts ' $ gem install hiera'
|
483
|
+
puts ''
|
484
|
+
puts ''
|
485
|
+
puts 'Configure default settings in hiera:'
|
486
|
+
puts ''
|
487
|
+
puts ' YAML'
|
488
|
+
puts ' ---'
|
489
|
+
puts ' pdfmd::config:'
|
490
|
+
puts ' sort:'
|
491
|
+
puts ' destination : /tmp/output'
|
492
|
+
puts ' action : copy'
|
493
|
+
puts ' logfile : /var/log/pdfmd.log'
|
494
|
+
puts ''
|
452
495
|
end
|
453
496
|
|
454
497
|
end
|
@@ -475,7 +518,9 @@ class DOC < Thor
|
|
475
518
|
[*destination|d*]
|
476
519
|
\x5 Speficy the root output directory to where the folderstructure is being created.
|
477
520
|
|
478
|
-
This parameter is required.
|
521
|
+
This parameter is required if hiera is not configured.
|
522
|
+
|
523
|
+
This parameter overwrites the hiera defaults
|
479
524
|
|
480
525
|
[*copy|c*]
|
481
526
|
\x5 Copy the files instead of moving them.
|
@@ -484,6 +529,11 @@ class DOC < Thor
|
|
484
529
|
\x5 Disable/Enable the logging.
|
485
530
|
\x5 Default: enabled.
|
486
531
|
|
532
|
+
[*interactive|i*]
|
533
|
+
\x5 Disable/Enable interactive sorting. This will ask for confirmation for
|
534
|
+
\x5 each sorting action.
|
535
|
+
\x5 Default: disabled.
|
536
|
+
|
487
537
|
=== Replacement rules
|
488
538
|
|
489
539
|
The subdirectories for the documents are generated from the values in the
|
@@ -496,6 +546,36 @@ class DOC < Thor
|
|
496
546
|
\x5 3. All letters are converted to their lowercase version.
|
497
547
|
\x5 4. Special characters are serialized
|
498
548
|
|
549
|
+
=== Hiera configuration
|
550
|
+
|
551
|
+
Set the default values mentioned below as sub-hash of the main configuration:
|
552
|
+
|
553
|
+
YAML
|
554
|
+
\x5sort:
|
555
|
+
\x5 key: value
|
556
|
+
|
557
|
+
=== Hiera defaults
|
558
|
+
|
559
|
+
The following values can be influenced by the hiera configuration in the
|
560
|
+
section 'sort'. Commandline parameter will overwrite the defaults coming
|
561
|
+
from hiera unless otherwise notet.
|
562
|
+
|
563
|
+
[*copy*]
|
564
|
+
\x5 If set to true copies the files from the source directory instead of moving them.
|
565
|
+
|
566
|
+
[*destination*]
|
567
|
+
\x5 Specifies the default output directory (root-directory). Either this or the
|
568
|
+
command line parameter for destinations must be set.
|
569
|
+
|
570
|
+
[*logfile*]
|
571
|
+
\x5 Specifies the default path for the logfile output. If this is not
|
572
|
+
specfied a logfile with the scriptname + '.log' will be created in the
|
573
|
+
current working directory.
|
574
|
+
|
575
|
+
[*interactive*]
|
576
|
+
\x5 If set to true, each file must be acknowledged to be processed when
|
577
|
+
running the script.
|
578
|
+
|
499
579
|
=== Example
|
500
580
|
|
501
581
|
This command does the following:
|
@@ -506,15 +586,51 @@ class DOC < Thor
|
|
506
586
|
\x5> CLI sort -d /tmp/test -c -l false ./documents
|
507
587
|
|
508
588
|
LONGDESC
|
509
|
-
method_option :destination, :aliases => '-d', :required =>
|
589
|
+
method_option :destination, :aliases => '-d', :required => false, :type => :string, :desc => 'Defines the output directory'
|
510
590
|
method_option :copy, :aliases => '-c', :required => false, :type => :boolean, :desc => 'Copy files instead of moving them'
|
511
|
-
method_option :log, :aliases => '-l', :
|
591
|
+
method_option :log, :aliases => '-l', :required => false, :type => :boolean, :desc => 'Enable/Disable creation of log files', :default => true
|
592
|
+
method_option :interactive, :aliases => '-i', :required => false, :type => :boolean, :desc => 'Enable/Disable interactive sort'
|
512
593
|
def sort(inputDir = '.')
|
513
594
|
|
595
|
+
hieraDefaults = queryHiera('pdfmd::config')
|
596
|
+
|
597
|
+
copyAction = options[:copy].nil? ? false : true
|
598
|
+
if options[:copy].nil? and hieraDefaults['sort']['copy'] == true
|
599
|
+
copyAction = true
|
600
|
+
puts 'Setting action to copy based on Hiera.'
|
601
|
+
end
|
602
|
+
|
603
|
+
interactiveAction = options[:interactive].nil? ? false : true
|
604
|
+
if options[:interactive].nil? and hieraDefaults['sort']['interactive'] == true
|
605
|
+
interactiveAction = true
|
606
|
+
puts 'Setting interactive to true based on Hiera.'
|
607
|
+
end
|
608
|
+
|
609
|
+
# Fetch alternate destination from hiera if available
|
514
610
|
destination = options[:destination]
|
515
|
-
|
516
|
-
|
517
|
-
|
611
|
+
if destination.nil?
|
612
|
+
|
613
|
+
hieraHash = queryHiera('pdfmd::config')
|
614
|
+
if !hieraHash['sort']['destination'].nil?
|
615
|
+
destination = hieraHash['sort']['destination']
|
616
|
+
else
|
617
|
+
puts 'No information about destination found.'
|
618
|
+
puts 'Set parameter -d or configure hiera.'
|
619
|
+
puts 'Abort.'
|
620
|
+
exit 1
|
621
|
+
end
|
622
|
+
|
623
|
+
end
|
624
|
+
|
625
|
+
logenable = options[:log]
|
626
|
+
logfile = !hieraHash['sort']['logfile'].nil? ? hieraHash['sort']['logfile'] : Dir.pwd.chomp('/') + '/' + Pathname.new(__FILE__).basename + '.log'
|
627
|
+
|
628
|
+
# Check that logfilepath exists and is writeable
|
629
|
+
if !File.writable?(logfile)
|
630
|
+
puts "Cannot write '#{logfile}. Abort."
|
631
|
+
exit 1
|
632
|
+
end
|
633
|
+
logenable ? $logger = Logger.new(logfile) : ''
|
518
634
|
|
519
635
|
# Input validation
|
520
636
|
!File.exist?(inputDir) ? abort('Input directory does not exist. Abort.'): ''
|
@@ -528,24 +644,31 @@ class DOC < Thor
|
|
528
644
|
# Iterate through all files
|
529
645
|
Dir[inputDir.chomp('/') + '/*.pdf'].sort.each do |file|
|
530
646
|
|
647
|
+
if interactiveAction
|
648
|
+
answer = readUserInput("Process '#{file}' ([y]/n): ")
|
649
|
+
answer.empty? ? 'y' : next
|
650
|
+
end
|
651
|
+
|
531
652
|
metadata = readMetadata(file)
|
532
653
|
if metadata['author'] and not metadata['author'].empty?
|
533
|
-
author
|
534
|
-
I18n.enforce_available_locales
|
535
|
-
author
|
536
|
-
folderdestination
|
654
|
+
author = metadata['author'].gsub(' ','_').gsub('.','_')
|
655
|
+
I18n.enforce_available_locales = false # Serialize special characters
|
656
|
+
author = I18n.transliterate(author).downcase
|
657
|
+
folderdestination = destination.chomp('/') + '/' + author
|
658
|
+
|
537
659
|
unless File.directory?(folderdestination)
|
538
660
|
FileUtils.mkdir_p(folderdestination)
|
539
661
|
logenable ? $logger.info("Folder '#{folderdestination}' has been created."): ''
|
540
662
|
end
|
541
|
-
|
663
|
+
|
664
|
+
filedestination = destination.chomp('/') + '/' + author + '/' + Pathname.new(file).basename.to_s
|
542
665
|
|
543
666
|
# Final check before touching the filesystem
|
544
667
|
if not File.exist?(filedestination)
|
545
668
|
$logger.info("File '#{file}' => '#{filedestination}'")
|
546
669
|
|
547
670
|
# Move/Copy the file
|
548
|
-
if
|
671
|
+
if copyAction
|
549
672
|
FileUtils.cp(file, filedestination)
|
550
673
|
else
|
551
674
|
FileUtils.mv(file,filedestination)
|
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.
|
4
|
+
version: 1.4.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-03-
|
11
|
+
date: 2015-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Managing the common pdf metadata values and renaming the pdf file accordingly.
|
14
14
|
email: pdfmd@micronarrativ.org
|
@@ -28,17 +28,17 @@ require_paths:
|
|
28
28
|
- lib
|
29
29
|
required_ruby_version: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - ">="
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '0'
|
39
39
|
requirements: []
|
40
40
|
rubyforge_project:
|
41
|
-
rubygems_version: 2.
|
41
|
+
rubygems_version: 2.0.6
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
44
|
summary: pdfmd - pdf-meta-data management
|