labrat 0.1.13
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.rubocop.yml +18 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +102 -0
- data/README.org +644 -0
- data/Rakefile +12 -0
- data/TODO.org +7 -0
- data/bin/console +15 -0
- data/bin/labrat +74 -0
- data/bin/labrat-install +85 -0
- data/bin/setup +8 -0
- data/img/sample.jpg +0 -0
- data/img/sample.pdf +82 -0
- data/img/sample.png +0 -0
- data/labrat.gemspec +40 -0
- data/lib/config_files/config.yml +121 -0
- data/lib/config_files/labeldb.yml +1010 -0
- data/lib/config_files/labeldb_usr.yml +24 -0
- data/lib/labrat/arg_parser.rb +481 -0
- data/lib/labrat/config.rb +188 -0
- data/lib/labrat/errors.rb +13 -0
- data/lib/labrat/hash.rb +38 -0
- data/lib/labrat/label.rb +158 -0
- data/lib/labrat/label_db.rb +49 -0
- data/lib/labrat/options.rb +184 -0
- data/lib/labrat/read_files.rb +40 -0
- data/lib/labrat/version.rb +5 -0
- data/lib/labrat.rb +20 -0
- data/lib/lisp/labrat.el +108 -0
- metadata +219 -0
data/bin/labrat
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../lib/labrat'
|
5
|
+
|
6
|
+
begin
|
7
|
+
# We need to know whether the verbose option is present before any
|
8
|
+
# examination of the config files or command-line options is done, so this
|
9
|
+
# is a bit of a hack.
|
10
|
+
verb = ARGV.include?('--verbose') || ARGV.include?('-v')
|
11
|
+
ops = Labrat::Options.set_options(ARGV, verbose: verb)
|
12
|
+
if ops.msg
|
13
|
+
warn ops.msg
|
14
|
+
exit(1)
|
15
|
+
end
|
16
|
+
ops.to_hash.report("\nFinal option set") if verb
|
17
|
+
|
18
|
+
# There are three possible sources of label text: (1) the non-option
|
19
|
+
# command-line arguments, if any, are always included, (3) paragraphs in the
|
20
|
+
# file specified by the --in-file argument, if any, are always included, and (3)
|
21
|
+
# paragraphs in standard input are included if there are no non-option
|
22
|
+
# arguments and no --in-file argument.
|
23
|
+
|
24
|
+
non_ops = ARGV.grep_v(/\A--?/)
|
25
|
+
texts = non_ops.empty? ? [] : non_ops.join(' ').split(ops.label_sep)
|
26
|
+
texts +=
|
27
|
+
if ops.template
|
28
|
+
[]
|
29
|
+
elsif !ops.in_file.blank?
|
30
|
+
Labrat.read_label_texts(ops.in_file, ops.nlsep)
|
31
|
+
elsif non_ops.empty?
|
32
|
+
Labrat.read_label_texts(nil, ops.nlsep)
|
33
|
+
else
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
|
37
|
+
lab = Labrat::Label.new(texts, ops).generate
|
38
|
+
if ops.view
|
39
|
+
lab.view
|
40
|
+
else
|
41
|
+
lab.print
|
42
|
+
end
|
43
|
+
|
44
|
+
rescue Labrat::OptionError => e
|
45
|
+
warn "Error: #{e}: exiting"
|
46
|
+
exit(1)
|
47
|
+
rescue Labrat::EmptyLabelError => e
|
48
|
+
warn "Error: #{e}: refusing to print"
|
49
|
+
exit(1)
|
50
|
+
rescue Labrat::RecursionError => e
|
51
|
+
warn "Error: #{e}: exiting"
|
52
|
+
exit(1)
|
53
|
+
rescue Labrat::LabelNameError => e
|
54
|
+
warn "Error: #{e}: exiting"
|
55
|
+
lab_names = Labrat::LabelDb.known_names
|
56
|
+
if lab_names.empty?
|
57
|
+
warn " Have you run labrat-install yet?"
|
58
|
+
else
|
59
|
+
warn " Try `labrat --list-labels` to list known labels."
|
60
|
+
end
|
61
|
+
exit(1)
|
62
|
+
rescue Labrat::DimensionError => e
|
63
|
+
warn "Error: #{e}: exiting"
|
64
|
+
exit(1)
|
65
|
+
rescue Prawn::Errors::CannotFit
|
66
|
+
warn "Error: #{e}:"
|
67
|
+
warn "Page and label dimensions leave no room for labels."
|
68
|
+
warn " Try `labrat -T -v -V` to diagnose the problem."
|
69
|
+
exit(1)
|
70
|
+
rescue Prawn::Errors::UnknownFont => e
|
71
|
+
warn "Error: #{e}:"
|
72
|
+
warn " Builtin fonts are Times-Roman, Courier, and Helvetica"
|
73
|
+
exit(1)
|
74
|
+
end
|
data/bin/labrat-install
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
###################################################################
|
8
|
+
# System config
|
9
|
+
###################################################################
|
10
|
+
sys_dest_dir = '/etc/xdg/labrat'
|
11
|
+
unless Dir.exist?(sys_dest_dir)
|
12
|
+
warn "Creating system config directory '#{sys_dest_dir}'."
|
13
|
+
mcmd = "sudo mkdir -p '#{sys_dest_dir}'"
|
14
|
+
system(mcmd)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Install system label db file
|
18
|
+
sys_src_db_path = File.join(__dir__, '../lib/config_files/labeldb.yml')
|
19
|
+
sys_src_db_path = File.expand_path(sys_src_db_path)
|
20
|
+
sys_dest_db_path = File.join(sys_dest_dir, 'labeldb.yml')
|
21
|
+
if File.exist?(sys_dest_db_path)
|
22
|
+
warn "System label db file '#{sys_dest_db_path}' exists."
|
23
|
+
warn " Delete it and re-run labrat-install to re-install it."
|
24
|
+
else
|
25
|
+
warn "Installing system label db file '#{sys_dest_db_path}'."
|
26
|
+
icmd = "sudo install -m 0664 '#{sys_src_db_path}' '#{sys_dest_dir}'"
|
27
|
+
system(icmd)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Install system config file
|
31
|
+
sys_src_cfg_path = File.join(__dir__, '../lib/config_files/config.yml')
|
32
|
+
sys_src_cfg_path = File.expand_path(sys_src_cfg_path)
|
33
|
+
sys_dest_cfg_path = File.join(sys_dest_dir, 'config.yml')
|
34
|
+
if File.exist?(sys_dest_cfg_path)
|
35
|
+
warn "System config file '#{sys_dest_cfg_path}' exists."
|
36
|
+
warn " Delete it and re-run labrat-install to re-install it."
|
37
|
+
else
|
38
|
+
warn "Installing system config file '#{sys_dest_cfg_path}'."
|
39
|
+
icmd = "sudo install -m 0664 '#{sys_src_cfg_path}' '#{sys_dest_dir}'"
|
40
|
+
system(icmd)
|
41
|
+
end
|
42
|
+
|
43
|
+
###################################################################
|
44
|
+
# User config
|
45
|
+
###################################################################
|
46
|
+
usr_dest_dir = File.expand_path('~/.config/labrat')
|
47
|
+
unless Dir.exist?(usr_dest_dir)
|
48
|
+
warn "Creating user config directory '#{usr_dest_dir}'."
|
49
|
+
mcmd = "mkdir -p '#{usr_dest_dir}'"
|
50
|
+
system(mcmd)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Install user label db file
|
54
|
+
usr_src_db_path = File.join(__dir__, '../lib/config_files/labeldb_usr.yml')
|
55
|
+
usr_src_db_path = File.expand_path(usr_src_db_path)
|
56
|
+
usr_dest_db_path = File.join(usr_dest_dir, 'labeldb.yml')
|
57
|
+
if File.exist?(usr_dest_db_path)
|
58
|
+
warn "User label db file '#{usr_dest_db_path}' exists."
|
59
|
+
warn " Delete it and re-run labrat-install to re-install it."
|
60
|
+
else
|
61
|
+
warn "Installing user label db file '#{usr_dest_db_path}'."
|
62
|
+
icmd = "install -m 0664 '#{usr_src_db_path}' '#{usr_dest_db_path}'"
|
63
|
+
system(icmd)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Install user config file
|
67
|
+
usr_src_cfg_path = File.join(__dir__, '../lib/config_files/config.yml')
|
68
|
+
usr_src_cfg_path = File.expand_path(usr_src_cfg_path)
|
69
|
+
usr_dest_cfg_path = File.join(usr_dest_dir, 'config.yml')
|
70
|
+
if File.exist?(usr_dest_cfg_path)
|
71
|
+
warn "User config file '#{usr_dest_cfg_path}' exists."
|
72
|
+
warn " Delete it and re-run labrat-install to re-install it."
|
73
|
+
else
|
74
|
+
warn "Installing user config file '#{usr_dest_cfg_path}'."
|
75
|
+
icmd = "install -m 0664 '#{usr_src_cfg_path}' '#{usr_dest_dir}'"
|
76
|
+
system(icmd)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Install Emacs lisp library
|
80
|
+
lsp_src_path = File.join(__dir__, '../lib/lisp/labrat.el')
|
81
|
+
lsp_src_path = File.expand_path(lsp_src_path)
|
82
|
+
lsp_dest_path = File.join(usr_dest_dir, 'labrat.el')
|
83
|
+
warn "Installing Emacs lisp library '#{lsp_dest_path}'."
|
84
|
+
icmd = "install -m 0664 '#{lsp_src_path}' '#{lsp_dest_path}'"
|
85
|
+
system(icmd)
|
data/bin/setup
ADDED
data/img/sample.jpg
ADDED
Binary file
|
data/img/sample.pdf
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
%PDF-1.3
|
2
|
+
%����
|
3
|
+
1 0 obj
|
4
|
+
<< /Creator <feff0050007200610077006e>
|
5
|
+
/Producer <feff0050007200610077006e>
|
6
|
+
>>
|
7
|
+
endobj
|
8
|
+
2 0 obj
|
9
|
+
<< /Type /Catalog
|
10
|
+
/Pages 3 0 R
|
11
|
+
>>
|
12
|
+
endobj
|
13
|
+
3 0 obj
|
14
|
+
<< /Type /Pages
|
15
|
+
/Count 1
|
16
|
+
/Kids [5 0 R]
|
17
|
+
>>
|
18
|
+
endobj
|
19
|
+
4 0 obj
|
20
|
+
<< /Length 229
|
21
|
+
>>
|
22
|
+
stream
|
23
|
+
q
|
24
|
+
0.0 14.17323 249.44882 36.85039 re
|
25
|
+
S
|
26
|
+
|
27
|
+
BT
|
28
|
+
62.06447 36.84775 Td
|
29
|
+
/F1.0 12 Tf
|
30
|
+
[<496e636f6d652054> 80 <6178> 10 <65732032303231>] TJ
|
31
|
+
ET
|
32
|
+
|
33
|
+
|
34
|
+
BT
|
35
|
+
59.22047 22.56775 Td
|
36
|
+
/F1.0 12 Tf
|
37
|
+
[<4578616d706c65204d616b6572> 60 <2c20496e632e>] TJ
|
38
|
+
ET
|
39
|
+
|
40
|
+
Q
|
41
|
+
|
42
|
+
endstream
|
43
|
+
endobj
|
44
|
+
5 0 obj
|
45
|
+
<< /Type /Page
|
46
|
+
/Parent 3 0 R
|
47
|
+
/MediaBox [0 0 249.44882 65.19685]
|
48
|
+
/CropBox [0 0 249.44882 65.19685]
|
49
|
+
/BleedBox [0 0 249.44882 65.19685]
|
50
|
+
/TrimBox [0 0 249.44882 65.19685]
|
51
|
+
/ArtBox [0 0 249.44882 65.19685]
|
52
|
+
/Contents 4 0 R
|
53
|
+
/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
|
54
|
+
/Font << /F1.0 6 0 R
|
55
|
+
>>
|
56
|
+
>>
|
57
|
+
>>
|
58
|
+
endobj
|
59
|
+
6 0 obj
|
60
|
+
<< /Type /Font
|
61
|
+
/Subtype /Type1
|
62
|
+
/BaseFont /Helvetica-Bold
|
63
|
+
/Encoding /WinAnsiEncoding
|
64
|
+
>>
|
65
|
+
endobj
|
66
|
+
xref
|
67
|
+
0 7
|
68
|
+
0000000000 65535 f
|
69
|
+
0000000015 00000 n
|
70
|
+
0000000109 00000 n
|
71
|
+
0000000158 00000 n
|
72
|
+
0000000215 00000 n
|
73
|
+
0000000495 00000 n
|
74
|
+
0000000816 00000 n
|
75
|
+
trailer
|
76
|
+
<< /Size 7
|
77
|
+
/Root 2 0 R
|
78
|
+
/Info 1 0 R
|
79
|
+
>>
|
80
|
+
startxref
|
81
|
+
918
|
82
|
+
%%EOF
|
data/img/sample.png
ADDED
Binary file
|
data/labrat.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/labrat/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "labrat"
|
7
|
+
spec.version = Labrat::VERSION
|
8
|
+
spec.authors = ["Daniel E. Doherty"]
|
9
|
+
spec.email = ["ded-labrat@ddoherty.net"]
|
10
|
+
|
11
|
+
spec.summary = "Simple command-line label printer."
|
12
|
+
spec.homepage = "http://github.com/ddoherty03/labrat"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "http://github.com/ddoherty03/labrat"
|
17
|
+
spec.metadata["changelog_uri"] = "http://github.com/ddoherty03/labrat/CHANGELOG.md"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
%x[git ls-files -z].split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = 'bin'
|
25
|
+
spec.executables = spec.files.grep(%r{\Abin/labrat}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
spec.post_install_message = 'To install config and label database files, run [sudo] labrat-install.'
|
28
|
+
spec.add_dependency "prawn", "~> 2.0"
|
29
|
+
spec.add_dependency "activesupport"
|
30
|
+
spec.add_dependency "fat_core"
|
31
|
+
|
32
|
+
# Note: pry-byebug requires that pry be within the '0.13.0' version box.
|
33
|
+
spec.add_development_dependency 'rake'
|
34
|
+
spec.add_development_dependency 'rspec'
|
35
|
+
spec.add_development_dependency 'pry', '~> 0.13.0'
|
36
|
+
spec.add_development_dependency 'pry-byebug', '>= 3.9.0'
|
37
|
+
spec.add_development_dependency 'rubocop-performance'
|
38
|
+
spec.add_development_dependency 'rubocop-shopify'
|
39
|
+
spec.add_development_dependency 'rubocop-rspec'
|
40
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# Sample config file for labrat.
|
2
|
+
|
3
|
+
# These settings correspond to the default values for all the options. To
|
4
|
+
# change the default for you, uncomment a setting and set it to your desired
|
5
|
+
# default. You can override these with command-line flags, having the same
|
6
|
+
# name as the config options, such as --page-width=44mm.
|
7
|
+
|
8
|
+
# Any option that takes a dimension can use pt, mm, cm, dm, m, in, ft, or yd.
|
9
|
+
# A dimension without a unit attached designates Adobe points, i.e., 1/72in.
|
10
|
+
|
11
|
+
# The following describe the size of the labels to be printed indirectly by
|
12
|
+
# describing the size of the page on which they are printed, the page margins,
|
13
|
+
# the number of rows and columns, and the size of the gap between rows and
|
14
|
+
# columns, and the orientation of printing within each grid. Each label is
|
15
|
+
# printed within a grid element resulting from the foregoing. These defaults
|
16
|
+
# are based on a Dymo file folder label, which prints only one per page and is
|
17
|
+
# printed in landscape.
|
18
|
+
|
19
|
+
# page-width: 24mm
|
20
|
+
# page-height: 87mm
|
21
|
+
# left-page-margin: 5mm
|
22
|
+
# right-page-margin: 5.mm
|
23
|
+
# top-page-margin: 0mm
|
24
|
+
# bottom-page-margin: 0.mm
|
25
|
+
# rows: 1
|
26
|
+
# columns: 1
|
27
|
+
# row-gap: 0mm
|
28
|
+
# column-gap: 0mm
|
29
|
+
# landscape: true
|
30
|
+
|
31
|
+
# Rather than setting the above attribytes in an ad-hoc manner, it is probably
|
32
|
+
# better to define a label name in the labeldb.yml file (either in the user
|
33
|
+
# config directory ~/.config/labrat/labeldb.yml or in the system config
|
34
|
+
# directory /etc/xdg/labrat/labeldb.yml) and then just specify a label name
|
35
|
+
# here or on the command-line. The name of a label with its dimensions to be
|
36
|
+
# used by default.
|
37
|
+
|
38
|
+
# For example, this is a defined label type and the its dimensions are the
|
39
|
+
# default for labrat.
|
40
|
+
#
|
41
|
+
# label: dymo30327
|
42
|
+
|
43
|
+
# Each of the following deal with formatting at the label level. What you see
|
44
|
+
# is the default.
|
45
|
+
|
46
|
+
# These can be one of (1) left, (2) right, or (3) center. They determine the
|
47
|
+
# alignment of the label text within a label.
|
48
|
+
#
|
49
|
+
# h-align: center
|
50
|
+
# v-align: center
|
51
|
+
|
52
|
+
# Dimensions for the padding within each label.
|
53
|
+
#
|
54
|
+
# left-pad: 4.5mm
|
55
|
+
# right-pad: 4.5mm
|
56
|
+
# top-pad: 0mm
|
57
|
+
# bottom-pad: 0mm
|
58
|
+
|
59
|
+
# On a multi-label page of labels, you may want to start printing in a label
|
60
|
+
# slot other than the first, e.g., if you are printing on a partially-used
|
61
|
+
# sheet. The labels are numbered left to right, top to bottom, starting with
|
62
|
+
# 1.
|
63
|
+
#
|
64
|
+
# start-label: 1
|
65
|
+
|
66
|
+
# The name of the font to use to print the text of the label.
|
67
|
+
#
|
68
|
+
# font_name: Helvetica
|
69
|
+
# The font style can be one of (1) normal, (2) bold, (3) italic, or (4)
|
70
|
+
# bold-italic.
|
71
|
+
#
|
72
|
+
# font-style: normal
|
73
|
+
# The size of the font to use.
|
74
|
+
#
|
75
|
+
# font-size: 12pt
|
76
|
+
|
77
|
+
# These dimensions should normally be left at zero, but are here to make up
|
78
|
+
# for defects in printer drivers that fail to print a pdf exactly as it is
|
79
|
+
# shown in a pdf previewer. They nudge the final label text left or right
|
80
|
+
# (delta_x) or up or down (delta_y) to compensate for any such defects.
|
81
|
+
#
|
82
|
+
# delta-x: 0
|
83
|
+
# delta-y: 0
|
84
|
+
|
85
|
+
# A file from which to read label texts, one per blank-line separated
|
86
|
+
# paragraph. A value of null here means no input file, and it would be
|
87
|
+
# unusual to define one in the configuration file, but if you wanted to you
|
88
|
+
# could put the path name here and labrat will perform ~ expansion on it.
|
89
|
+
# Relative paths are relative to the directory from which labrat is run.
|
90
|
+
#
|
91
|
+
# file: null
|
92
|
+
|
93
|
+
# A string sequence that is interpreted as a line-break can be defined. Such
|
94
|
+
# a sequence is particularly helpful when you provide the label text on the
|
95
|
+
# command-line, though it will be applied to file-read label texts as well.
|
96
|
+
# nlsep: '++'
|
97
|
+
|
98
|
+
# The name of the printer to use in substituting for the %p placeholder in the
|
99
|
+
# print-command setting below.
|
100
|
+
#
|
101
|
+
# printer: 'dymo'
|
102
|
+
|
103
|
+
# The file to write the pdf on. It is used in substituting for the %o
|
104
|
+
# placeholder in the print-command and view-command settings below.
|
105
|
+
#
|
106
|
+
# out-file: labrat.pdf
|
107
|
+
|
108
|
+
# These are the commands for printing and viewing the out-file. The
|
109
|
+
# view-command is something you may want to change, depending on your
|
110
|
+
# preferences, though qpdfview is quite good in that it provides a tabbed view
|
111
|
+
# and allows a unique instance to be dedicated to labrat with the --unique and
|
112
|
+
# --instance flags.
|
113
|
+
#
|
114
|
+
# print-command: lpr -P %p %o
|
115
|
+
# view-command: qpdfview --unique --instance labrat %o
|
116
|
+
|
117
|
+
# The following correspond to the -V, -T, and -v flags respectively.
|
118
|
+
#
|
119
|
+
# view: false
|
120
|
+
# template: false
|
121
|
+
# verbose: false
|