alexandria-book-collection-manager 0.7.2 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/ruby.yml +77 -0
- data/.gitignore +5 -1
- data/.hound.yml +2 -0
- data/.rubocop.yml +87 -37
- data/.rubocop_todo.yml +62 -191
- data/.simplecov +5 -2
- data/CHANGELOG.md +63 -0
- data/Gemfile +4 -3
- data/INSTALL.md +26 -14
- data/README.md +52 -42
- data/Rakefile +93 -109
- data/TODO.md +9 -1
- data/alexandria-book-collection-manager.gemspec +50 -43
- data/bin/alexandria +30 -53
- data/doc/FAQ +2 -6
- data/doc/dependency_decisions.yml +27 -8
- data/lib/alexandria.rb +27 -37
- data/lib/alexandria/about.rb +50 -50
- data/lib/alexandria/book_providers.rb +90 -97
- data/lib/alexandria/book_providers/adlibris.rb +41 -76
- data/lib/alexandria/book_providers/amazon_aws.rb +96 -100
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +295 -322
- data/lib/alexandria/book_providers/barnes_and_noble.rb +48 -45
- data/lib/alexandria/book_providers/douban.rb +26 -42
- data/lib/alexandria/book_providers/proxis.rb +44 -55
- data/lib/alexandria/book_providers/pseudomarc.rb +77 -85
- data/lib/alexandria/book_providers/siciliano.rb +64 -65
- data/lib/alexandria/book_providers/thalia.rb +42 -41
- data/lib/alexandria/book_providers/web.rb +15 -33
- data/lib/alexandria/book_providers/worldcat.rb +70 -97
- data/lib/alexandria/book_providers/z3950.rb +160 -173
- data/lib/alexandria/config.rb +1 -1
- data/lib/alexandria/console.rb +8 -21
- data/lib/alexandria/default_preferences.rb +37 -0
- data/lib/alexandria/execution_queue.rb +15 -13
- data/lib/alexandria/export_format.rb +47 -0
- data/lib/alexandria/export_library.rb +193 -300
- data/lib/alexandria/import_library.rb +108 -141
- data/lib/alexandria/import_library_csv.rb +43 -46
- data/lib/alexandria/library_collection.rb +79 -0
- data/lib/alexandria/library_sort_order.rb +45 -0
- data/lib/alexandria/library_store.rb +233 -0
- data/lib/alexandria/logging.rb +11 -13
- data/lib/alexandria/models/book.rb +13 -20
- data/lib/alexandria/models/library.rb +81 -353
- data/lib/alexandria/net.rb +5 -6
- data/lib/alexandria/preferences.rb +73 -87
- data/lib/alexandria/scanners.rb +2 -2
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +20 -18
- data/lib/alexandria/scanners/keyboard.rb +8 -8
- data/lib/alexandria/smart_library.rb +133 -170
- data/lib/alexandria/ui.rb +15 -15
- data/lib/alexandria/ui/about_dialog.rb +49 -0
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +119 -136
- data/lib/alexandria/ui/alert_dialog.rb +64 -0
- data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
- data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +16 -15
- data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +39 -52
- data/lib/alexandria/ui/book_properties_dialog_base.rb +318 -0
- data/lib/alexandria/ui/builder_base.rb +7 -27
- data/lib/alexandria/ui/calendar_popup.rb +58 -0
- data/lib/alexandria/ui/callbacks.rb +189 -183
- data/lib/alexandria/ui/completion_models.rb +10 -23
- data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
- data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
- data/lib/alexandria/ui/dndable.rb +7 -7
- data/lib/alexandria/ui/error_dialog.rb +25 -0
- data/lib/alexandria/ui/export_dialog.rb +142 -0
- data/lib/alexandria/ui/icons.rb +47 -63
- data/lib/alexandria/ui/iconview.rb +12 -10
- data/lib/alexandria/ui/iconview_tooltips.rb +41 -54
- data/lib/alexandria/ui/import_dialog.rb +157 -0
- data/lib/alexandria/ui/init.rb +21 -33
- data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
- data/lib/alexandria/ui/libraries_combo.rb +16 -14
- data/lib/alexandria/ui/listview.rb +73 -87
- data/lib/alexandria/ui/main_app.rb +24 -26
- data/lib/alexandria/ui/misc_dialogs.rb +10 -0
- data/lib/alexandria/ui/multi_drag_treeview.rb +28 -41
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +156 -194
- data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
- data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
- data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
- data/lib/alexandria/ui/preferences_dialog.rb +313 -0
- data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
- data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
- data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
- data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +56 -68
- data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
- data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
- data/lib/alexandria/ui/smart_library_properties_dialog_base.rb +242 -0
- data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
- data/lib/alexandria/ui/sound.rb +11 -13
- data/lib/alexandria/ui/ui_manager.rb +236 -251
- data/lib/alexandria/undo_manager.rb +1 -0
- data/lib/alexandria/version.rb +4 -19
- data/lib/alexandria/web_themes.rb +22 -21
- data/po/Makefile +2 -2
- data/po/cs.po +993 -880
- data/po/cy.po +957 -874
- data/po/de.po +990 -869
- data/po/el.po +989 -869
- data/po/es.po +985 -865
- data/po/fr.po +986 -870
- data/po/ga.po +907 -823
- data/po/gl.po +981 -865
- data/po/it.po +986 -868
- data/po/ja.po +969 -853
- data/po/mk.po +983 -863
- data/po/nb.po +979 -863
- data/po/nl.po +983 -864
- data/po/pl.po +1017 -974
- data/po/pt.po +988 -861
- data/po/pt_BR.po +984 -868
- data/po/ru.po +992 -873
- data/po/sk.po +987 -869
- data/po/sv.po +977 -861
- data/po/uk.po +975 -865
- data/po/zh_TW.po +976 -860
- data/schemas/alexandria.schemas +25 -3
- data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
- data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
- data/share/alexandria/glade/main_app__builder.glade +24 -33
- data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
- data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
- data/share/gnome/help/alexandria/C/introduction.xml +0 -8
- data/share/gnome/help/alexandria/C/searching.xml +1 -1
- data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
- data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
- data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
- data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
- data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
- data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
- data/spec/alexandria/book_providers_spec.rb +75 -171
- data/spec/alexandria/book_spec.rb +12 -10
- data/spec/alexandria/console_spec.rb +27 -0
- data/spec/alexandria/export_library_spec.rb +130 -0
- data/spec/alexandria/library_spec.rb +128 -172
- data/spec/alexandria/library_store_spec.rb +37 -0
- data/spec/alexandria/preferences_spec.rb +44 -17
- data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
- data/spec/alexandria/smart_library_spec.rb +30 -25
- data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/export_dialog_spec.rb +36 -0
- data/spec/alexandria/ui/icons_spec.rb +26 -0
- data/spec/alexandria/ui/iconview_spec.rb +7 -21
- data/spec/alexandria/ui/import_dialog_spec.rb +46 -0
- data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/main_app_spec.rb +7 -34
- data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
- data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
- data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
- data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
- data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
- data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
- data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +49 -0
- data/spec/alexandria/ui/sound_spec.rb +2 -2
- data/spec/alexandria/ui/ui_manager_spec.rb +43 -20
- data/spec/end_to_end/basic_run_spec.rb +52 -0
- data/spec/spec_helper.rb +65 -33
- data/tasks/setup.rb +2 -2
- data/tasks/spec.rake +16 -3
- data/util/rake/fileinstall.rb +39 -35
- data/util/rake/gettextgenerate.rb +7 -7
- data/util/rake/omfgenerate.rb +7 -7
- metadata +178 -45
- data/dogtail/basic_run_test.py +0 -9
- data/lib/alexandria/book_providers/deastore.rb +0 -265
- data/lib/alexandria/book_providers/mcu.rb +0 -182
- data/lib/alexandria/book_providers/renaud.rb +0 -149
- data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -61
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -72
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -51
- data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +0 -426
- data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
- data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
- data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -87
- data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -568
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -59
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +0 -420
- data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
- data/spec/alexandria/ui/dialogs_spec.rb +0 -96
- data/spec/alexandria/ui/sidepane_spec.rb +0 -29
- data/spec/alexandria/ui/ui_utilities_spec.rb +0 -62
- data/spec/alexandria/utilities_spec.rb +0 -52
- data/tasks/dogtail.rake +0 -6
data/lib/alexandria/net.rb
CHANGED
@@ -24,7 +24,7 @@ module Alexandria
|
|
24
24
|
class WWWAgent
|
25
25
|
def initialize
|
26
26
|
user_agent = "Ruby #{RUBY_VERSION} #{Alexandria::TITLE}/#{Alexandria::VERSION}"
|
27
|
-
@extra_request_headers = {
|
27
|
+
@extra_request_headers = { "User-Agent" => user_agent }
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.transport
|
@@ -38,18 +38,17 @@ module Alexandria
|
|
38
38
|
@extra_request_headers.each_pair do |header_name, value|
|
39
39
|
req.add_field(header_name, value)
|
40
40
|
end
|
41
|
-
|
41
|
+
WWWAgent.transport.start(uri.host, uri.port) do |http|
|
42
42
|
http.request(req)
|
43
|
-
|
44
|
-
res
|
43
|
+
end
|
45
44
|
end
|
46
45
|
|
47
46
|
def language=(lang)
|
48
|
-
@extra_request_headers[
|
47
|
+
@extra_request_headers["Accept-Language"] = lang.to_s
|
49
48
|
end
|
50
49
|
|
51
50
|
def user_agent=(agent_string)
|
52
|
-
@extra_request_headers[
|
51
|
+
@extra_request_headers["User-Agent"] = agent_string
|
53
52
|
end
|
54
53
|
end
|
55
54
|
end
|
@@ -1,39 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
# Copyright (C) 2011 Cathal Mc Ginley
|
5
|
-
# Copyright (C) 2011, 2016 Matijs van Zuijlen
|
3
|
+
# This file is part of Alexandria.
|
6
4
|
#
|
7
|
-
#
|
8
|
-
# modify it under the terms of the GNU General Public License as
|
9
|
-
# published by the Free Software Foundation; either version 2 of the
|
10
|
-
# License, or (at your option) any later version.
|
11
|
-
#
|
12
|
-
# Alexandria is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
-
# General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public
|
18
|
-
# License along with Alexandria; see the file COPYING. If not,
|
19
|
-
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
20
|
-
# Fifth Floor, Boston, MA 02110-1301 USA.
|
5
|
+
# See the file README.md for authorship and licensing information.
|
21
6
|
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
7
|
+
require "singleton"
|
8
|
+
require "set"
|
9
|
+
require "alexandria/default_preferences"
|
25
10
|
|
26
11
|
module Alexandria
|
27
12
|
class Preferences
|
28
13
|
include Singleton
|
29
14
|
include Logging
|
30
15
|
|
31
|
-
APP_DIR =
|
32
|
-
HTTP_PROXY_DIR =
|
33
|
-
HTTP_PROXY_MODE =
|
34
|
-
URL_HANDLERS_DIR =
|
16
|
+
APP_DIR = "/apps/alexandria"
|
17
|
+
HTTP_PROXY_DIR = "/system/http_proxy"
|
18
|
+
HTTP_PROXY_MODE = "/system/proxy/mode"
|
19
|
+
URL_HANDLERS_DIR = "/desktop/gnome/url-handlers"
|
35
20
|
|
36
|
-
GCONFTOOL =
|
21
|
+
GCONFTOOL = "gconftool-2"
|
37
22
|
|
38
23
|
def initialize
|
39
24
|
@alexandria_settings = {}
|
@@ -61,38 +46,35 @@ module Alexandria
|
|
61
46
|
end
|
62
47
|
|
63
48
|
def save!
|
64
|
-
log.debug {
|
49
|
+
log.debug { "preferences save!" }
|
65
50
|
@changed_settings.each do |variable_name|
|
66
|
-
log.debug
|
51
|
+
log.debug do
|
52
|
+
klass = @alexandria_settings[variable_name].class
|
53
|
+
"saving preference #{variable_name} / #{klass}"
|
54
|
+
end
|
67
55
|
generic_save_setting(variable_name, @alexandria_settings[variable_name])
|
68
56
|
end
|
69
57
|
@changed_settings.clear
|
70
58
|
end
|
71
59
|
|
72
|
-
def method_missing(id, *args)
|
73
|
-
method = id.id2name
|
74
|
-
if (match = /(.*)=$/.match(method))
|
75
|
-
if args.length != 1
|
76
|
-
raise "Set method #{method} should be called with " \
|
77
|
-
"only one argument (was called with #{args.length})"
|
78
|
-
end
|
79
|
-
variable_name = match[1]
|
80
|
-
new_value = args.first
|
81
|
-
generic_setter(variable_name, new_value)
|
82
|
-
else
|
83
|
-
unless args.empty?
|
84
|
-
raise "Get method #{method} should be called " \
|
85
|
-
"without argument (was called with #{args.length})"
|
86
|
-
end
|
87
|
-
generic_getter(method)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
60
|
def remove_preference(variable_name)
|
92
61
|
@alexandria_settings.delete(variable_name)
|
93
62
|
@changed_settings << variable_name
|
94
63
|
end
|
95
64
|
|
65
|
+
DEFAULT_VALUES.each_key do |var|
|
66
|
+
define_method(var) { generic_getter var }
|
67
|
+
define_method("#{var}=") { |val| generic_setter var, val }
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_variable(variable_name)
|
71
|
+
generic_getter(variable_name.to_s)
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_variable(variable_name, value)
|
75
|
+
generic_setter(variable_name.to_s, value)
|
76
|
+
end
|
77
|
+
|
96
78
|
private
|
97
79
|
|
98
80
|
##
|
@@ -122,7 +104,7 @@ module Alexandria
|
|
122
104
|
end
|
123
105
|
|
124
106
|
def generic_save_setting(variable_name, new_value)
|
125
|
-
var_path = APP_DIR +
|
107
|
+
var_path = APP_DIR + "/" + variable_name
|
126
108
|
if new_value.is_a?(Array)
|
127
109
|
# when setting array, first remove nil elements (fixing #9007)
|
128
110
|
new_value.compact!
|
@@ -132,17 +114,17 @@ module Alexandria
|
|
132
114
|
# set list value
|
133
115
|
exec_gconf_set_list(var_path, new_value)
|
134
116
|
end
|
117
|
+
elsif new_value.nil?
|
118
|
+
exec_gconf_unset(variable_name)
|
135
119
|
else
|
136
120
|
# set non-list value
|
137
|
-
|
138
|
-
exec_gconf_unset(variable_name)
|
139
|
-
else
|
140
|
-
exec_gconf_set(var_path, new_value)
|
141
|
-
end
|
121
|
+
exec_gconf_set(var_path, new_value)
|
142
122
|
end
|
143
|
-
rescue => ex
|
123
|
+
rescue StandardError => ex
|
144
124
|
log.debug { new_value.inspect }
|
145
|
-
log.error
|
125
|
+
log.error do
|
126
|
+
"Could not set GConf setting #{variable_name} to value: #{new_value.inspect}"
|
127
|
+
end
|
146
128
|
log << ex.message
|
147
129
|
log << ex
|
148
130
|
end
|
@@ -152,14 +134,15 @@ module Alexandria
|
|
152
134
|
##
|
153
135
|
|
154
136
|
def get_gconf_type(value)
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
137
|
+
case value
|
138
|
+
when String
|
139
|
+
"string"
|
140
|
+
when Integer
|
141
|
+
"int"
|
142
|
+
when TrueClass, FalseClass
|
143
|
+
"bool"
|
161
144
|
else
|
162
|
-
|
145
|
+
"string"
|
163
146
|
end
|
164
147
|
end
|
165
148
|
|
@@ -167,7 +150,7 @@ module Alexandria
|
|
167
150
|
# NOTE we must check between list and pair...
|
168
151
|
|
169
152
|
list_type = get_gconf_type(new_list.first)
|
170
|
-
if list_type ==
|
153
|
+
if list_type == "int" && new_list.size == 2
|
171
154
|
# treat this as a pair of int
|
172
155
|
a = new_list[0]
|
173
156
|
b = new_list[1]
|
@@ -180,29 +163,29 @@ module Alexandria
|
|
180
163
|
end
|
181
164
|
|
182
165
|
def make_list_string(list)
|
183
|
-
list.map! { |x| x.gsub(
|
184
|
-
contents = list.join(
|
185
|
-
|
166
|
+
list.map! { |x| x.gsub(/"/, '\\"') } if get_gconf_type(list.first) == "string"
|
167
|
+
contents = list.join(",")
|
168
|
+
"[" + contents + "]"
|
186
169
|
end
|
187
170
|
|
188
171
|
def exec_gconf_set(var_path, new_value)
|
189
|
-
if /cols_width
|
190
|
-
|
172
|
+
if /cols_width/.match?(var_path)
|
173
|
+
log.debug { new_value }
|
191
174
|
|
192
175
|
# new_value = {}
|
193
176
|
end
|
194
177
|
type = get_gconf_type(new_value)
|
195
178
|
value_str = new_value
|
196
179
|
if new_value.is_a? String
|
197
|
-
new_value.gsub
|
180
|
+
new_value = new_value.gsub(/"/, '\\"')
|
198
181
|
value_str = "\"#{new_value}\""
|
199
182
|
end
|
200
|
-
|
183
|
+
log.debug { value_str } if /cols_width/.match?(var_path)
|
201
184
|
`gconftool-2 --type #{type} --set #{var_path} #{value_str}`
|
202
185
|
end
|
203
186
|
|
204
187
|
def exec_gconf_unset(variable_name)
|
205
|
-
`#{GCONFTOOL} --unset #{APP_DIR +
|
188
|
+
`#{GCONFTOOL} --unset #{APP_DIR + "/" + variable_name}`
|
206
189
|
end
|
207
190
|
|
208
191
|
##
|
@@ -222,14 +205,14 @@ module Alexandria
|
|
222
205
|
def load_http_proxy_settings
|
223
206
|
http_proxy_vars = `#{GCONFTOOL} --recursive-list #{HTTP_PROXY_DIR}`
|
224
207
|
http_proxy = gconftool_values_to_hash(http_proxy_vars)
|
225
|
-
if http_proxy[
|
208
|
+
if http_proxy["use_http_proxy"]
|
226
209
|
proxy_mode = `#{GCONFTOOL} --get #{HTTP_PROXY_MODE}`.chomp
|
227
|
-
if proxy_mode ==
|
210
|
+
if proxy_mode == "manual"
|
228
211
|
@use_http_proxy = true
|
229
|
-
@proxy_host = http_proxy[
|
230
|
-
@proxy_port = http_proxy[
|
231
|
-
@proxy_user = http_proxy[
|
232
|
-
@proxy_password = http_proxy[
|
212
|
+
@proxy_host = http_proxy["host"]
|
213
|
+
@proxy_port = http_proxy["port"]
|
214
|
+
@proxy_user = http_proxy["authentication_user"]
|
215
|
+
@proxy_password = http_proxy["authentication_n_password"]
|
233
216
|
end
|
234
217
|
end
|
235
218
|
@http_proxy_loaded = true
|
@@ -243,7 +226,9 @@ module Alexandria
|
|
243
226
|
hash = {}
|
244
227
|
vals = all_vals.split(/$/)
|
245
228
|
vals.each do |val|
|
246
|
-
|
229
|
+
if /([a-z_]+) = (.*)/ =~ val
|
230
|
+
hash[Regexp.last_match[1]] = discriminate(Regexp.last_match[2])
|
231
|
+
end
|
247
232
|
end
|
248
233
|
hash
|
249
234
|
end
|
@@ -252,20 +237,21 @@ module Alexandria
|
|
252
237
|
# gconftool. This is not fool-proof, but it *does* work for the
|
253
238
|
# range of values used by Alexandria.
|
254
239
|
def discriminate(value)
|
255
|
-
|
240
|
+
case value
|
241
|
+
when "true" # bool
|
256
242
|
true
|
257
|
-
|
243
|
+
when "false" # bool
|
258
244
|
false
|
259
|
-
|
245
|
+
when /^[0-9]+$/ # int
|
260
246
|
value.to_i
|
261
|
-
|
262
|
-
Regexp.last_match[1].split(
|
263
|
-
|
247
|
+
when /^\[(.*)\]$/ # list (assume of type String)
|
248
|
+
Regexp.last_match[1].split(",")
|
249
|
+
when /^\((.*)\)$/ # pair (assume of type int)
|
264
250
|
begin
|
265
|
-
pair = Regexp.last_match[1].split(
|
266
|
-
|
267
|
-
rescue
|
268
|
-
|
251
|
+
pair = Regexp.last_match[1].split(",")
|
252
|
+
[discriminate(pair.first), discriminate(pair.last)]
|
253
|
+
rescue StandardError
|
254
|
+
[0, 0]
|
269
255
|
end
|
270
256
|
else
|
271
257
|
value # string
|
data/lib/alexandria/scanners.rb
CHANGED
@@ -18,28 +18,30 @@
|
|
18
18
|
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
19
19
|
# Fifth Floor, Boston, MA 02110-1301 USA.
|
20
20
|
|
21
|
-
require
|
21
|
+
require "alexandria/scanners"
|
22
22
|
|
23
23
|
module Alexandria
|
24
24
|
module Scanners
|
25
25
|
class CueCat
|
26
|
-
include
|
26
|
+
include Logging
|
27
27
|
|
28
28
|
def name
|
29
|
-
|
29
|
+
"CueCat"
|
30
30
|
end
|
31
31
|
|
32
32
|
def display_name
|
33
|
-
|
33
|
+
"CueCat"
|
34
34
|
end
|
35
35
|
|
36
36
|
# Checks if data looks like cuecat input
|
37
37
|
def match?(data)
|
38
38
|
data = data.chomp
|
39
|
-
return false if data[-1] !=
|
40
|
-
|
39
|
+
return false if data[-1] != "."
|
40
|
+
|
41
|
+
fields = data.split(".")
|
41
42
|
return false if fields.size != 4
|
42
43
|
return false if fields[2].size != 4
|
44
|
+
|
43
45
|
true
|
44
46
|
end
|
45
47
|
|
@@ -48,13 +50,13 @@ module Alexandria
|
|
48
50
|
# domain perl implementation.
|
49
51
|
def decode(data)
|
50
52
|
data = data.chomp
|
51
|
-
fields = data.split(
|
53
|
+
fields = data.split(".")
|
52
54
|
fields.shift # First part is gibberish
|
53
55
|
fields.shift # Second part is cuecat serial number
|
54
56
|
type, code = fields.map { |field| decode_field(field) }
|
55
57
|
|
56
|
-
if type ==
|
57
|
-
type =
|
58
|
+
if type == "IB5"
|
59
|
+
type = "IBN"
|
58
60
|
code = code[0, 13]
|
59
61
|
end
|
60
62
|
|
@@ -62,33 +64,33 @@ module Alexandria
|
|
62
64
|
if Library.valid_upc? code
|
63
65
|
isbn13 = Library.canonicalise_ean(code)
|
64
66
|
code = isbn13
|
65
|
-
type =
|
67
|
+
type = "IBN"
|
66
68
|
end
|
67
|
-
rescue
|
69
|
+
rescue StandardError
|
68
70
|
log.debug { "Cannot translate UPC (#{type}) code #{code} to ISBN" }
|
69
71
|
end
|
70
72
|
|
71
|
-
return code if type ==
|
73
|
+
return code if type == "IBN"
|
72
74
|
|
73
|
-
raise "Don't know how to handle type
|
75
|
+
raise format(_("Don't know how to handle type %<type>s (barcode: %<code>s)"),
|
76
|
+
type: type, code: code)
|
74
77
|
end
|
75
78
|
|
76
79
|
private
|
77
80
|
|
78
81
|
def decode_field(encoded)
|
79
|
-
seq =
|
82
|
+
seq = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-"
|
80
83
|
|
81
84
|
chars = encoded.split(//)
|
82
85
|
values = chars.map { |c| seq.index(c) }
|
83
86
|
|
84
87
|
padding = pad(values)
|
85
88
|
result = calc(values)
|
86
|
-
result
|
87
|
-
result
|
89
|
+
result[0, result.length - padding]
|
88
90
|
end
|
89
91
|
|
90
92
|
def calc(values)
|
91
|
-
result =
|
93
|
+
result = ""
|
92
94
|
until values.empty?
|
93
95
|
num = ((values[0] << 6 | values[1]) << 6 | values[2]) << 6 | values[3]
|
94
96
|
result += ((num >> 16) ^ 67).chr
|
@@ -104,7 +106,7 @@ module Alexandria
|
|
104
106
|
length = array.length % 4
|
105
107
|
|
106
108
|
if length.nonzero?
|
107
|
-
raise
|
109
|
+
raise _("Error parsing CueCat input") if length == 1
|
108
110
|
|
109
111
|
length = 4 - length
|
110
112
|
length.times { array.push(0) }
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
19
19
|
# Fifth Floor, Boston, MA 02110-1301 USA.
|
20
20
|
|
21
|
-
require
|
21
|
+
require "alexandria/scanners"
|
22
22
|
|
23
23
|
module Alexandria
|
24
24
|
module Scanners
|
@@ -27,28 +27,28 @@ module Alexandria
|
|
27
27
|
# like this.)
|
28
28
|
class KeyboardWedge
|
29
29
|
def name
|
30
|
-
|
30
|
+
"KeyboardWedge"
|
31
31
|
end
|
32
32
|
|
33
33
|
def display_name
|
34
|
-
|
34
|
+
"Keyboard Wedge"
|
35
35
|
end
|
36
36
|
|
37
37
|
# Checks if data looks like a completed scan
|
38
38
|
def match?(data)
|
39
|
-
data.gsub!(/\s/,
|
39
|
+
data.gsub!(/\s/, "")
|
40
40
|
(data =~ /[0-9]{12,18}/) || (data =~ /[0-9]{9}[0-9Xx]/)
|
41
41
|
end
|
42
42
|
|
43
43
|
# Gets the essential 13-digits from an ISBN barcode (EAN-13)
|
44
44
|
def decode(data)
|
45
|
-
data.gsub!(/\s/,
|
45
|
+
data.gsub!(/\s/, "")
|
46
46
|
if data.length == 10
|
47
|
-
|
47
|
+
data
|
48
48
|
elsif data.length >= 13
|
49
|
-
|
49
|
+
data[0, 13]
|
50
50
|
else
|
51
|
-
raise "Unknown scan data
|
51
|
+
raise format(_("Unknown scan data %s<data>"), data: data)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|