libis-format 1.0.2 → 2.0.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.
Files changed (236) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +5 -1
  3. data/.travis.yml +43 -25
  4. data/README.md +2 -2
  5. data/base/Dockerfile +35 -0
  6. data/base/Dockerfile.alpine +20 -0
  7. data/base/Dockerfile.rvm +56 -0
  8. data/base/rework_path +20 -0
  9. data/bin/libis_format +8 -0
  10. data/docker_cfg.yml +1 -0
  11. data/lib/libis/format.rb +12 -2
  12. data/lib/libis/format/cli/convert.rb +310 -0
  13. data/lib/libis/format/cli/format.rb +77 -0
  14. data/lib/libis/format/cli/prompt_helper.rb +87 -0
  15. data/lib/libis/format/cli/sub_command.rb +22 -0
  16. data/lib/libis/format/command_line.rb +25 -0
  17. data/lib/libis/format/config.rb +15 -10
  18. data/lib/libis/format/converter/audio_converter.rb +3 -37
  19. data/lib/libis/format/converter/base.rb +22 -8
  20. data/lib/libis/format/converter/chain.rb +3 -3
  21. data/lib/libis/format/converter/image_assembler.rb +82 -0
  22. data/lib/libis/format/converter/image_converter.rb +32 -127
  23. data/lib/libis/format/converter/image_splitter.rb +84 -0
  24. data/lib/libis/format/converter/image_watermarker.rb +261 -0
  25. data/lib/libis/format/converter/jp2_converter.rb +2 -2
  26. data/lib/libis/format/converter/office_converter.rb +2 -2
  27. data/lib/libis/format/converter/pdf_assembler.rb +66 -0
  28. data/lib/libis/format/converter/pdf_converter.rb +10 -134
  29. data/lib/libis/format/converter/pdf_metadata.rb +82 -0
  30. data/lib/libis/format/converter/pdf_optimizer.rb +67 -0
  31. data/lib/libis/format/converter/pdf_protecter.rb +147 -0
  32. data/lib/libis/format/converter/pdf_selecter.rb +77 -0
  33. data/lib/libis/format/converter/pdf_splitter.rb +70 -0
  34. data/lib/libis/format/converter/pdf_watermarker_header.rb +71 -0
  35. data/lib/libis/format/converter/pdf_watermarker_image.rb +76 -0
  36. data/lib/libis/format/converter/pdf_watermarker_text.rb +93 -0
  37. data/lib/libis/format/converter/spreadsheet_converter.rb +2 -2
  38. data/lib/libis/format/converter/video_converter.rb +1 -1
  39. data/lib/libis/format/identifier.rb +7 -7
  40. data/lib/libis/format/info.rb +27 -0
  41. data/lib/libis/format/library.rb +147 -0
  42. data/lib/libis/format/tool.rb +4 -1
  43. data/lib/libis/format/tool/droid.rb +2 -2
  44. data/lib/libis/format/tool/extension_identification.rb +4 -4
  45. data/lib/libis/format/tool/ffmpeg.rb +1 -1
  46. data/lib/libis/format/tool/fido.rb +1 -1
  47. data/lib/libis/format/tool/fop_pdf.rb +1 -1
  48. data/lib/libis/format/tool/identification_tool.rb +6 -6
  49. data/lib/libis/format/tool/office_to_pdf.rb +1 -1
  50. data/lib/libis/format/tool/pdf_merge.rb +4 -4
  51. data/lib/libis/format/tool/{pdf_copy.rb → pdf_metadata.rb} +6 -6
  52. data/lib/libis/format/tool/pdf_protect.rb +47 -0
  53. data/lib/libis/format/tool/pdf_select.rb +47 -0
  54. data/lib/libis/format/tool/pdf_split.rb +5 -5
  55. data/lib/libis/format/tool/pdf_to_pdfa.rb +1 -2
  56. data/lib/libis/format/tool/pdf_watermark.rb +47 -0
  57. data/lib/libis/format/tool/pdfa_validator.rb +3 -4
  58. data/lib/libis/format/tool/spreadsheet_to_ods.rb +2 -1
  59. data/lib/libis/format/version.rb +1 -1
  60. data/lib/libis/format/yaml_loader.rb +71 -0
  61. data/libis-format.gemspec +5 -5
  62. data/tools/PdfTool.jar +0 -0
  63. data/tools/bcpkix-jdk15on-167.jar +0 -0
  64. data/tools/bcprov-jdk15on-167.jar +0 -0
  65. data/tools/fop/build/fop.jar +0 -0
  66. data/tools/fop/conf/fop.xconf +466 -0
  67. data/tools/fop/fop +258 -0
  68. data/tools/fop/fop.bat +75 -0
  69. data/tools/fop/fop.cmd +31 -0
  70. data/tools/fop/fop.js +341 -0
  71. data/tools/fop/lib/README.txt +243 -0
  72. data/tools/fop/lib/avalon-framework-api-4.3.1.jar +0 -0
  73. data/tools/fop/lib/avalon-framework-impl-4.3.1.jar +0 -0
  74. data/tools/fop/lib/avalon-framework.LICENSE.txt +175 -0
  75. data/tools/fop/lib/avalon-framework.NOTICE.TXT +11 -0
  76. data/tools/fop/lib/batik-all-1.10.jar +0 -0
  77. data/tools/fop/lib/batik.LICENSE.txt +201 -0
  78. data/tools/fop/lib/batik.NOTICE.txt +18 -0
  79. data/tools/fop/lib/commons-io-1.3.1.jar +0 -0
  80. data/tools/fop/lib/commons-io.LICENSE.txt +203 -0
  81. data/tools/fop/lib/commons-io.NOTICE.txt +6 -0
  82. data/tools/fop/lib/commons-logging-1.0.4.jar +0 -0
  83. data/tools/fop/lib/commons-logging.LICENSE.txt +202 -0
  84. data/tools/fop/lib/commons-logging.NOTICE.txt +3 -0
  85. data/tools/fop/lib/fontbox-2.0.7.jar +0 -0
  86. data/tools/fop/lib/serializer-2.7.2.jar +0 -0
  87. data/tools/fop/lib/serializer.LICENSE.txt +201 -0
  88. data/tools/fop/lib/serializer.NOTICE.txt +15 -0
  89. data/tools/fop/lib/xalan-2.7.2.jar +0 -0
  90. data/tools/fop/lib/xalan.BCEL.LICENSE.txt +52 -0
  91. data/tools/fop/lib/xalan.LICENSE.txt +202 -0
  92. data/tools/fop/lib/xalan.NOTICE.txt +44 -0
  93. data/tools/fop/lib/xalan.regexp.LICENSE.txt +52 -0
  94. data/tools/fop/lib/xalan.runtime.LICENSE.txt +20 -0
  95. data/tools/fop/lib/xerces.LICENSE.txt +56 -0
  96. data/tools/fop/lib/xercesImpl-2.9.1.jar +0 -0
  97. data/tools/fop/lib/xercesImpl.LICENSE.txt +201 -0
  98. data/tools/fop/lib/xercesImpl.NOTICE.txt +14 -0
  99. data/tools/fop/lib/xml-apis-1.3.04.jar +0 -0
  100. data/tools/fop/lib/xml-apis-ext-1.3.04.jar +0 -0
  101. data/tools/fop/lib/xml-apis-ext.LICENSE.dom-documentation.txt +73 -0
  102. data/tools/fop/lib/xml-apis-ext.LICENSE.dom-software.txt +61 -0
  103. data/tools/fop/lib/xml-apis-ext.LICENSE.sac.html +75 -0
  104. data/tools/fop/lib/xml-apis-ext.LICENSE.txt +202 -0
  105. data/tools/fop/lib/xml-apis-ext.NOTICE.txt +16 -0
  106. data/tools/fop/lib/xml-apis-ext.README.dom.txt +56 -0
  107. data/tools/fop/lib/xml-apis.LICENSE-SAX.html +17 -0
  108. data/tools/fop/lib/xml-apis.LICENSE.DOM-documentation.html +74 -0
  109. data/tools/fop/lib/xml-apis.LICENSE.DOM-software.html +66 -0
  110. data/tools/fop/lib/xml-apis.LICENSE.txt +201 -0
  111. data/tools/fop/lib/xml-apis.NOTICE.txt +13 -0
  112. data/tools/fop/lib/xmlgraphics-commons-2.3.jar +0 -0
  113. data/tools/fop/lib/xmlgraphics-commons.LICENSE.txt +202 -0
  114. data/tools/fop/lib/xmlgraphics-commons.NOTICE.txt +5 -0
  115. data/tools/pdfbox/pdfbox-app-2.0.13.jar +0 -0
  116. data/tools/pdfbox/{pdfbox-app-1.8.10.jar → preflight-app-2.0.13.jar} +0 -0
  117. metadata +93 -259
  118. data/lib/libis/format/type_database.rb +0 -201
  119. data/spec/converter_audio_spec.rb +0 -66
  120. data/spec/converter_fop_spec.rb +0 -37
  121. data/spec/converter_image_spec.rb +0 -166
  122. data/spec/converter_office_spec.rb +0 -84
  123. data/spec/converter_pdf_spec.rb +0 -30
  124. data/spec/converter_repository_spec.rb +0 -97
  125. data/spec/converter_spreadsheet_spec.rb +0 -39
  126. data/spec/converter_video_spec.rb +0 -97
  127. data/spec/converter_xsl_spec.rb +0 -56
  128. data/spec/data/Cevennes2.bmp +0 -0
  129. data/spec/data/Cevennes2.jp2 +0 -0
  130. data/spec/data/Cevennes2.ppm +0 -22492
  131. data/spec/data/NikonRaw-CameraRaw.TIF +0 -0
  132. data/spec/data/NikonRaw-CaptureOne.tif +0 -0
  133. data/spec/data/audio/carlin_disappointed.aac +0 -0
  134. data/spec/data/audio/carlin_disappointed.ac3 +0 -0
  135. data/spec/data/audio/carlin_disappointed.aiff +0 -0
  136. data/spec/data/audio/carlin_disappointed.au +0 -0
  137. data/spec/data/audio/carlin_disappointed.flac +0 -0
  138. data/spec/data/audio/carlin_disappointed.m4a +0 -0
  139. data/spec/data/audio/carlin_disappointed.mka +0 -0
  140. data/spec/data/audio/carlin_disappointed.mp3 +0 -0
  141. data/spec/data/audio/carlin_disappointed.ogg +0 -0
  142. data/spec/data/audio/carlin_disappointed.ra +0 -0
  143. data/spec/data/audio/carlin_disappointed.voc +0 -0
  144. data/spec/data/audio/carlin_disappointed.wav +0 -0
  145. data/spec/data/audio/carlin_disappointed.wma +0 -0
  146. data/spec/data/audio/greensleeves.aac +0 -0
  147. data/spec/data/audio/greensleeves.ac3 +0 -0
  148. data/spec/data/audio/greensleeves.aiff +0 -0
  149. data/spec/data/audio/greensleeves.au +0 -0
  150. data/spec/data/audio/greensleeves.flac +0 -0
  151. data/spec/data/audio/greensleeves.m4a +0 -0
  152. data/spec/data/audio/greensleeves.mka +0 -0
  153. data/spec/data/audio/greensleeves.mp3 +0 -0
  154. data/spec/data/audio/greensleeves.ogg +0 -0
  155. data/spec/data/audio/greensleeves.ra +0 -0
  156. data/spec/data/audio/greensleeves.voc +0 -0
  157. data/spec/data/audio/greensleeves.wav +0 -0
  158. data/spec/data/audio/greensleeves.wma +0 -0
  159. data/spec/data/audio/king_nonviolence.aac +0 -0
  160. data/spec/data/audio/king_nonviolence.ac3 +0 -0
  161. data/spec/data/audio/king_nonviolence.aiff +0 -0
  162. data/spec/data/audio/king_nonviolence.au +0 -0
  163. data/spec/data/audio/king_nonviolence.flac +0 -0
  164. data/spec/data/audio/king_nonviolence.m4a +0 -0
  165. data/spec/data/audio/king_nonviolence.mka +0 -0
  166. data/spec/data/audio/king_nonviolence.mp3 +0 -0
  167. data/spec/data/audio/king_nonviolence.ogg +0 -0
  168. data/spec/data/audio/king_nonviolence.ra +0 -0
  169. data/spec/data/audio/king_nonviolence.voc +0 -0
  170. data/spec/data/audio/king_nonviolence.wav +0 -0
  171. data/spec/data/audio/king_nonviolence.wma +0 -0
  172. data/spec/data/audio/top_gun_secret.aac +0 -0
  173. data/spec/data/audio/top_gun_secret.ac3 +0 -0
  174. data/spec/data/audio/top_gun_secret.aiff +0 -0
  175. data/spec/data/audio/top_gun_secret.au +0 -0
  176. data/spec/data/audio/top_gun_secret.flac +0 -0
  177. data/spec/data/audio/top_gun_secret.m4a +0 -0
  178. data/spec/data/audio/top_gun_secret.mka +0 -0
  179. data/spec/data/audio/top_gun_secret.mp3 +0 -0
  180. data/spec/data/audio/top_gun_secret.ogg +0 -0
  181. data/spec/data/audio/top_gun_secret.ra +0 -0
  182. data/spec/data/audio/top_gun_secret.voc +0 -0
  183. data/spec/data/audio/top_gun_secret.wav +0 -0
  184. data/spec/data/audio/top_gun_secret.wma +0 -0
  185. data/spec/data/multipage.tif +0 -0
  186. data/spec/data/multipage.tif.jp2 +0 -0
  187. data/spec/data/test-ead.xml +0 -392
  188. data/spec/data/test-jpg.tif +0 -0
  189. data/spec/data/test-lzw.tif +0 -0
  190. data/spec/data/test-options.jpg +0 -0
  191. data/spec/data/test-options.png +0 -0
  192. data/spec/data/test.bmp +0 -0
  193. data/spec/data/test.doc +0 -0
  194. data/spec/data/test.docx +0 -0
  195. data/spec/data/test.gif +0 -0
  196. data/spec/data/test.jpg +0 -0
  197. data/spec/data/test.ods +0 -0
  198. data/spec/data/test.odt +0 -0
  199. data/spec/data/test.pdf +0 -0
  200. data/spec/data/test.pdf.tif +0 -0
  201. data/spec/data/test.png +0 -0
  202. data/spec/data/test.ps +0 -8631
  203. data/spec/data/test.psd +0 -0
  204. data/spec/data/test.rtf +0 -1455
  205. data/spec/data/test.tif +0 -0
  206. data/spec/data/test.txt +0 -12
  207. data/spec/data/test.xcf +0 -0
  208. data/spec/data/test.xls +0 -0
  209. data/spec/data/test.xlsx +0 -0
  210. data/spec/data/test.xml +0 -4
  211. data/spec/data/test_pdfa.pdf +0 -0
  212. data/spec/data/video/SampleVideo_1080x720_2mb.flv +0 -0
  213. data/spec/data/video/SampleVideo_1080x720_2mb.mkv +0 -0
  214. data/spec/data/video/SampleVideo_1080x720_2mb.mp4 +0 -0
  215. data/spec/data/video/SampleVideo_176x144_2mb.3gp +0 -0
  216. data/spec/data/video/SampleVideo_320x240_2mb.3gp +0 -0
  217. data/spec/data/video/SampleVideo_360x240_2mb.flv +0 -0
  218. data/spec/data/video/SampleVideo_360x240_2mb.mkv +0 -0
  219. data/spec/data/video/SampleVideo_360x240_2mb.mp4 +0 -0
  220. data/spec/data/video/copyright.png +0 -0
  221. data/spec/data/xml/134476_ead.XML +0 -1
  222. data/spec/data/xml/134476_ead.pdf +0 -0
  223. data/spec/data/xml/134476_fo.XML +0 -383
  224. data/spec/data/xml/134476_raw.XML +0 -141
  225. data/spec/data/xml/ead2fo_pdf.xsl +0 -1453
  226. data/spec/data/xml/header_nolink_pdf.xsl +0 -120
  227. data/spec/data/xml/lookupLists.xsl +0 -488
  228. data/spec/data/xml/scope_eadToHTML.xsl +0 -2376
  229. data/spec/data/xml/scope_xmlToEAD_dom.xsl +0 -952
  230. data/spec/identifier_spec.rb +0 -161
  231. data/spec/spec_helper.rb +0 -58
  232. data/spec/test_types.yml +0 -12
  233. data/spec/type_database_spec.rb +0 -140
  234. data/tools/bcpkix-jdk15on-1.49.jar +0 -0
  235. data/tools/bcprov-jdk15on-1.49.jar +0 -0
  236. data/tools/pdfbox/preflight-app-1.8.10.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 21f527308cef3b9865c24c956f5a76cf67973400
4
- data.tar.gz: 19c867aef5d28da24a3354025b11fc718b885a7f
2
+ SHA256:
3
+ metadata.gz: bfe52fc3216a0da8528941b4232c252880006137cc92fe8d42512840f5b7ab7d
4
+ data.tar.gz: 349303abd8b4d8748960713933f532bae3ca83d45613a79321269497baa6ae2a
5
5
  SHA512:
6
- metadata.gz: 3af22a3b301bc89a0839215a96a571d729478c61f3d414ee144e7f011d16443f4e604efd8f6afb0b40d2dd02dc77ca65878dfba7b29a6f4bc186beec8373b437
7
- data.tar.gz: 81bebc7836625f251e9365100bfdb4a13d3ec4424a26a536521bb1776a11d96472645af1e360077ff64d5ef4e6f08671e0c87330d8fa32f5230b390509a016ce
6
+ metadata.gz: '0917e66b03e3bf008dd3a86761f9004d93d1fbc3c02c8c692a1f6f312f25c4edc0a1536b73e4a01043b4e03c85125437ae1307c49349bdee7c46d3f5b2503231'
7
+ data.tar.gz: 29bd68dce1a8f5f2c0216299b29268d3fdcbafaed4282b7076fac4810762fb377a403dbc08dc23672a3eda4bb17cae8c8882bb24d21980396d3c2943935d1437
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /spec/work/
10
+ /spec/tmp/
10
11
  /tmp/
11
12
  *.bundle
12
13
  *.so
@@ -15,4 +16,7 @@
15
16
  mkmf.log
16
17
  /.idea/
17
18
  *.pyc
18
- tools/pdf/
19
+ tools/pdf/
20
+ /test*
21
+ /*~
22
+ /*.pdf
data/.travis.yml CHANGED
@@ -1,43 +1,61 @@
1
+ dist: bionic
1
2
  language: ruby
2
- sudo: false
3
- dist: trusty
4
3
  cache: bundler
4
+ sudo: false
5
5
  rvm:
6
- - 2.1.10
7
- - 2.2.8
8
- - 2.3.5
9
- - 2.4.2
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - 2.6
10
10
  - ruby-head
11
- - jruby-9.0.5.0
12
- - jruby-9.1.9.0
11
+ - jruby-9.1
12
+ - jruby-9.2
13
13
  - jruby-head
14
14
  jdk:
15
- - openjdk8
16
- - oraclejdk8
15
+ - openjdk10
16
+ - openjdk11
17
17
  matrix:
18
18
  exclude:
19
- - rvm: 2.1.10
20
- jdk: oraclejdk8
21
- - rvm: 2.2.8
22
- jdk: oraclejdk8
23
- - rvm: 2.3.5
24
- jdk: oraclejdk8
25
- - rvm: 2.4.2
26
- jdk: oraclejdk8
19
+ - rvm: 2.3
20
+ jdk: openjdk10
21
+ - rvm: 2.4
22
+ jdk: openjdk10
23
+ - rvm: 2.5
24
+ jdk: openjdk10
25
+ - rvm: 2.6
26
+ jdk: openjdk10
27
27
  - rvm: ruby-head
28
- jdk: oraclejdk8
28
+ jdk: openjdk10
29
29
  allow_failures:
30
30
  - rvm: ruby-head
31
31
  - rvm: jruby-head
32
32
  branches:
33
33
  only:
34
- - master
34
+ - master
35
+ - v2
35
36
  before_install:
36
- - sudo add-apt-repository ppa:mc3man/trusty-media -y
37
- - sudo apt-get update -y
38
- - sudo apt-get install -y ffmpeg gstreamer0.10-ffmpeg
39
- - sudo pip install opf-fido --upgrade --ignore-installed six
40
-
37
+ - gem update --system
38
+ - gem --version
39
+ - sudo add-apt-repository ppa:mc3man/bionic-media -y
40
+ - sudo apt-get update -y -q
41
+ - sudo apt-get install
42
+ - sudo apt-get install -y -q ffmpeg ubuntu-restricted-extras
43
+ - sudo pip install --upgrade pip
44
+ - sudo pip install --upgrade --ignore-installed opf-fido six
45
+ - sudo wget -O droid.zip -q http://www.nationalarchives.gov.uk/documents/information-management/droid-binary-6.4-bin.zip
46
+ - sudo mkdir -p /opt/droid
47
+ - sudo unzip droid.zip -d /opt/droid
48
+ - sudo chmod 755 /opt/droid/droid.sh
49
+ - sudo locale-gen "en_US.UTF-8"
50
+ - echo 'Europe/Brussels' | sudo tee /etc/timezone
51
+ - export TZ=Europe/Brussels
52
+ - sudo dpkg-reconfigure --frontend noninteractive tzdata
53
+ - date
54
+ before_script:
55
+ - export TZ=Europe/Brussels
56
+ env:
57
+ - LC_ALL=en_US.UTF-8
58
+ - LANG=en_US.UTF-8
41
59
  addons:
42
60
  apt:
43
61
  packages:
data/README.md CHANGED
@@ -26,9 +26,9 @@ Or install it yourself as:
26
26
 
27
27
  ## Usage
28
28
 
29
- ### ::Libis::Format::TypeDatabase
29
+ ### ::Libis::Format::Library
30
30
 
31
- The type database is the core of the format services. It stores information about all the known formats.
31
+ The format database is the core of the format services. It stores information about all the known formats.
32
32
 
33
33
  ### ::Libis::Format::Identifier
34
34
 
data/base/Dockerfile ADDED
@@ -0,0 +1,35 @@
1
+ FROM ubuntu:18.04
2
+ RUN apt-get -q update \
3
+ && apt-get install -q -y --no-install-recommends \
4
+ wget \
5
+ unzip \
6
+ imagemagick \
7
+ python2.7 \
8
+ python-pip \
9
+ openjdk-8-jre-headless \
10
+ libreoffice \
11
+ ghostscript
12
+
13
+ RUN apt-get clean \
14
+ && rm -rf /var/lib/apt/lists/*
15
+
16
+ RUN pip install --upgrade pip && pip install opf-fido
17
+
18
+ RUN wget -q -O droid.zip "http://www.nationalarchives.gov.uk/documents/information-management/droid-binary-6.4-bin.zip" \
19
+ && mkdir -p /opt/droid \
20
+ && unzip -d /opt/droid droid.zip \
21
+ && chmod 755 /opt/droid/droid.sh \
22
+ && rm droid.zip
23
+
24
+ RUN wget -q -O fop.tar.gz "http://www.apache.org/dyn/closer.cgi?filename=/xmlgraphics/fop/binaries/fop-2.3-bin.tar.gz&action=download" \
25
+ && mkdir -p /opt/fop \
26
+ && tar xzf fop.tar.gz -C /opt/fop --strip-components=2 \
27
+ && rm fop.tar.gz
28
+
29
+ RUN echo "8\n9\n" | apt-get install tzdata
30
+ RUN mkdir -p /teneo/format/spec
31
+ ADD ./tools /teneo/format/tools
32
+ ADD ./data /teneo/format/data
33
+ ADD ./spec/data /teneo/format/spec/data
34
+ ADD ./base/rework_path /teneo/format/rework_path
35
+ CMD /bin/bash
@@ -0,0 +1,20 @@
1
+ FROM alpine:3.8
2
+ LABEL maintainer="kris.dekeyser@libis.be"
3
+ RUN apk update -q && apk upgrade -q
4
+ RUN apk add -q python2 py-pip openjdk8-jre ffmpeg libreoffice ttf-liberation ttf-freefont ttf-opensans sox git wget unzip sudo bash curl tar imagemagick
5
+ # install fido
6
+ RUN pip install -q --upgrade pip && pip install -q opf-fido
7
+ # install droid
8
+ RUN wget -q -O droid.zip http://www.nationalarchives.gov.uk/documents/information-management/droid-binary-6.4-bin.zip \
9
+ && mkdir -p /opt/droid \
10
+ && unzip -q -d /opt/droid droid.zip \
11
+ && chmod 755 /opt/droid/droid.sh \
12
+ && rm droid.zip
13
+ # install ImageMagick
14
+ RUN apk add -q imagemagick
15
+ ADD ../tools /tools
16
+ ADD ../data /cfg
17
+ VOLUME /data
18
+ WORKDIR /data
19
+
20
+ CMD ["/bin/bash", "-l"]
@@ -0,0 +1,56 @@
1
+ ARG ubuntu_ver=latest
2
+ ARG ruby_ver=2.5.3
3
+ ARG node_ver=10.15.0
4
+
5
+ FROM ubuntu:${ubuntu_ver}
6
+ LABEL maintainer="kris.dekeyser@libis.be"
7
+
8
+ ENV RUBY_ENV=${ruby_ver}
9
+ ENV NVM_DIR=/usr/local/nvm
10
+ ENV NODE_VER=${node_ver}
11
+ ENV NODE_PATH=$NVM_DIR/v$NODE_VER/lib/node_modules
12
+ ENV NODE_PATH=$NVM_DIR/versions/node/v$NODE_VER/bin
13
+ ENV PATH "${PATH}:${NODE_PATH}:${NODE_PATH}/npm"
14
+
15
+ RUN echo $RUBY_ENV
16
+
17
+ ENV DEBIAN_FRONTEND=noninteractive
18
+ RUN apt-get update -q \
19
+ && apt-get install -y -q --no-install-recommends software-properties-common apt-utils
20
+ RUN apt-add-repository -y ppa:rael-gc/rvm \
21
+ && apt-get update -q
22
+ RUN apt-get install -y -q --no-install-recommends \
23
+ build-essential \
24
+ gnupg2 \
25
+ git \
26
+ wget \
27
+ curl \
28
+ sudo \
29
+ unzip \
30
+ openjdk-8-jre-headless
31
+
32
+ ENV BASH_ENV='/etc/profile exec bash'
33
+ SHELL ["/bin/bash", "-l", "-c"]
34
+
35
+ RUN addgroup --gid 2000 teneo \
36
+ && adduser --uid 2000 --gid 2000 --disabled-password --gecos "Teneo user" teneo \
37
+ && usermod -L -s /bin/bash teneo
38
+ RUN echo 'teneo ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers
39
+
40
+ USER teneo
41
+
42
+ RUN gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
43
+
44
+ RUN curl -sSL https://get.rvm.io | bash -s stable
45
+
46
+ RUN echo 'gem: --no-document' > ${HOME}/.gemrc
47
+ RUN echo rvm install ${ruby_ver}
48
+ RUN echo rvm use ${RUBY_ENV}@teneo --create --ruby-version --ruby-gems
49
+
50
+ # required due to bug in rubygems (https://github.com/rubygems/rubygems/issues/2483)
51
+ RUN gem install rdoc bundler
52
+ RUN gem update --no-document --system
53
+ RUN rvm info
54
+ #ADD . /home/libis/libis_format
55
+ #WORKDIR /home/libis/libis_format
56
+ #RUN bundle install && bundle exec rake spec
data/base/rework_path ADDED
@@ -0,0 +1,20 @@
1
+ #!/bin/bash
2
+
3
+ CMD=$1
4
+ shift
5
+
6
+ readarray -d ',' -t mapping <<< "$VOLUME_MAPPING"
7
+
8
+ args=("$@")
9
+ #echo "args: ${args[@]}"
10
+ for map in "${mapping[@]}"
11
+ do
12
+ map="${map//[$'\t\r\n ']}"
13
+ readarray -d '=' -t m <<< "$map"
14
+ src="${m[0]//[$'\t\r\n ']}"
15
+ tgt="${m[1]//[$'\t\r\n ']}"
16
+ # echo "$src -> $tgt"
17
+ args=("${args[@]/$src/$tgt}")
18
+ # echo "args: ${args[@]}"
19
+ done
20
+ ${CMD} "${args[@]}"
data/bin/libis_format ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+
6
+ require 'libis/format/command_line'
7
+
8
+ Libis::Format::CommandLine.start(ARGV)
data/docker_cfg.yml ADDED
@@ -0,0 +1 @@
1
+ :fop_jar: '/tools/fop.jar'
data/lib/libis/format.rb CHANGED
@@ -3,7 +3,11 @@ require 'libis/format/version'
3
3
  module Libis
4
4
  module Format
5
5
  autoload :Config, 'libis/format/config'
6
- autoload :TypeDatabase, 'libis/format/type_database'
6
+
7
+ autoload :Info, 'libis/format/info'
8
+ autoload :Library, 'libis/format/library'
9
+ autoload :YamlLoader, 'libis/format/yaml_loader'
10
+
7
11
  autoload :Identifier, 'libis/format/identifier'
8
12
 
9
13
  autoload :Tool, 'libis/format/tool'
@@ -14,4 +18,10 @@ module Libis
14
18
  TOOL_DIR = File.join(ROOT_DIR, 'tools')
15
19
 
16
20
  end
17
- end
21
+ end
22
+
23
+ class Object
24
+ def blank?
25
+ respond_to?(:empty?) ? !!empty? : !self
26
+ end unless defined? :blank?
27
+ end
@@ -0,0 +1,310 @@
1
+ require 'awesome_print'
2
+ require 'libis-format'
3
+ require 'libis-tools'
4
+ require 'libis/tools/extend/hash'
5
+ require 'fileutils'
6
+ require 'tmpdir'
7
+ require 'yaml'
8
+
9
+ require 'libis/format/converter/image_converter'
10
+
11
+ require_relative 'sub_command'
12
+
13
+ module Libis
14
+ module Format
15
+ module Cli
16
+ class Convert < SubCommand
17
+
18
+ no_commands do
19
+ def self.description(field)
20
+ "#{STRING_CONFIG[field]}." + (DEFAULT_CONFIG[field].nil? ? '' : " default: #{DEFAULT_CONFIG[field]}")
21
+ end
22
+ end
23
+
24
+ DEFAULT_CONFIG = {
25
+ scale: '100%',
26
+ resize: '100%',
27
+ wm_tiles: 4,
28
+ wm_resize: 1.0,
29
+ wm_gap: 0.2,
30
+ wm_rotation: 30,
31
+ wm_opacity: 0.1,
32
+ wm_gravity: 'center',
33
+ wm_composition: 'modulate'
34
+ }
35
+
36
+ STRING_CONFIG = {
37
+ page: 'Page number to select for multipage documents',
38
+ quiet: 'suppress all warning messages. Error messages are still reported',
39
+ scale: 'minify / magnify the image with pixel block averaging and pixel replication, respectively',
40
+ resize: 'Resize the image',
41
+ resample: 'Resize the image so that its rendered size remains the same as the original at the specified target resolution',
42
+ flatten: 'Create a canvas the size of the first images virtual canvas using the current -background color, and -compose each image in turn onto that canvas. Images falling outside that canvas is clipped',
43
+ delete_date: 'Remove modified date and created date metadata from the target image',
44
+ colorspace: 'Set the image colorspace',
45
+ profile: 'Specify color profile used for the image',
46
+ wm_text: 'Create watermark with given text',
47
+ wm_file: 'Create watermark from given file',
48
+ wm_tiles: 'Number of tiles of the watermark to distribute over the image. 0: no tiling, 1: watermark image scaled to fit image, n>1: at least n tiles horizontally/vertically, n<0: tile without recaling',
49
+ wm_resize: 'Resize the watermark image (fraction 0.0 - 1.0)',
50
+ wm_gap: 'Leave n % of whitespace between the watermark images. Similar effect can be achieved with wm_resize',
51
+ wm_rotation: 'Rotate the watermark text n degrees counterclockwise (0-360)',
52
+ wm_opacity: 'Opacity of the watermark (fraction 0.0 - 1.0)',
53
+ wm_gravity: 'Center point of the watermark overlay',
54
+ wm_composition: 'Set the type of image composition'
55
+ }
56
+
57
+ desc 'auto SOURCE TARGET [options]', 'Convert SOURCE file to TARGET file using auto algorithm'
58
+ long_desc <<-DESC
59
+
60
+ 'auto SOURCE TARGET [options]' will convert a file according to the best conversion chain algorithm.
61
+
62
+ A source file name and target file name should be supplied. The source file should exist and be readable.
63
+ The target file should be writable, but should not exist.
64
+
65
+ Optionally an options file name can be added to the command line. The options file should be a valid YAML
66
+ file that contains either a Hash or an Array of Hashes. The content should contain the required methods and
67
+ arguments that any of the targetted converters support.
68
+
69
+ The source file's format will be identified by the Libis::Format::Identifier and the target file's format
70
+ will be derived from the file's extension. The Libis::Format::Library is used to relate extensions
71
+ with formats.
72
+
73
+ DESC
74
+
75
+ method_option :options, aliases: '-o', desc: 'Options file'
76
+
77
+ def auto(source_file, target_file)
78
+ options_file = options[:options]
79
+ opts = check_input(source_file, target_file, options_file)
80
+ output, converter = do_convert(source_file, target_file, opts)
81
+ prompt.ok "Output file '#{output}' created with converter #{converter}."
82
+ end
83
+
84
+ desc 'image SOURCE TARGET [options]', 'Convert SOURCE image to TARGET image using ImageConverter'
85
+ long_desc <<-DESC
86
+
87
+ 'image SOURCE TARGET [options]' will convert a SOURCE image to TARGET image using the ImageConverter.
88
+
89
+ A source file name and target file name should be supplied. The source file should exist and be readable.
90
+ The target file should be writable, but should not exist.
91
+
92
+ The target file's format will be derived from the file's extension. The Libis::Format::Library is used
93
+ to relate extensions with formats.
94
+
95
+ DESC
96
+
97
+ method_option :page, type: :numeric, aliases: '-p', desc: description(:page)
98
+ method_option :quiet, type: :boolean, aliases: '-q', desc: description(:quiet)
99
+ method_option :scale, type: :numeric, aliases: '-c', desc: description(:scale)
100
+ method_option :resize, type: :numeric, aliases: '-r', desc: description(:resize)
101
+ method_option :resample, type: :numeric, aliases: '-m', desc: description(:resample)
102
+ method_option :flatten, type: :boolean, aliases: '-f', desc: description(:flatten)
103
+ method_option :delete_date, type: :boolean, aliases: '-dd', desc: description(:delete_date)
104
+ method_option :colorspace, aliases: '-cs', desc: description(:colorspace)
105
+ method_option :profile, aliases: '-prof', desc: description(:profile)
106
+ method_option :wm_text, desc: description(:wm_text)
107
+ method_option :wm_file, desc: description(:wm_file)
108
+ method_option :wm_tiles, type: :numeric, desc: description(:wm_tiles)
109
+ method_option :wm_resize, type: :numeric, desc: description(:wm_resize)
110
+ method_option :wm_gap, type: :numeric, desc: description(:wm_gap)
111
+ method_option :wm_rotation, type: :numeric, desc: description(:wm_rotation)
112
+ method_option :wm_opacity, type: :numeric, desc: description(:wm_opacity)
113
+ method_option :wm_gravity, desc: description(:wm_gravity)
114
+ method_option :wm_composition, desc: description(:wm_composition)
115
+
116
+ def image(source_file, target_file)
117
+ check_input(source_file, target_file)
118
+ convert_image(source_file, target_file)
119
+ prompt.ok "Output file '#{target_file}' created with image converter."
120
+ end
121
+
122
+ protected
123
+
124
+ def do_convert(source_file, target_file, opts)
125
+ format_info = format_identifier(source_file)
126
+ src_mime = format_info[:mimetype]
127
+ source_format = format_info[:TYPE]
128
+ unless source_format
129
+ prompt.error "File item %s format (#{src_mime}) is not supported."
130
+ exit
131
+ end
132
+ target_format = get_format(target_file)
133
+ converterlist = []
134
+ temp_files = []
135
+ opts.each do |o|
136
+ o = o.dup
137
+ tgt_format = o.delete(:target_format) || target_format
138
+ tgt_file = tempname(source_file, tgt_format)
139
+ temp_files << tgt_file
140
+ begin
141
+ source_file, converter = convert_file(source_file, tgt_file, source_format, tgt_format, o)
142
+ rescue Exception => e
143
+ prompt.error "File conversion of '%s' from '%s' to '%s' failed: %s @ %s" %
144
+ [source_file, source_format, tgt_format, e.message, e.backtrace.first]
145
+ exit
146
+ end
147
+ source_format = tgt_format
148
+ converterlist << converter
149
+ end
150
+ converter = converterlist.join(' + ')
151
+ if target_file
152
+ FileUtils.mkpath(File.dirname(target_file))
153
+ FileUtils.copy(source_file, target_file)
154
+ else
155
+ target_file = temp_files.pop
156
+ end
157
+ temp_files.each {|tmp_file| FileUtils.rm_f tmp_file}
158
+ [target_file, converter]
159
+ end
160
+
161
+ def convert_file(src_file, tgt_file, src_format, tgt_format, opts)
162
+ converter = Libis::Format::Converter::Repository.get_converter_chain(src_format, tgt_format, opts)
163
+
164
+ unless converter
165
+ prompt.error "Could not find converter for #{src_format} -> #{tgt_format} with #{opts}"
166
+ exit
167
+ end
168
+
169
+ converter_name = converter.to_s
170
+ prompt.say 'Converting file %s to %s with %s ' % [src_file, tgt_file, converter_name]
171
+ converted = converter.convert(src_file, tgt_file)
172
+
173
+ unless converted && converted == tgt_file
174
+ prompt.error 'File conversion failed (%s).', converter_name
175
+ return [nil, converter_name]
176
+ end
177
+
178
+ [tgt_file, converter_name]
179
+ end
180
+
181
+ def convert_image(source_file, target_file)
182
+ target_format = get_format(target_file)
183
+ converter = Libis::Format::Converter::ImageConverter.new
184
+ converter.page options[:page] if options[:page]
185
+ converter.quiet options[:quiet] if options[:quiet]
186
+ converter.scale options[:scale] if options[:scale]
187
+ converter.resize options[:resize] if options[:resize]
188
+ converter.resample options[:resample] if options[:resample]
189
+ converter.flatten if options[:flatten]
190
+ converter.delete_date if options[:delete_date]
191
+ converter.colorspace options[:colorspace] if options[:colorspace]
192
+ converter.profile options[:profile] if options[:profile]
193
+ if options[:wm_text] || options[:wm_file]
194
+ wm_options = {}
195
+ wm_options[:text] = options[:wm_text] if options[:wm_text]
196
+ wm_options[:file] = options[:wm_file] if options[:wm_file]
197
+ wm_options[:tiles] = options[:wm_tiles] if options[:wm_tiles]
198
+ wm_options[:resize] = options[:wm_resize] if options[:wm_resize]
199
+ wm_options[:gap] = options[:wm_gap] if options[:wm_gap]
200
+ wm_options[:rotation] = options[:wm_rotation] if options[:wm_rotation]
201
+ wm_options[:opacity] = options[:wm_opacity] if options[:wm_opacity]
202
+ wm_options[:gravity] = options[:wm_gravity] if options[:wm_gravity]
203
+ wm_options[:composition] = options[:wm_composition] if options[:wm_composition]
204
+ converter.watermark(wm_options)
205
+ end
206
+ converter.convert source_file, target_file, target_format
207
+ end
208
+
209
+ private
210
+
211
+ def check_input(source_file, target_file, options_file = nil)
212
+ # Check if source file exists and can be read
213
+ unless source_file && File.exist?(source_file) && File.readable?(source_file)
214
+ prompt.error "Fatal error trying to access source file '#{source_file}'."
215
+ exit
216
+ end
217
+ # Check if target file argument is supplied
218
+ unless target_file
219
+ prompt.error "Fatal error: no target file name supplied."
220
+ exit
221
+ end
222
+ # Check if target file directory can be created
223
+ begin
224
+ FileUtils.mkdir_p(File.dirname(target_file))
225
+ rescue SystemCallError => e
226
+ prompt.error "Fatal error trying to create folder for target file: #{e.message}"
227
+ exit
228
+ end
229
+
230
+ return [{}] unless options_file
231
+
232
+ # Check if options file exists and can be read
233
+ unless File.exist?(options_file) && File.readable?(options_file)
234
+ prompt.error "Fatal error trying to access options file '#{options_file}'."
235
+ exit
236
+ end
237
+
238
+ begin
239
+ opts = ::YAML.load_file(options_file)
240
+ opts = case opts
241
+ when Hash
242
+ [opts]
243
+ when Array
244
+ opts
245
+ when NilClass
246
+ [{}]
247
+ else
248
+ prompt.error "Options file contents should be a Hash or an Array of Hashes."
249
+ exit
250
+ end
251
+ opts.each {|h| h.key_strings_to_symbols!(recursive: true)}
252
+ opts
253
+ rescue Exception => e
254
+ prompt.error "Fatal error trying to parse options file: #{e.message}"
255
+ exit
256
+ end
257
+
258
+ end
259
+
260
+ def tempname(source_file, target_format)
261
+ # noinspection RubyResolve
262
+ Dir::Tmpname.create(
263
+ [File.basename(source_file, '.*'), ".#{extname(target_format)}"]
264
+ ) {}
265
+ end
266
+
267
+ def extname(format)
268
+ Libis::Format::Library.get_field(format, :extensions)
269
+ end
270
+
271
+ def get_format(file_name)
272
+ Libis::Format::Library.get_field_by(:extension, File.extname(file_name), :format)
273
+ end
274
+
275
+ def format_identifier(file)
276
+ prompt.say "Identifying format of file '#{file}'"
277
+ result = Libis::Format::Identifier.get(file) || {}
278
+ process_messages(result)
279
+ format = result[:formats][file]
280
+ unless format[:mimetype]
281
+ prompt.warn "Could not determine MIME type. Using default 'application/octet-stream'."
282
+ result[:puid] ||= 'fmt/unknown'
283
+ end
284
+ prompt.say "#{file} format: #{format[:GROUP]}, #{format[:TYPE]} (puid: #{format[:puid]}) mimetype: #{format[:mimetype]}"
285
+ format
286
+ end
287
+
288
+ def process_messages(format_result)
289
+ format_result[:messages].each do |msg|
290
+ case msg[0]
291
+ when :debug
292
+ prompt.say msg[1]
293
+ when :info
294
+ prompt.say msg[1]
295
+ when :warn
296
+ prompt.warn msg[1]
297
+ when :error
298
+ prompt.error msg[1]
299
+ when :fatal
300
+ prompt.error msg[1]
301
+ else
302
+ prompt.say "#{msg[0]}: #{msg[1]}"
303
+ end
304
+ end
305
+ end
306
+
307
+ end
308
+ end
309
+ end
310
+ end