alexandria-book-collection-manager 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -25
- data/.rubocop_todo.yml +87 -67
- data/CHANGELOG.md +12 -1
- data/Gemfile +4 -3
- data/README.md +16 -6
- data/Rakefile +71 -72
- data/alexandria-book-collection-manager.gemspec +44 -44
- data/bin/alexandria +12 -12
- data/lib/alexandria.rb +22 -22
- data/lib/alexandria/about.rb +50 -50
- data/lib/alexandria/book_providers.rb +50 -50
- data/lib/alexandria/book_providers/adlibris.rb +28 -44
- data/lib/alexandria/book_providers/amazon_aws.rb +64 -64
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +52 -78
- data/lib/alexandria/book_providers/barnes_and_noble.rb +34 -34
- data/lib/alexandria/book_providers/douban.rb +21 -37
- data/lib/alexandria/book_providers/proxis.rb +24 -24
- data/lib/alexandria/book_providers/pseudomarc.rb +19 -19
- data/lib/alexandria/book_providers/renaud.rb +44 -57
- data/lib/alexandria/book_providers/siciliano.rb +39 -39
- data/lib/alexandria/book_providers/thalia.rb +33 -33
- data/lib/alexandria/book_providers/web.rb +5 -5
- data/lib/alexandria/book_providers/worldcat.rb +44 -69
- data/lib/alexandria/book_providers/z3950.rb +94 -109
- data/lib/alexandria/config.rb +1 -1
- data/lib/alexandria/console.rb +3 -3
- data/lib/alexandria/export_format.rb +8 -8
- data/lib/alexandria/export_library.rb +112 -113
- data/lib/alexandria/import_library.rb +45 -45
- data/lib/alexandria/import_library_csv.rb +30 -30
- data/lib/alexandria/library_collection.rb +4 -4
- data/lib/alexandria/library_sort_order.rb +1 -1
- data/lib/alexandria/library_store.rb +14 -14
- data/lib/alexandria/logging.rb +5 -5
- data/lib/alexandria/models/book.rb +1 -1
- data/lib/alexandria/models/library.rb +36 -36
- data/lib/alexandria/net.rb +5 -5
- data/lib/alexandria/preferences.rb +32 -32
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +13 -13
- data/lib/alexandria/scanners/keyboard.rb +5 -5
- data/lib/alexandria/smart_library.rb +53 -53
- data/lib/alexandria/ui.rb +15 -15
- data/lib/alexandria/ui/{dialogs/about_dialog.rb → about_dialog.rb} +1 -1
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +66 -65
- data/lib/alexandria/ui/{dialogs/alert_dialog.rb → alert_dialog.rb} +1 -16
- data/lib/alexandria/ui/{dialogs/bad_isbns_dialog.rb → bad_isbns_dialog.rb} +0 -0
- data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +7 -7
- data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +25 -37
- data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +38 -37
- data/lib/alexandria/ui/builder_base.rb +1 -1
- data/lib/alexandria/ui/callbacks.rb +95 -91
- data/lib/alexandria/ui/completion_models.rb +7 -21
- 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/{dialogs/export_dialog.rb → export_dialog.rb} +22 -42
- data/lib/alexandria/ui/icons.rb +6 -6
- data/lib/alexandria/ui/iconview.rb +7 -7
- data/lib/alexandria/ui/iconview_tooltips.rb +6 -6
- data/lib/alexandria/ui/{dialogs/import_dialog.rb → import_dialog.rb} +14 -32
- data/lib/alexandria/ui/init.rb +16 -29
- data/lib/alexandria/ui/{dialogs/keep_bad_isbn_dialog.rb → keep_bad_isbn_dialog.rb} +6 -4
- data/lib/alexandria/ui/libraries_combo.rb +7 -7
- data/lib/alexandria/ui/listview.rb +40 -40
- data/lib/alexandria/ui/main_app.rb +22 -24
- data/lib/alexandria/ui/misc_dialogs.rb +10 -0
- data/lib/alexandria/ui/multi_drag_treeview.rb +4 -4
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +46 -45
- data/lib/alexandria/ui/{dialogs/new_book_dialog_manual.rb → new_book_dialog_manual.rb} +20 -19
- data/lib/alexandria/ui/new_provider_dialog.rb +99 -0
- data/lib/alexandria/ui/{dialogs/new_smart_library_dialog.rb → new_smart_library_dialog.rb} +4 -4
- data/lib/alexandria/ui/{dialogs/preferences_dialog.rb → preferences_dialog.rb} +44 -235
- data/lib/alexandria/ui/provider_preferences_base_dialog.rb +90 -0
- data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
- data/lib/alexandria/ui/{dialogs/misc_dialogs.rb → really_delete_dialog.rb} +6 -27
- data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +27 -25
- data/lib/alexandria/ui/skip_entry_dialog.rb +32 -0
- data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog.rb → smart_library_properties_dialog.rb} +2 -2
- data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +30 -30
- data/lib/alexandria/ui/sound.rb +8 -8
- data/lib/alexandria/ui/ui_manager.rb +136 -135
- data/lib/alexandria/version.rb +4 -19
- data/lib/alexandria/web_themes.rb +8 -8
- data/po/cs.po +97 -97
- data/po/cy.po +97 -97
- data/po/de.po +97 -97
- data/po/el.po +97 -97
- data/po/es.po +97 -97
- data/po/fr.po +97 -97
- data/po/ga.po +97 -97
- data/po/gl.po +97 -97
- data/po/it.po +97 -97
- data/po/ja.po +97 -97
- data/po/mk.po +97 -97
- data/po/nb.po +97 -97
- data/po/nl.po +97 -97
- data/po/pl.po +97 -97
- data/po/pt.po +97 -97
- data/po/pt_BR.po +97 -97
- data/po/ru.po +97 -97
- data/po/sk.po +97 -97
- data/po/sv.po +97 -97
- data/po/uk.po +97 -97
- data/po/zh_TW.po +97 -97
- data/schemas/alexandria.schemas +24 -2
- data/spec/alexandria/book_providers_spec.rb +65 -82
- data/spec/alexandria/book_spec.rb +12 -10
- data/spec/alexandria/console_spec.rb +9 -9
- data/spec/alexandria/export_library_spec.rb +31 -31
- data/spec/alexandria/library_spec.rb +86 -86
- data/spec/alexandria/library_store_spec.rb +8 -8
- data/spec/alexandria/preferences_spec.rb +18 -17
- data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
- data/spec/alexandria/smart_library_spec.rb +15 -15
- 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 +15 -0
- data/spec/alexandria/ui/iconview_spec.rb +7 -21
- data/spec/alexandria/ui/import_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/main_app_spec.rb +6 -6
- data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
- data/spec/alexandria/ui/{dialogs/new_book_dialog_spec.rb → new_book_dialog_spec.rb} +4 -4
- data/spec/alexandria/ui/new_provider_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +19 -0
- data/spec/alexandria/ui/really_delete_dialog_spec.rb +15 -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 +18 -0
- data/spec/alexandria/ui/sound_spec.rb +2 -2
- data/spec/alexandria/ui/ui_manager_spec.rb +6 -20
- data/spec/alexandria/ui/ui_utilities_spec.rb +9 -9
- data/spec/alexandria/utilities_spec.rb +6 -6
- data/spec/end_to_end/basic_run_spec.rb +24 -36
- data/spec/spec_helper.rb +9 -9
- data/tasks/dogtail.rake +1 -1
- data/tasks/setup.rb +2 -2
- data/tasks/spec.rake +11 -11
- data/util/rake/fileinstall.rb +25 -25
- data/util/rake/gettextgenerate.rb +7 -7
- data/util/rake/omfgenerate.rb +7 -7
- metadata +59 -33
- data/spec/alexandria/scanners/cuecat_spec.rb +0 -67
- data/spec/alexandria/ui/dialogs_spec.rb +0 -162
- data/spec/alexandria/ui/sidepane_spec.rb +0 -29
data/lib/alexandria/logging.rb
CHANGED
@@ -18,8 +18,8 @@
|
|
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
|
22
|
-
require
|
21
|
+
require "logger"
|
22
|
+
require "forwardable"
|
23
23
|
|
24
24
|
module Alexandria
|
25
25
|
# A Logger subclass which accepts a source for log messages
|
@@ -82,9 +82,9 @@ module Alexandria
|
|
82
82
|
|
83
83
|
def <<(msg)
|
84
84
|
if msg.respond_to? :backtrace
|
85
|
-
msg.backtrace.each
|
85
|
+
msg.backtrace.each do |line|
|
86
86
|
@logger << " #{line} \n"
|
87
|
-
|
87
|
+
end
|
88
88
|
else
|
89
89
|
@logger << msg + "\n"
|
90
90
|
end
|
@@ -137,7 +137,7 @@ module Alexandria
|
|
137
137
|
def self.create_logger
|
138
138
|
logger = Alexandria::Logger.new(STDERR)
|
139
139
|
|
140
|
-
level = ENV[
|
140
|
+
level = ENV["LOGLEVEL"] ? ENV["LOGLEVEL"].intern : nil
|
141
141
|
if [:FATAL, :ERROR, :WARN, :INFO, :DEBUG].include? level
|
142
142
|
logger.level = Logger.const_get(level)
|
143
143
|
else
|
@@ -4,12 +4,12 @@
|
|
4
4
|
#
|
5
5
|
# See the file README.md for authorship and licensing information.
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
7
|
+
require "yaml"
|
8
|
+
require "fileutils"
|
9
|
+
require "rexml/document"
|
10
|
+
require "tempfile"
|
11
|
+
require "etc"
|
12
|
+
require "alexandria/library_store"
|
13
13
|
|
14
14
|
module Alexandria
|
15
15
|
class Library < Array
|
@@ -17,12 +17,12 @@ module Alexandria
|
|
17
17
|
|
18
18
|
attr_reader :name
|
19
19
|
attr_accessor :ruined_books, :updating, :deleted_books
|
20
|
-
DEFAULT_DIR = File.join(ENV[
|
21
|
-
EXT = { book:
|
20
|
+
DEFAULT_DIR = File.join(ENV["HOME"], ".alexandria")
|
21
|
+
EXT = { book: ".yaml", cover: ".cover" }.freeze
|
22
22
|
|
23
23
|
include GetText
|
24
24
|
extend GetText
|
25
|
-
bindtextdomain(Alexandria::TEXTDOMAIN, charset:
|
25
|
+
bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
|
26
26
|
|
27
27
|
BOOK_ADDED, BOOK_UPDATED, BOOK_REMOVED = (0..3).to_a
|
28
28
|
include Observable
|
@@ -36,7 +36,7 @@ module Alexandria
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.generate_new_name(existing_libraries,
|
39
|
-
from_base = _(
|
39
|
+
from_base = _("Untitled"))
|
40
40
|
i = 1
|
41
41
|
name = nil
|
42
42
|
all_libraries = existing_libraries + @@deleted_libraries
|
@@ -71,11 +71,11 @@ module Alexandria
|
|
71
71
|
def self.extract_numbers(entry)
|
72
72
|
return [] if entry.nil? || entry.empty?
|
73
73
|
|
74
|
-
normalized = entry.delete(
|
75
|
-
return [] unless
|
74
|
+
normalized = entry.delete("- ").upcase
|
75
|
+
return [] unless /\A[\dX]*\Z/.match?(normalized)
|
76
76
|
|
77
|
-
normalized.split(
|
78
|
-
char ==
|
77
|
+
normalized.split("").map do |char|
|
78
|
+
char == "X" ? 10 : char.to_i
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -84,7 +84,7 @@ module Alexandria
|
|
84
84
|
accumulator + numbers[i] * (i + 1)
|
85
85
|
end % 11
|
86
86
|
|
87
|
-
sum == 10 ?
|
87
|
+
sum == 10 ? "X" : sum
|
88
88
|
end
|
89
89
|
|
90
90
|
def self.valid_isbn?(isbn)
|
@@ -117,18 +117,18 @@ module Alexandria
|
|
117
117
|
end
|
118
118
|
|
119
119
|
AMERICAN_UPC_LOOKUP = {
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
120
|
+
"014794" => "08041", "018926" => "0445", "02778" => "0449",
|
121
|
+
"037145" => "0812", "042799" => "0785", "043144" => "0688",
|
122
|
+
"044903" => "0312", "045863" => "0517", "046594" => "0064",
|
123
|
+
"047132" => "0152", "051487" => "08167", "051488" => "0140",
|
124
|
+
"060771" => "0002", "065373" => "0373", "070992" => "0523",
|
125
|
+
"070993" => "0446", "070999" => "0345", "071001" => "0380",
|
126
|
+
"071009" => "0440", "071125" => "088677", "071136" => "0451",
|
127
|
+
"071149" => "0451", "071152" => "0515", "071162" => "0451",
|
128
|
+
"071268" => "08217", "071831" => "0425", "071842" => "08439",
|
129
|
+
"072742" => "0441", "076714" => "0671", "076783" => "0553",
|
130
|
+
"076814" => "0449", "078021" => "0872", "079808" => "0394",
|
131
|
+
"090129" => "0679", "099455" => "0061", "099769" => "0451"
|
132
132
|
}.freeze
|
133
133
|
|
134
134
|
def self.upc_convert(upc)
|
@@ -137,15 +137,15 @@ module Alexandria
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def self.canonicalise_ean(code)
|
140
|
-
code = code.to_s.delete(
|
140
|
+
code = code.to_s.delete("- ")
|
141
141
|
if valid_ean?(code)
|
142
142
|
code
|
143
143
|
elsif valid_isbn?(code)
|
144
|
-
code =
|
144
|
+
code = "978" + code[0..8]
|
145
145
|
code + String(ean_checksum(extract_numbers(code)))
|
146
146
|
elsif valid_upc?(code)
|
147
147
|
isbn10 = canonicalise_isbn
|
148
|
-
code =
|
148
|
+
code = "978" + isbn10[0..8]
|
149
149
|
code + String(ean_checksum(extract_numbers(code)))
|
150
150
|
end
|
151
151
|
end
|
@@ -185,8 +185,8 @@ module Alexandria
|
|
185
185
|
end
|
186
186
|
book.saved_ident = book.ident
|
187
187
|
|
188
|
-
filename = book.saved_ident.to_s +
|
189
|
-
File.open(filename,
|
188
|
+
filename = book.saved_ident.to_s + ".yaml"
|
189
|
+
File.open(filename, "w") { |io| io.puts book.to_yaml }
|
190
190
|
filename
|
191
191
|
end
|
192
192
|
|
@@ -212,7 +212,7 @@ module Alexandria
|
|
212
212
|
|
213
213
|
temp_book = book.dup
|
214
214
|
temp_book.library = nil
|
215
|
-
File.open(yaml(temp_book),
|
215
|
+
File.open(yaml(temp_book), "w") { |io| io.puts temp_book.to_yaml }
|
216
216
|
|
217
217
|
# Do not notify twice.
|
218
218
|
if changed?
|
@@ -231,7 +231,7 @@ module Alexandria
|
|
231
231
|
Dir.chdir(path) do
|
232
232
|
# Fetch the cover picture.
|
233
233
|
cover_file = cover(book)
|
234
|
-
File.open(cover_file,
|
234
|
+
File.open(cover_file, "w") do |io|
|
235
235
|
uri = URI.parse(cover_uri)
|
236
236
|
if uri.scheme.nil?
|
237
237
|
# Regular filename.
|
@@ -388,12 +388,12 @@ module Alexandria
|
|
388
388
|
end
|
389
389
|
|
390
390
|
def self.jpeg?(file)
|
391
|
-
IO.read(file, 10)[6..9] ==
|
391
|
+
IO.read(file, 10)[6..9] == "JFIF"
|
392
392
|
end
|
393
393
|
|
394
394
|
def final_cover(book)
|
395
395
|
# TODO: what about PNG?
|
396
|
-
book.ident + (Library.jpeg?(cover(book)) ?
|
396
|
+
book.ident + (Library.jpeg?(cover(book)) ? ".jpg" : ".gif")
|
397
397
|
end
|
398
398
|
|
399
399
|
protected
|
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,18 @@ 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
|
-
res = WWWAgent.transport.start(uri.host, uri.port)
|
41
|
+
res = WWWAgent.transport.start(uri.host, uri.port) do |http|
|
42
42
|
http.request(req)
|
43
|
-
|
43
|
+
end
|
44
44
|
res
|
45
45
|
end
|
46
46
|
|
47
47
|
def language=(lang)
|
48
|
-
@extra_request_headers[
|
48
|
+
@extra_request_headers["Accept-Language"] = lang.to_s
|
49
49
|
end
|
50
50
|
|
51
51
|
def user_agent=(agent_string)
|
52
|
-
@extra_request_headers[
|
52
|
+
@extra_request_headers["User-Agent"] = agent_string
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -4,21 +4,21 @@
|
|
4
4
|
#
|
5
5
|
# See the file README.md for authorship and licensing information.
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
7
|
+
require "singleton"
|
8
|
+
require "set"
|
9
|
+
require "alexandria/default_preferences"
|
10
10
|
|
11
11
|
module Alexandria
|
12
12
|
class Preferences
|
13
13
|
include Singleton
|
14
14
|
include Logging
|
15
15
|
|
16
|
-
APP_DIR =
|
17
|
-
HTTP_PROXY_DIR =
|
18
|
-
HTTP_PROXY_MODE =
|
19
|
-
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"
|
20
20
|
|
21
|
-
GCONFTOOL =
|
21
|
+
GCONFTOOL = "gconftool-2"
|
22
22
|
|
23
23
|
def initialize
|
24
24
|
@alexandria_settings = {}
|
@@ -46,7 +46,7 @@ module Alexandria
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def save!
|
49
|
-
log.debug {
|
49
|
+
log.debug { "preferences save!" }
|
50
50
|
@changed_settings.each do |variable_name|
|
51
51
|
log.debug { "saving preference #{variable_name} / #{@alexandria_settings[variable_name].class}" }
|
52
52
|
generic_save_setting(variable_name, @alexandria_settings[variable_name])
|
@@ -107,7 +107,7 @@ module Alexandria
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def generic_save_setting(variable_name, new_value)
|
110
|
-
var_path = APP_DIR +
|
110
|
+
var_path = APP_DIR + "/" + variable_name
|
111
111
|
if new_value.is_a?(Array)
|
112
112
|
# when setting array, first remove nil elements (fixing #9007)
|
113
113
|
new_value.compact!
|
@@ -136,13 +136,13 @@ module Alexandria
|
|
136
136
|
|
137
137
|
def get_gconf_type(value)
|
138
138
|
if value.is_a?(String)
|
139
|
-
|
139
|
+
"string"
|
140
140
|
elsif value.is_a?(Integer)
|
141
|
-
|
141
|
+
"int"
|
142
142
|
elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
143
|
-
|
143
|
+
"bool"
|
144
144
|
else
|
145
|
-
|
145
|
+
"string"
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -150,7 +150,7 @@ module Alexandria
|
|
150
150
|
# NOTE we must check between list and pair...
|
151
151
|
|
152
152
|
list_type = get_gconf_type(new_list.first)
|
153
|
-
if list_type ==
|
153
|
+
if list_type == "int" && new_list.size == 2
|
154
154
|
# treat this as a pair of int
|
155
155
|
a = new_list[0]
|
156
156
|
b = new_list[1]
|
@@ -163,13 +163,13 @@ module Alexandria
|
|
163
163
|
end
|
164
164
|
|
165
165
|
def make_list_string(list)
|
166
|
-
list.map! { |x| x.gsub(/\"/, '\\"') } if get_gconf_type(list.first) ==
|
167
|
-
contents = list.join(
|
168
|
-
|
166
|
+
list.map! { |x| x.gsub(/\"/, '\\"') } if get_gconf_type(list.first) == "string"
|
167
|
+
contents = list.join(",")
|
168
|
+
"[" + contents + "]"
|
169
169
|
end
|
170
170
|
|
171
171
|
def exec_gconf_set(var_path, new_value)
|
172
|
-
if /cols_width
|
172
|
+
if /cols_width/.match?(var_path)
|
173
173
|
puts new_value
|
174
174
|
|
175
175
|
# new_value = {}
|
@@ -180,12 +180,12 @@ module Alexandria
|
|
180
180
|
new_value.gsub!(/\"/, '\\"')
|
181
181
|
value_str = "\"#{new_value}\""
|
182
182
|
end
|
183
|
-
puts value_str if /cols_width
|
183
|
+
puts value_str if /cols_width/.match?(var_path)
|
184
184
|
`gconftool-2 --type #{type} --set #{var_path} #{value_str}`
|
185
185
|
end
|
186
186
|
|
187
187
|
def exec_gconf_unset(variable_name)
|
188
|
-
`#{GCONFTOOL} --unset #{APP_DIR +
|
188
|
+
`#{GCONFTOOL} --unset #{APP_DIR + "/" + variable_name}`
|
189
189
|
end
|
190
190
|
|
191
191
|
##
|
@@ -205,14 +205,14 @@ module Alexandria
|
|
205
205
|
def load_http_proxy_settings
|
206
206
|
http_proxy_vars = `#{GCONFTOOL} --recursive-list #{HTTP_PROXY_DIR}`
|
207
207
|
http_proxy = gconftool_values_to_hash(http_proxy_vars)
|
208
|
-
if http_proxy[
|
208
|
+
if http_proxy["use_http_proxy"]
|
209
209
|
proxy_mode = `#{GCONFTOOL} --get #{HTTP_PROXY_MODE}`.chomp
|
210
|
-
if proxy_mode ==
|
210
|
+
if proxy_mode == "manual"
|
211
211
|
@use_http_proxy = true
|
212
|
-
@proxy_host = http_proxy[
|
213
|
-
@proxy_port = http_proxy[
|
214
|
-
@proxy_user = http_proxy[
|
215
|
-
@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"]
|
216
216
|
end
|
217
217
|
end
|
218
218
|
@http_proxy_loaded = true
|
@@ -235,17 +235,17 @@ module Alexandria
|
|
235
235
|
# gconftool. This is not fool-proof, but it *does* work for the
|
236
236
|
# range of values used by Alexandria.
|
237
237
|
def discriminate(value)
|
238
|
-
if value ==
|
238
|
+
if value == "true" # bool
|
239
239
|
true
|
240
|
-
elsif value ==
|
240
|
+
elsif value == "false" # bool
|
241
241
|
false
|
242
|
-
elsif
|
242
|
+
elsif /^[0-9]+$/.match?(value) # int
|
243
243
|
value.to_i
|
244
244
|
elsif value =~ /^\[(.*)\]$/ # list (assume of type String)
|
245
|
-
Regexp.last_match[1].split(
|
245
|
+
Regexp.last_match[1].split(",")
|
246
246
|
elsif value =~ /^\((.*)\)$/ # pair (assume of type int)
|
247
247
|
begin
|
248
|
-
pair = Regexp.last_match[1].split(
|
248
|
+
pair = Regexp.last_match[1].split(",")
|
249
249
|
return [discriminate(pair.first), discriminate(pair.last)]
|
250
250
|
rescue StandardError
|
251
251
|
return [0, 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
|
@@ -26,19 +26,19 @@ module Alexandria
|
|
26
26
|
include Alexandria::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] !=
|
39
|
+
return false if data[-1] != "."
|
40
40
|
|
41
|
-
fields = data.split(
|
41
|
+
fields = data.split(".")
|
42
42
|
return false if fields.size != 4
|
43
43
|
return false if fields[2].size != 4
|
44
44
|
|
@@ -50,13 +50,13 @@ module Alexandria
|
|
50
50
|
# domain perl implementation.
|
51
51
|
def decode(data)
|
52
52
|
data = data.chomp
|
53
|
-
fields = data.split(
|
53
|
+
fields = data.split(".")
|
54
54
|
fields.shift # First part is gibberish
|
55
55
|
fields.shift # Second part is cuecat serial number
|
56
56
|
type, code = fields.map { |field| decode_field(field) }
|
57
57
|
|
58
|
-
if type ==
|
59
|
-
type =
|
58
|
+
if type == "IB5"
|
59
|
+
type = "IBN"
|
60
60
|
code = code[0, 13]
|
61
61
|
end
|
62
62
|
|
@@ -64,13 +64,13 @@ module Alexandria
|
|
64
64
|
if Library.valid_upc? code
|
65
65
|
isbn13 = Library.canonicalise_ean(code)
|
66
66
|
code = isbn13
|
67
|
-
type =
|
67
|
+
type = "IBN"
|
68
68
|
end
|
69
69
|
rescue StandardError
|
70
70
|
log.debug { "Cannot translate UPC (#{type}) code #{code} to ISBN" }
|
71
71
|
end
|
72
72
|
|
73
|
-
return code if type ==
|
73
|
+
return code if type == "IBN"
|
74
74
|
|
75
75
|
raise "Don't know how to handle type #{type} (barcode: #{code})"
|
76
76
|
end
|
@@ -78,7 +78,7 @@ module Alexandria
|
|
78
78
|
private
|
79
79
|
|
80
80
|
def decode_field(encoded)
|
81
|
-
seq =
|
81
|
+
seq = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-"
|
82
82
|
|
83
83
|
chars = encoded.split(//)
|
84
84
|
values = chars.map { |c| seq.index(c) }
|
@@ -90,7 +90,7 @@ module Alexandria
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def calc(values)
|
93
|
-
result =
|
93
|
+
result = ""
|
94
94
|
until values.empty?
|
95
95
|
num = ((values[0] << 6 | values[1]) << 6 | values[2]) << 6 | values[3]
|
96
96
|
result += ((num >> 16) ^ 67).chr
|
@@ -106,7 +106,7 @@ module Alexandria
|
|
106
106
|
length = array.length % 4
|
107
107
|
|
108
108
|
if length.nonzero?
|
109
|
-
raise
|
109
|
+
raise "Error parsing CueCat input" if length == 1
|
110
110
|
|
111
111
|
length = 4 - length
|
112
112
|
length.times { array.push(0) }
|