gubbins-shell 0.1.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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +19 -0
  3. data/LICENSE +289 -0
  4. data/README.md +186 -0
  5. data/lib/gubbins/shell.rb +4 -0
  6. data/lib/shell/all.rb +34 -0
  7. data/lib/shell/base_64.rb +40 -0
  8. data/lib/shell/clam_av.rb +68 -0
  9. data/lib/shell/command.rb +1400 -0
  10. data/lib/shell/convert.rb +312 -0
  11. data/lib/shell/errors.rb +89 -0
  12. data/lib/shell/exiftool.rb +15 -0
  13. data/lib/shell/file.rb +84 -0
  14. data/lib/shell/ghostscript.rb +239 -0
  15. data/lib/shell/identify.rb +111 -0
  16. data/lib/shell/img2_pdf.rb +47 -0
  17. data/lib/shell/magick.rb +111 -0
  18. data/lib/shell/open_ssl.rb +26 -0
  19. data/lib/shell/optional_dependencies.rb +36 -0
  20. data/lib/shell/path.rb +40 -0
  21. data/lib/shell/pdf_detach.rb +86 -0
  22. data/lib/shell/pdffonts.rb +73 -0
  23. data/lib/shell/pdfimages.rb +48 -0
  24. data/lib/shell/pdfinfo.rb +79 -0
  25. data/lib/shell/pdftocairo.rb +24 -0
  26. data/lib/shell/pdftotext.rb +32 -0
  27. data/lib/shell/ping.rb +50 -0
  28. data/lib/shell/power_array.rb +42 -0
  29. data/lib/shell/seven_zip.rb +142 -0
  30. data/lib/shell/tesseract.rb +120 -0
  31. data/lib/shell/testing/mock/shell/clam_av.rb +12 -0
  32. data/lib/shell/testing/mock/shell/command.rb +241 -0
  33. data/lib/shell/testing/mock/shell/configurator.rb +223 -0
  34. data/lib/shell/testing/mock/shell/convert.rb +12 -0
  35. data/lib/shell/testing/mock/shell/file.rb +12 -0
  36. data/lib/shell/testing/mock/shell/ghostscript.rb +13 -0
  37. data/lib/shell/testing/mock/shell/identify.rb +11 -0
  38. data/lib/shell/testing/mock/shell/open_ssl.rb +11 -0
  39. data/lib/shell/testing/mock/shell/tesseract.rb +12 -0
  40. data/lib/shell/testing/mock/shell/unzip.rb +20 -0
  41. data/lib/shell/testing/mock/shell/zip.rb +11 -0
  42. data/lib/shell/testing.rb +15 -0
  43. data/lib/shell/tiff_2_pdf.rb +19 -0
  44. data/lib/shell/unzip.rb +137 -0
  45. data/lib/shell/version.rb +5 -0
  46. data/lib/shell/zbar.rb +123 -0
  47. data/lib/shell/zip.rb +52 -0
  48. data/lib/shell.rb +16 -0
  49. metadata +116 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 52d9dba435f2d841637f534de9e4f6149ad157b5bfd3bb8a947d42f035d3dd56
4
+ data.tar.gz: 7ff6cbccdb4acaa044799930c47168533ab68d424143c1c5f76edb0f57920e17
5
+ SHA512:
6
+ metadata.gz: 6c7646ed4616c4d4222980a8f1bb1667081d06542d2ca6d6ce233517c317ca56c9d0c990e5be1df18391842fb024baeb17adb74129c4106385fbff39b9a3ac2c
7
+ data.tar.gz: 3e038f8230139c2f08f87ec313251c84cfc386c426614f989557ac4ef44a331945ac2e9f1da94e36acd58d023be8472281bb424e7b0a91b741b21463a1d317fa
data/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ ## [Unreleased]
2
+
3
+ - `Shell::Zbar.extract_sepa_credit_transfers` returns the IBAN as written in the code instead of an
4
+ `IBAN` object, and no longer rejects an invalid one. Validating it is up to the caller.
5
+ - `Mock::Shell::Command` configures its mocks with `Mock::Shell::Configurator`, which this gem now
6
+ ships, instead of an external `Mock::Configurator`.
7
+ - ActiveSupport (>= 7.0) is a declared dependency, and the code requires the parts of it it uses.
8
+ `Shell::Zbar.scan` additionally needs the `rexml` gem, which is not installed with this one;
9
+ without it, it raises `Shell::Errors::DependencyMissing`.
10
+ - Requires Ruby 3.2 or newer.
11
+ - `Result#post_process` runs a block deriving `#value` from a successful command's output. An exception
12
+ raised there no longer escapes: it is stored as `Result#post_processing_failure` (and as `#value`),
13
+ which makes the Result a `#failure?`. `Shell::Zbar.scan` and `.extract_sepa_credit_transfers` use it, so
14
+ a QR code with an invalid IBAN yields a failed Result instead of raising `ArgumentError`.
15
+ - `Command#exec` no longer leaves its child process running if the calling thread is killed,
16
+ interrupted or has an exception raised into it while waiting: the child is sent SIGTERM and,
17
+ if it has not exited after `Command::TERMINATION_GRACE_PERIOD`, SIGKILL, and then reaped.
18
+ Termination on `timeout:` shares this code and now returns as soon as the child has exited,
19
+ instead of always waiting out the grace period.
data/LICENSE ADDED
@@ -0,0 +1,289 @@
1
+ Copyright Jan-Christian Foeh
2
+
3
+ EUROPEAN UNION PUBLIC LICENCE v. 1.2
4
+ EUPL © the European Union 2007, 2016
5
+
6
+ This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined
7
+ below) which is provided under the terms of this Licence. Any use of the Work,
8
+ other than as authorised under this Licence is prohibited (to the extent such
9
+ use is covered by a right of the copyright holder of the Work).
10
+
11
+ The Work is provided under the terms of this Licence when the Licensor (as
12
+ defined below) has placed the following notice immediately following the
13
+ copyright notice for the Work:
14
+
15
+ Licensed under the EUPL
16
+
17
+ or has expressed by any other means his willingness to license under the EUPL.
18
+
19
+ 1. Definitions
20
+
21
+ In this Licence, the following terms have the following meaning:
22
+
23
+ - ‘The Licence’: this Licence.
24
+
25
+ - ‘The Original Work’: the work or software distributed or communicated by the
26
+ Licensor under this Licence, available as Source Code and also as Executable
27
+ Code as the case may be.
28
+
29
+ - ‘Derivative Works’: the works or software that could be created by the
30
+ Licensee, based upon the Original Work or modifications thereof. This Licence
31
+ does not define the extent of modification or dependence on the Original Work
32
+ required in order to classify a work as a Derivative Work; this extent is
33
+ determined by copyright law applicable in the country mentioned in Article 15.
34
+
35
+ - ‘The Work’: the Original Work or its Derivative Works.
36
+
37
+ - ‘The Source Code’: the human-readable form of the Work which is the most
38
+ convenient for people to study and modify.
39
+
40
+ - ‘The Executable Code’: any code which has generally been compiled and which is
41
+ meant to be interpreted by a computer as a program.
42
+
43
+ - ‘The Licensor’: the natural or legal person that distributes or communicates
44
+ the Work under the Licence.
45
+
46
+ - ‘Contributor(s)’: any natural or legal person who modifies the Work under the
47
+ Licence, or otherwise contributes to the creation of a Derivative Work.
48
+
49
+ - ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
50
+ the Work under the terms of the Licence.
51
+
52
+ - ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
53
+ renting, distributing, communicating, transmitting, or otherwise making
54
+ available, online or offline, copies of the Work or providing access to its
55
+ essential functionalities at the disposal of any other natural or legal
56
+ person.
57
+
58
+ 2. Scope of the rights granted by the Licence
59
+
60
+ The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
61
+ sublicensable licence to do the following, for the duration of copyright vested
62
+ in the Original Work:
63
+
64
+ - use the Work in any circumstance and for all usage,
65
+ - reproduce the Work,
66
+ - modify the Work, and make Derivative Works based upon the Work,
67
+ - communicate to the public, including the right to make available or display
68
+ the Work or copies thereof to the public and perform publicly, as the case may
69
+ be, the Work,
70
+ - distribute the Work or copies thereof,
71
+ - lend and rent the Work or copies thereof,
72
+ - sublicense rights in the Work or copies thereof.
73
+
74
+ Those rights can be exercised on any media, supports and formats, whether now
75
+ known or later invented, as far as the applicable law permits so.
76
+
77
+ In the countries where moral rights apply, the Licensor waives his right to
78
+ exercise his moral right to the extent allowed by law in order to make effective
79
+ the licence of the economic rights here above listed.
80
+
81
+ The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to
82
+ any patents held by the Licensor, to the extent necessary to make use of the
83
+ rights granted on the Work under this Licence.
84
+
85
+ 3. Communication of the Source Code
86
+
87
+ The Licensor may provide the Work either in its Source Code form, or as
88
+ Executable Code. If the Work is provided as Executable Code, the Licensor
89
+ provides in addition a machine-readable copy of the Source Code of the Work
90
+ along with each copy of the Work that the Licensor distributes or indicates, in
91
+ a notice following the copyright notice attached to the Work, a repository where
92
+ the Source Code is easily and freely accessible for as long as the Licensor
93
+ continues to distribute or communicate the Work.
94
+
95
+ 4. Limitations on copyright
96
+
97
+ Nothing in this Licence is intended to deprive the Licensee of the benefits from
98
+ any exception or limitation to the exclusive rights of the rights owners in the
99
+ Work, of the exhaustion of those rights or of other applicable limitations
100
+ thereto.
101
+
102
+ 5. Obligations of the Licensee
103
+
104
+ The grant of the rights mentioned above is subject to some restrictions and
105
+ obligations imposed on the Licensee. Those obligations are the following:
106
+
107
+ Attribution right: The Licensee shall keep intact all copyright, patent or
108
+ trademarks notices and all notices that refer to the Licence and to the
109
+ disclaimer of warranties. The Licensee must include a copy of such notices and a
110
+ copy of the Licence with every copy of the Work he/she distributes or
111
+ communicates. The Licensee must cause any Derivative Work to carry prominent
112
+ notices stating that the Work has been modified and the date of modification.
113
+
114
+ Copyleft clause: If the Licensee distributes or communicates copies of the
115
+ Original Works or Derivative Works, this Distribution or Communication will be
116
+ done under the terms of this Licence or of a later version of this Licence
117
+ unless the Original Work is expressly distributed only under this version of the
118
+ Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee
119
+ (becoming Licensor) cannot offer or impose any additional terms or conditions on
120
+ the Work or Derivative Work that alter or restrict the terms of the Licence.
121
+
122
+ Compatibility clause: If the Licensee Distributes or Communicates Derivative
123
+ Works or copies thereof based upon both the Work and another work licensed under
124
+ a Compatible Licence, this Distribution or Communication can be done under the
125
+ terms of this Compatible Licence. For the sake of this clause, ‘Compatible
126
+ Licence’ refers to the licences listed in the appendix attached to this Licence.
127
+ Should the Licensee's obligations under the Compatible Licence conflict with
128
+ his/her obligations under this Licence, the obligations of the Compatible
129
+ Licence shall prevail.
130
+
131
+ Provision of Source Code: When distributing or communicating copies of the Work,
132
+ the Licensee will provide a machine-readable copy of the Source Code or indicate
133
+ a repository where this Source will be easily and freely available for as long
134
+ as the Licensee continues to distribute or communicate the Work.
135
+
136
+ Legal Protection: This Licence does not grant permission to use the trade names,
137
+ trademarks, service marks, or names of the Licensor, except as required for
138
+ reasonable and customary use in describing the origin of the Work and
139
+ reproducing the content of the copyright notice.
140
+
141
+ 6. Chain of Authorship
142
+
143
+ The original Licensor warrants that the copyright in the Original Work granted
144
+ hereunder is owned by him/her or licensed to him/her and that he/she has the
145
+ power and authority to grant the Licence.
146
+
147
+ Each Contributor warrants that the copyright in the modifications he/she brings
148
+ to the Work are owned by him/her or licensed to him/her and that he/she has the
149
+ power and authority to grant the Licence.
150
+
151
+ Each time You accept the Licence, the original Licensor and subsequent
152
+ Contributors grant You a licence to their contributions to the Work, under the
153
+ terms of this Licence.
154
+
155
+ 7. Disclaimer of Warranty
156
+
157
+ The Work is a work in progress, which is continuously improved by numerous
158
+ Contributors. It is not a finished work and may therefore contain defects or
159
+ ‘bugs’ inherent to this type of development.
160
+
161
+ For the above reason, the Work is provided under the Licence on an ‘as is’ basis
162
+ and without warranties of any kind concerning the Work, including without
163
+ limitation merchantability, fitness for a particular purpose, absence of defects
164
+ or errors, accuracy, non-infringement of intellectual property rights other than
165
+ copyright as stated in Article 6 of this Licence.
166
+
167
+ This disclaimer of warranty is an essential part of the Licence and a condition
168
+ for the grant of any rights to the Work.
169
+
170
+ 8. Disclaimer of Liability
171
+
172
+ Except in the cases of wilful misconduct or damages directly caused to natural
173
+ persons, the Licensor will in no event be liable for any direct or indirect,
174
+ material or moral, damages of any kind, arising out of the Licence or of the use
175
+ of the Work, including without limitation, damages for loss of goodwill, work
176
+ stoppage, computer failure or malfunction, loss of data or any commercial
177
+ damage, even if the Licensor has been advised of the possibility of such damage.
178
+ However, the Licensor will be liable under statutory product liability laws as
179
+ far such laws apply to the Work.
180
+
181
+ 9. Additional agreements
182
+
183
+ While distributing the Work, You may choose to conclude an additional agreement,
184
+ defining obligations or services consistent with this Licence. However, if
185
+ accepting obligations, You may act only on your own behalf and on your sole
186
+ responsibility, not on behalf of the original Licensor or any other Contributor,
187
+ and only if You agree to indemnify, defend, and hold each Contributor harmless
188
+ for any liability incurred by, or claims asserted against such Contributor by
189
+ the fact You have accepted any warranty or additional liability.
190
+
191
+ 10. Acceptance of the Licence
192
+
193
+ The provisions of this Licence can be accepted by clicking on an icon ‘I agree’
194
+ placed under the bottom of a window displaying the text of this Licence or by
195
+ affirming consent in any other similar way, in accordance with the rules of
196
+ applicable law. Clicking on that icon indicates your clear and irrevocable
197
+ acceptance of this Licence and all of its terms and conditions.
198
+
199
+ Similarly, you irrevocably accept this Licence and all of its terms and
200
+ conditions by exercising any rights granted to You by Article 2 of this Licence,
201
+ such as the use of the Work, the creation by You of a Derivative Work or the
202
+ Distribution or Communication by You of the Work or copies thereof.
203
+
204
+ 11. Information to the public
205
+
206
+ In case of any Distribution or Communication of the Work by means of electronic
207
+ communication by You (for example, by offering to download the Work from a
208
+ remote location) the distribution channel or media (for example, a website) must
209
+ at least provide to the public the information requested by the applicable law
210
+ regarding the Licensor, the Licence and the way it may be accessible, concluded,
211
+ stored and reproduced by the Licensee.
212
+
213
+ 12. Termination of the Licence
214
+
215
+ The Licence and the rights granted hereunder will terminate automatically upon
216
+ any breach by the Licensee of the terms of the Licence.
217
+
218
+ Such a termination will not terminate the licences of any person who has
219
+ received the Work from the Licensee under the Licence, provided such persons
220
+ remain in full compliance with the Licence.
221
+
222
+ 13. Miscellaneous
223
+
224
+ Without prejudice of Article 9 above, the Licence represents the complete
225
+ agreement between the Parties as to the Work.
226
+
227
+ If any provision of the Licence is invalid or unenforceable under applicable
228
+ law, this will not affect the validity or enforceability of the Licence as a
229
+ whole. Such provision will be construed or reformed so as necessary to make it
230
+ valid and enforceable.
231
+
232
+ The European Commission may publish other linguistic versions or new versions of
233
+ this Licence or updated versions of the Appendix, so far this is required and
234
+ reasonable, without reducing the scope of the rights granted by the Licence. New
235
+ versions of the Licence will be published with a unique version number.
236
+
237
+ All linguistic versions of this Licence, approved by the European Commission,
238
+ have identical value. Parties can take advantage of the linguistic version of
239
+ their choice.
240
+
241
+ 14. Jurisdiction
242
+
243
+ Without prejudice to specific agreement between parties,
244
+
245
+ - any litigation resulting from the interpretation of this License, arising
246
+ between the European Union institutions, bodies, offices or agencies, as a
247
+ Licensor, and any Licensee, will be subject to the jurisdiction of the Court
248
+ of Justice of the European Union, as laid down in article 272 of the Treaty on
249
+ the Functioning of the European Union,
250
+
251
+ - any litigation arising between other parties and resulting from the
252
+ interpretation of this License, will be subject to the exclusive jurisdiction
253
+ of the competent court where the Licensor resides or conducts its primary
254
+ business.
255
+
256
+ 15. Applicable Law
257
+
258
+ Without prejudice to specific agreement between parties,
259
+
260
+ - this Licence shall be governed by the law of the European Union Member State
261
+ where the Licensor has his seat, resides or has his registered office,
262
+
263
+ - this licence shall be governed by Belgian law if the Licensor has no seat,
264
+ residence or registered office inside a European Union Member State.
265
+
266
+ Appendix
267
+
268
+ ‘Compatible Licences’ according to Article 5 EUPL are:
269
+
270
+ - GNU General Public License (GPL) v. 2, v. 3
271
+ - GNU Affero General Public License (AGPL) v. 3
272
+ - Open Software License (OSL) v. 2.1, v. 3.0
273
+ - Eclipse Public License (EPL) v. 1.0
274
+ - CeCILL v. 2.0, v. 2.1
275
+ - Mozilla Public Licence (MPL) v. 2
276
+ - GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
277
+ - Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
278
+ works other than software
279
+ - European Union Public Licence (EUPL) v. 1.1, v. 1.2
280
+ - Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
281
+ Reciprocity (LiLiQ-R+).
282
+
283
+ The European Commission may update this Appendix to later versions of the above
284
+ licences without producing a new version of the EUPL, as long as they provide
285
+ the rights granted in Article 2 of this Licence and protect the covered Source
286
+ Code from exclusive appropriation.
287
+
288
+ All other changes or additions to this Appendix require the production of a new
289
+ EUPL version.
data/README.md ADDED
@@ -0,0 +1,186 @@
1
+ # gubbins-shell
2
+
3
+ Ruby wrappers for shell commands with a clean DSL. Provides a base `Shell::Command` class for creating your own command wrappers, plus optional ready-made wrappers for common tools.
4
+
5
+ ## Why & what
6
+
7
+ `Shell` gives you a way to paper over the little annoyances when shelling out in Ruby, both on the Ruby
8
+ side (Backticks? `system`? `exec`? `spawn`? `IO.popen`? `Open3.popen3`?) and on the commands' side, from
9
+ wrong return codes over inscrutable options to inconsistent flags between versions or environments.
10
+
11
+ - clean DSL for command wrappers
12
+ - automatic shell argument escaping
13
+ - a standardized return object
14
+ - timeout support for long-running commands
15
+ - STDIN/STDOUT redirection
16
+ - error handling with custom exceptions
17
+ - handles changes due to version or environment differences
18
+
19
+ See the extensive documentation in `Shell::Command` for creating custom wrappers.
20
+
21
+ ## Requirements
22
+
23
+ Ruby 3.2 or newer and ActiveSupport 7.0 or newer (up to 8.x). The wrappers run the programs they are named
24
+ after, which have to be installed; see "Optional dependencies" below.
25
+
26
+ ## Installation
27
+
28
+ ### Option 1: Core Library Only (Recommended)
29
+
30
+ Add to your Gemfile:
31
+
32
+ ```ruby
33
+ gem 'gubbins-shell'
34
+ ```
35
+
36
+ This loads only the `Shell::Command` base class. Individual wrappers can be required as needed:
37
+
38
+ ```ruby
39
+ require 'shell/ping'
40
+ require 'shell/tesseract'
41
+ ```
42
+
43
+ ### Option 2: Core + All Wrappers
44
+
45
+ If you want all command wrappers loaded automatically:
46
+
47
+ ```ruby
48
+ gem 'gubbins-shell', require: 'shell/all'
49
+ ```
50
+
51
+ This loads all of the concrete command wrappers at once.
52
+
53
+ ### Direct Installation
54
+
55
+ ```bash
56
+ $ gem install gubbins-shell
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ ### Core Library
62
+
63
+ By default, requiring `shell` loads only the core `Shell::Command` class:
64
+
65
+ ```ruby
66
+ require 'shell'
67
+
68
+ # Create your own command wrappers
69
+ class Shell::MyCommand < Shell::Command
70
+ command_path "/usr/bin/my_command"
71
+ end
72
+
73
+ result = Shell::MyCommand.exec("file.txt")
74
+ puts result.stdout
75
+ ```
76
+
77
+ ### Concrete Command Wrappers
78
+
79
+ The gem includes wrappers for common shell commands. These are **not loaded by default** to keep the footprint small.
80
+
81
+ **Load individual wrappers:**
82
+
83
+ ```ruby
84
+ require 'shell/ping'
85
+ require 'shell/zip'
86
+
87
+ Shell::Ping.exec("example.com")
88
+ ```
89
+
90
+ **Load all wrappers at once:**
91
+
92
+ ```ruby
93
+ require 'shell/all'
94
+
95
+ Shell::Ping.exec("example.com")
96
+ Shell::Tesseract.exec("image.png", "output", language: "eng")
97
+ Shell::Ghostscript.pdf_to_image(input: "in.pdf", output: "page.jpg", resolution: 150)
98
+ ```
99
+
100
+ ### Available Wrappers
101
+
102
+ - `shell/base_64` - Base64 encoding
103
+ - `shell/clam_av` - ClamAV virus scanning
104
+ - `shell/convert` - ImageMagick convert
105
+ - `shell/exiftool` - EXIF metadata
106
+ - `shell/file` - File type detection
107
+ - `shell/ghostscript` - PDF operations
108
+ - `shell/identify` - ImageMagick identify
109
+ - `shell/img2_pdf` - Image to PDF conversion
110
+ - `shell/magick` - ImageMagick (v7+)
111
+ - `shell/open_ssl` - OpenSSL operations
112
+ - `shell/path` - Path conversion helpers, used by the other wrappers
113
+ - `shell/pdf_detach` - Extract files embedded in PDFs
114
+ - `shell/pdffonts` - Fonts used by a PDF
115
+ - `shell/pdfimages` - Extract images from PDFs
116
+ - `shell/pdfinfo` - PDF metadata
117
+ - `shell/pdftocairo` - Rewrite PDFs with all fonts embedded
118
+ - `shell/pdftotext` - PDF text extraction
119
+ - `shell/ping` - Network ping
120
+ - `shell/seven_zip` - 7-Zip compression
121
+ - `shell/tesseract` - OCR
122
+ - `shell/tiff_2_pdf` - TIFF to PDF conversion
123
+ - `shell/unzip` - ZIP extraction
124
+ - `shell/zbar` - Barcode/QR code scanning
125
+ - `shell/zip` - ZIP compression
126
+
127
+ ### Optional dependencies
128
+
129
+ The gem depends on ActiveSupport only. Whatever a single wrapper needs beyond that is not installed
130
+ with it, because RubyGems cannot express optional dependencies and most users will never touch that wrapper.
131
+ Add it to your own Gemfile if you use the wrapper; otherwise the wrapper raises
132
+ `Shell::Errors::DependencyMissing`, naming the gem.
133
+
134
+ | Wrapper | Gem |
135
+ |---|---|
136
+ | `Shell::Zbar.scan` (and everything built on it) | `rexml` |
137
+ | `Shell::PDFDetach.to_temp`, `Shell::SevenZip.to_temp` | `gubbins-fs`, whose `Fs::Directory` they return |
138
+
139
+ Each wrapper also needs its program on the `PATH`. They are looked up when the wrapper is loaded;
140
+ one that is missing raises `Shell::Errors::CommandNotFound` when you run it.
141
+
142
+ | Wrapper | Program |
143
+ |---|---|
144
+ | `shell/base_64` | `base64` |
145
+ | `shell/clam_av` | `clamdscan`, `clamscan` |
146
+ | `shell/convert` | `convert` (ImageMagick) |
147
+ | `shell/exiftool` | `exiftool` |
148
+ | `shell/file` | `file` |
149
+ | `shell/ghostscript` | `gs` |
150
+ | `shell/identify` | `identify` (ImageMagick) |
151
+ | `shell/img2_pdf` | `img2pdf` |
152
+ | `shell/magick` | `magick` (ImageMagick 7) |
153
+ | `shell/open_ssl` | `openssl` |
154
+ | `shell/pdf_detach`, `shell/pdffonts`, `shell/pdfimages`, `shell/pdfinfo`, `shell/pdftocairo`, `shell/pdftotext` | the program of the same name, from Poppler |
155
+ | `shell/ping` | `ping` |
156
+ | `shell/seven_zip` | `7z` |
157
+ | `shell/tesseract` | `tesseract` |
158
+ | `shell/tiff_2_pdf` | `tiff2pdf` (libtiff) |
159
+ | `shell/unzip`, `shell/zip` | `unzip`, `zip` |
160
+ | `shell/zbar` | `zbarimg` |
161
+
162
+ ### Testing
163
+
164
+ `shell/testing` has RSpec mocks for some of the wrappers (`Mock::Shell::ClamAv`, `Convert`, `File`,
165
+ `Ghostscript`, `Identify`, `OpenSsl`, `Tesseract`, `Unzip` and `Zip`). They need `rspec-mocks`, which this gem
166
+ does not install. A mock replaces a wrapper's method, and hands back a `Shell::Command::Result` carrying the value you configure:
167
+
168
+ ```ruby
169
+ require "shell/testing"
170
+
171
+ Mock::Shell::Zip.on(:from_directory) # returns the mock's default value
172
+ Mock::Shell::Zip.on(:from_directory) { return_value "archive.zip" } # or one of your own
173
+
174
+ Shell::Zip.from_directory("source", to: "target.zip").value # => "archive.zip"
175
+ ```
176
+
177
+ See the documentation of `Mock::Shell::Command` for making a mock of your own wrappers.
178
+
179
+ ## Development
180
+
181
+ After checking out the repo, run `bin/setup` to install dependencies. Then run `bundle exec rake` to run the specs. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
182
+
183
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
184
+
185
+ ## License
186
+ The gem is available as open source under the terms of the [European Union Public Licence v1.2](https://interoperable-europe.ec.europa.eu/sites/default/files/custom-page/attachment/2020-03/EUPL-1.2%20EN.txt).
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # What Bundler requires for `gem "gubbins-shell"`
4
+ require_relative "../shell"
data/lib/shell/all.rb ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Require all concrete Shell command wrappers
4
+ #
5
+ # Usage:
6
+ # require 'shell' # Core only
7
+ # require 'shell/all' # Core + all wrappers
8
+
9
+ require_relative "../shell"
10
+
11
+ require_relative "base_64"
12
+ require_relative "clam_av"
13
+ require_relative "convert"
14
+ require_relative "exiftool"
15
+ require_relative "file"
16
+ require_relative "ghostscript"
17
+ require_relative "identify"
18
+ require_relative "img2_pdf"
19
+ require_relative "magick"
20
+ require_relative "open_ssl"
21
+ require_relative "path"
22
+ require_relative "pdf_detach"
23
+ require_relative "pdffonts"
24
+ require_relative "pdfimages"
25
+ require_relative "pdfinfo"
26
+ require_relative "pdftocairo"
27
+ require_relative "pdftotext"
28
+ require_relative "ping"
29
+ require_relative "seven_zip"
30
+ require_relative "tesseract"
31
+ require_relative "tiff_2_pdf"
32
+ require_relative "unzip"
33
+ require_relative "zbar"
34
+ require_relative "zip"
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../shell"
4
+
5
+ module Shell
6
+ class Base64 < Command
7
+ command_path `which base64`
8
+
9
+ detect_version do
10
+ :mac if RUBY_PLATFORM.match?(/darwin/)
11
+ end
12
+
13
+ # @param input [Pathname, Fs::File, String]
14
+ # @param wrap [Integer] wrap lines at this column; pass 0 to turn off wrapping
15
+ # @return [Shell::Command::Result]
16
+ def self.encode(input, wrap: 0, **kargs)
17
+ versioned_new.encode(input, wrap: wrap, **kargs)
18
+ end
19
+
20
+ # @param input [Pathname, Fs::File, String]
21
+ # @param wrap [Integer] wrap lines at this column; pass 0 to turn off wrapping
22
+ # @return [Shell::Command::Result]
23
+ def encode(input, wrap: 0, **kargs)
24
+ exec(input, w: wrap, **kargs).on_success do |result|
25
+ result.value = result.stdout
26
+ end
27
+ end
28
+
29
+ version(:mac) do
30
+ # @param input [Pathname, Fs::File, String]
31
+ # @param wrap [Integer] wrap lines at this column; pass 0 to turn off wrapping
32
+ # @return [Shell::Command::Result]
33
+ def encode(input, wrap: 0, **kargs)
34
+ exec(i: input, b: wrap, **kargs).on_success do |result|
35
+ result.value = result.stdout
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../shell"
4
+
5
+ module Shell
6
+ # Interface for the ClamAV virus scanner. Auto-switches between
7
+ # standalone and daemonized mode.
8
+ class ClamAv < Command
9
+ command_path `which clamdscan`
10
+
11
+ # Run an AV scan on `input`
12
+ #
13
+ # @param input [Pathname, Fs::File, String]
14
+ # @return [Shell::Command::Result]
15
+ def self.safe(input)
16
+ versioned_new.safe?(input)
17
+ end
18
+
19
+ # Run an AV scan on `input`
20
+ #
21
+ # @param input [Pathname, Fs::File, String]
22
+ # @return [Boolean]
23
+ def self.safe?(input)
24
+ safe(input).value
25
+ end
26
+
27
+ # Run an AV scan on `input`
28
+ #
29
+ # @param input [Pathname, Fs::File, String]
30
+ # @return [Shell::Command::Result]
31
+ def safe?(input)
32
+ exec(fdpass: input).on_success do |result|
33
+ result.value = stdout_says_ok?(result.stdout)
34
+ end
35
+ end
36
+
37
+ detect_version do
38
+ exec_base(ping: 1).status == 21 ? :no_daemon : nil
39
+ end
40
+
41
+ version(:no_daemon) do
42
+ command_path `which clamscan`
43
+
44
+ # Run an AV scan on `input`
45
+ #
46
+ # @param input [Pathname, Fs::File, String]
47
+ # @return [Shell::Command::Result]
48
+ def safe?(input)
49
+ exec(input).on_success do |result|
50
+ result.value = stdout_says_ok?(result.stdout)
51
+ end
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ # Detects the scan result from STDOUT output
58
+ #
59
+ # @param stdout [String]
60
+ # @return [Boolean]
61
+ def stdout_says_ok?(stdout)
62
+ stdout.lines
63
+ .first
64
+ .chomp
65
+ .end_with?(": OK")
66
+ end
67
+ end
68
+ end