alexandria-book-collection-manager 0.7.1 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +9 -0
  3. data/.gitignore +5 -2
  4. data/.hound.yml +2 -0
  5. data/.rubocop.yml +113 -45
  6. data/.rubocop_todo.yml +82 -170
  7. data/.simplecov +5 -1
  8. data/.travis.yml +45 -0
  9. data/.yardopts +1 -1
  10. data/CHANGELOG.md +60 -0
  11. data/ChangeLog.0 +33 -35
  12. data/Gemfile +6 -5
  13. data/INSTALL.md +164 -0
  14. data/README.md +52 -42
  15. data/Rakefile +95 -109
  16. data/TODO.md +9 -1
  17. data/alexandria-book-collection-manager.gemspec +52 -45
  18. data/bin/alexandria +31 -53
  19. data/doc/AUTHORS +61 -0
  20. data/doc/BUGS +31 -0
  21. data/doc/FAQ +365 -0
  22. data/doc/HACKING +19 -0
  23. data/doc/NEWS +341 -0
  24. data/doc/alexandria.1 +120 -0
  25. data/doc/cuecat_support.rdoc +67 -0
  26. data/doc/dependency_decisions.yml +80 -0
  27. data/lib/alexandria.rb +29 -37
  28. data/lib/alexandria/about.rb +52 -51
  29. data/lib/alexandria/book_providers.rb +94 -101
  30. data/lib/alexandria/book_providers/adlibris.rb +45 -85
  31. data/lib/alexandria/book_providers/amazon_aws.rb +105 -113
  32. data/lib/alexandria/book_providers/amazon_ecs_util.rb +293 -324
  33. data/lib/alexandria/book_providers/barnes_and_noble.rb +54 -53
  34. data/lib/alexandria/book_providers/douban.rb +29 -51
  35. data/lib/alexandria/book_providers/proxis.rb +42 -59
  36. data/lib/alexandria/book_providers/pseudomarc.rb +79 -99
  37. data/lib/alexandria/book_providers/siciliano.rb +68 -70
  38. data/lib/alexandria/book_providers/thalia.rb +46 -45
  39. data/lib/alexandria/book_providers/web.rb +17 -33
  40. data/lib/alexandria/book_providers/worldcat.rb +74 -102
  41. data/lib/alexandria/book_providers/z3950.rb +170 -174
  42. data/lib/alexandria/config.rb +5 -3
  43. data/lib/alexandria/console.rb +10 -21
  44. data/lib/alexandria/default_preferences.rb +37 -0
  45. data/lib/alexandria/execution_queue.rb +17 -15
  46. data/lib/alexandria/export_format.rb +47 -0
  47. data/lib/alexandria/export_library.rb +188 -302
  48. data/lib/alexandria/import_library.rb +114 -155
  49. data/lib/alexandria/import_library_csv.rb +46 -96
  50. data/lib/alexandria/library_collection.rb +79 -0
  51. data/lib/alexandria/library_sort_order.rb +45 -0
  52. data/lib/alexandria/library_store.rb +233 -0
  53. data/lib/alexandria/logging.rb +15 -19
  54. data/lib/alexandria/models/book.rb +15 -20
  55. data/lib/alexandria/models/library.rb +81 -363
  56. data/lib/alexandria/net.rb +7 -6
  57. data/lib/alexandria/preferences.rb +73 -91
  58. data/lib/alexandria/scanners.rb +4 -2
  59. data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +24 -20
  60. data/lib/alexandria/scanners/keyboard.rb +10 -8
  61. data/lib/alexandria/smart_library.rb +135 -171
  62. data/lib/alexandria/ui.rb +17 -15
  63. data/lib/alexandria/ui/about_dialog.rb +49 -0
  64. data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +129 -152
  65. data/lib/alexandria/ui/alert_dialog.rb +64 -0
  66. data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
  67. data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +18 -15
  68. data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +44 -61
  69. data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +84 -89
  70. data/lib/alexandria/ui/builder_base.rb +9 -27
  71. data/lib/alexandria/ui/callbacks.rb +188 -186
  72. data/lib/alexandria/ui/columns.rb +2 -0
  73. data/lib/alexandria/ui/completion_models.rb +12 -23
  74. data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
  75. data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
  76. data/lib/alexandria/ui/dndable.rb +10 -8
  77. data/lib/alexandria/ui/error_dialog.rb +25 -0
  78. data/lib/alexandria/ui/export_dialog.rb +139 -0
  79. data/lib/alexandria/ui/icons.rb +49 -65
  80. data/lib/alexandria/ui/iconview.rb +15 -13
  81. data/lib/alexandria/ui/iconview_tooltips.rb +43 -58
  82. data/lib/alexandria/ui/import_dialog.rb +157 -0
  83. data/lib/alexandria/ui/init.rb +23 -33
  84. data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
  85. data/lib/alexandria/ui/libraries_combo.rb +18 -14
  86. data/lib/alexandria/ui/listview.rb +77 -88
  87. data/lib/alexandria/ui/main_app.rb +26 -26
  88. data/lib/alexandria/ui/misc_dialogs.rb +10 -0
  89. data/lib/alexandria/ui/multi_drag_treeview.rb +30 -41
  90. data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +168 -215
  91. data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
  92. data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
  93. data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
  94. data/lib/alexandria/ui/preferences_dialog.rb +313 -0
  95. data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
  96. data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
  97. data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
  98. data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +62 -72
  99. data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
  100. data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
  101. data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +96 -172
  102. data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
  103. data/lib/alexandria/ui/sound.rb +13 -13
  104. data/lib/alexandria/ui/ui_manager.rb +262 -283
  105. data/lib/alexandria/undo_manager.rb +3 -0
  106. data/lib/alexandria/version.rb +6 -19
  107. data/lib/alexandria/web_themes.rb +24 -21
  108. data/po/Makefile +2 -2
  109. data/po/cs.po +993 -880
  110. data/po/cy.po +957 -874
  111. data/po/de.po +990 -869
  112. data/po/el.po +989 -869
  113. data/po/es.po +985 -865
  114. data/po/fr.po +986 -870
  115. data/po/ga.po +907 -823
  116. data/po/gl.po +981 -865
  117. data/po/it.po +986 -868
  118. data/po/ja.po +969 -853
  119. data/po/mk.po +983 -863
  120. data/po/nb.po +979 -863
  121. data/po/nl.po +983 -864
  122. data/po/pl.po +1020 -969
  123. data/po/pt.po +988 -861
  124. data/po/pt_BR.po +984 -868
  125. data/po/ru.po +992 -873
  126. data/po/sk.po +987 -869
  127. data/po/sv.po +977 -861
  128. data/po/uk.po +975 -865
  129. data/po/zh_TW.po +976 -860
  130. data/schemas/alexandria.schemas +25 -3
  131. data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
  132. data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
  133. data/share/alexandria/glade/main_app__builder.glade +24 -33
  134. data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
  135. data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
  136. data/share/gnome/help/alexandria/C/introduction.xml +0 -8
  137. data/share/gnome/help/alexandria/C/searching.xml +1 -1
  138. data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
  139. data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
  140. data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
  141. data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
  142. data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
  143. data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
  144. data/spec/alexandria/book_providers_spec.rb +77 -210
  145. data/spec/alexandria/book_spec.rb +16 -12
  146. data/spec/alexandria/console_spec.rb +27 -0
  147. data/spec/alexandria/export_library_spec.rb +130 -0
  148. data/spec/alexandria/library_spec.rb +130 -172
  149. data/spec/alexandria/library_store_spec.rb +37 -0
  150. data/spec/alexandria/preferences_spec.rb +46 -17
  151. data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
  152. data/spec/alexandria/smart_library_spec.rb +32 -25
  153. data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
  154. data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
  155. data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
  156. data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
  157. data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
  158. data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
  159. data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
  160. data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
  161. data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
  162. data/spec/alexandria/ui/icons_spec.rb +26 -0
  163. data/spec/alexandria/ui/iconview_spec.rb +9 -21
  164. data/spec/alexandria/ui/import_dialog_spec.rb +41 -0
  165. data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
  166. data/spec/alexandria/ui/main_app_spec.rb +8 -33
  167. data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
  168. data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
  169. data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
  170. data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
  171. data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
  172. data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
  173. data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
  174. data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
  175. data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
  176. data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +32 -0
  177. data/spec/alexandria/ui/sound_spec.rb +4 -2
  178. data/spec/alexandria/ui/ui_manager_spec.rb +45 -20
  179. data/spec/end_to_end/basic_run_spec.rb +57 -0
  180. data/spec/spec_helper.rb +66 -33
  181. data/tasks/setup.rb +5 -3
  182. data/tasks/spec.rake +18 -3
  183. data/util/rake/fileinstall.rb +38 -40
  184. data/util/rake/gettextgenerate.rb +15 -70
  185. data/util/rake/omfgenerate.rb +10 -10
  186. metadata +176 -60
  187. data/INSTALL.rdoc +0 -148
  188. data/dogtail/basic_run_test.py +0 -9
  189. data/lib/alexandria/book_providers/bol_it.rb +0 -160
  190. data/lib/alexandria/book_providers/deastore.rb +0 -273
  191. data/lib/alexandria/book_providers/ibs_it.rb +0 -147
  192. data/lib/alexandria/book_providers/mcu.rb +0 -169
  193. data/lib/alexandria/book_providers/renaud.rb +0 -140
  194. data/lib/alexandria/book_providers/webster_it.rb +0 -167
  195. data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -59
  196. data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -70
  197. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -43
  198. data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
  199. data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
  200. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -85
  201. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
  202. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
  203. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -578
  204. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -57
  205. data/spec/alexandria/scanners/cuecat_spec.rb +0 -65
  206. data/spec/alexandria/ui/dialogs_spec.rb +0 -94
  207. data/spec/alexandria/ui/sidepane_spec.rb +0 -27
  208. data/spec/alexandria/ui/ui_utilities_spec.rb +0 -60
  209. data/spec/alexandria/utilities_spec.rb +0 -50
  210. data/tasks/dogtail.rake +0 -4
@@ -1,45 +1,78 @@
1
- # Copyright (C) 2007 Joseph Method
2
- # Copyright (C) 2014, 2016 Matijs van Zuijlen
3
- #
4
- # Alexandria is free software; you can redistribute it and/or
5
- # modify it under the terms of the GNU General Public License as
6
- # published by the Free Software Foundation; either version 2 of the
7
- # License, or (at your option) any later version.
8
- #
9
- # Alexandria is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # General Public License for more details.
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Alexandria.
13
4
  #
14
- # You should have received a copy of the GNU General Public
15
- # License along with Alexandria; see the file COPYING. If not,
16
- # write to the Free Software Foundation, Inc., 51 Franklin Street,
17
- # Fifth Floor, Boston, MA 02110-1301 USA.
5
+ # See the file README.md for authorship and licensing information.
18
6
 
19
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../lib'))
7
+ require "rspec"
8
+ require "alexandria"
9
+ require "webmock/rspec"
20
10
 
21
- require 'alexandria'
11
+ LIBDIR = File.expand_path("data/libraries", __dir__)
12
+ TESTDIR = File.join(LIBDIR, "test")
22
13
 
23
- LIBDIR = File.expand_path(File.join(File.dirname(__FILE__), '/data/libraries'))
24
- TESTDIR = File.join(LIBDIR, 'test')
14
+ def an_artist_of_the_floating_world
15
+ Alexandria::Book.new("An Artist of the Floating World",
16
+ ["Kazuo Ishiguro"],
17
+ "9780571147168",
18
+ "Faber and Faber", 1999,
19
+ "Paperback")
20
+ end
25
21
 
26
- # def useTestLibrary(version)
27
- # libVersion = File.join(LIBDIR, version)
28
- # FileUtils.cp_r(libVersion, TESTDIR)
29
- # end
22
+ def assert_correct_search_result(provider, query,
23
+ search_type = Alexandria::BookProviders::SEARCH_BY_ISBN)
24
+ begin
25
+ results = provider.instance.search(query, search_type)
26
+ rescue SocketError
27
+ skip "Service is offline"
28
+ end
30
29
 
31
- def an_artist_of_the_floating_world
32
- Alexandria::Book.new('An Artist of the Floating World',
33
- 'Kazuo Ishiguro',
34
- '9780571147168',
35
- 'Faber and Faber', 1999,
36
- 'Paperback')
30
+ expect(results).to be_instance_of(Array), "Results are not an array for #{provider}"
31
+ expect(results).not_to be_empty, "Results are empty for #{provider}"
32
+
33
+ if search_type == Alexandria::BookProviders::SEARCH_BY_ISBN
34
+ expect(results.length).to be <= 2, "Results are greater than 2 for #{provider}"
35
+
36
+ book = results.first
37
+
38
+ expect(book).to be_instance_of(Alexandria::Book),
39
+ "Result is not a Book for #{provider}"
40
+
41
+ canonical_query = Alexandria::Library.canonicalise_ean(query)
42
+ canonical_result = Alexandria::Library.canonicalise_ean(book.isbn)
43
+ expect(canonical_query)
44
+ .to eq(canonical_result),
45
+ "Result's isbn #{book.isbn} is not equivalent" \
46
+ " to the requested isbn #{query} for #{provider}"
47
+
48
+ if results.length == 2
49
+ cover_url = results.last
50
+ if cover_url
51
+ expect(cover_url)
52
+ .to be_instance_of(String),
53
+ "Unexpected cover_url #{cover_url.inspect} for #{provider}"
54
+ end
55
+ end
56
+ else
57
+ expect(results.first.first)
58
+ .to be_instance_of(Alexandria::Book), "Result item is not a Book for #{provider}"
59
+ end
60
+ results
37
61
  end
38
62
 
39
63
  Alexandria::UI::Icons.init
40
64
 
41
- module Alexandria
42
- class Library
43
- DIR.replace TESTDIR
65
+ test_store = Alexandria::LibraryStore.new(TESTDIR)
66
+ Alexandria::LibraryCollection.instance.library_store = test_store
67
+
68
+ RSpec.configure do |config|
69
+ config.example_status_persistence_file_path = "spec/examples.txt"
70
+
71
+ config.before do
72
+ FileUtils.rm_rf(TESTDIR)
73
+ end
74
+
75
+ config.after do
76
+ FileUtils.rm_rf(TESTDIR)
44
77
  end
45
78
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (C) 2011 Matijs van Zuijlen
3
5
  #
@@ -22,9 +24,9 @@
22
24
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
25
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
26
  #++
25
- require 'rake/clean'
27
+ require "rake/clean"
26
28
 
27
29
  # Load the other rake files in the tasks folder
28
- tasks_dir = File.expand_path(File.dirname(__FILE__))
29
- rakefiles = Dir.glob(File.join(tasks_dir, '*.rake')).sort
30
+ tasks_dir = __dir__
31
+ rakefiles = Dir.glob(File.join(tasks_dir, "*.rake")).sort
30
32
  import(*rakefiles)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -*- ruby -*-
2
4
  #--
3
5
  # Copyright (C) 2011 Matijs van Zuijlen
@@ -24,8 +26,21 @@
24
26
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
27
  #++
26
28
 
27
- require 'rspec/core/rake_task'
29
+ require "rspec/core/rake_task"
30
+
31
+ namespace "spec" do
32
+ RSpec::Core::RakeTask.new("unit") do |t|
33
+ t.pattern = "spec/alexandria/**/*_spec.rb"
34
+ t.ruby_opts = ["-rbundler/setup -rsimplecov -Ilib -w"]
35
+ end
28
36
 
29
- RSpec::Core::RakeTask.new(:spec) do |t|
30
- t.ruby_opts = ['-rbundler/setup -rsimplecov -Ilib -w']
37
+ RSpec::Core::RakeTask.new("end_to_end") do |t|
38
+ t.pattern = "spec/end_to_end/**/*_spec.rb"
39
+ t.ruby_opts = ["-rbundler/setup -rsimplecov -Ilib -w"]
40
+ end
41
+
42
+ desc "Runs all unit and end-to-end specs"
43
+ task "all" => ["spec:unit", "spec:end_to_end"]
31
44
  end
45
+
46
+ task spec: "spec:all"
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -*- ruby -*-
2
4
  #--
3
5
  # Copyright (C) 2009 Cathal Mc Ginley
4
- # Copyright (C) 2011 Matijs van Zuijlen
6
+ # Copyright (C) 2011, 2020 Matijs van Zuijlen
5
7
  #
6
8
  # This file is part of the Alexandria build system.
7
9
  #
@@ -25,10 +27,10 @@
25
27
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
28
  #++
27
29
 
28
- require 'fileutils'
29
- require 'pathname'
30
- require 'set'
31
- require 'rake/tasklib'
30
+ require "fileutils"
31
+ require "pathname"
32
+ require "set"
33
+ require "rake/tasklib"
32
34
 
33
35
  # A file installer task, capable of installing into the system
34
36
  # directories, or doing a staged install to a given directory
@@ -82,8 +84,8 @@ class FileInstallTask < Rake::TaskLib
82
84
 
83
85
  # INSTALL TASK
84
86
 
85
- description = 'Install package files'
86
- description += ' to staging directory' if @stage_dir
87
+ description = "Install package files"
88
+ description += " to staging directory" if @stage_dir
87
89
  desc description
88
90
  task tasknames[:install] do
89
91
  @file_groups.each { |g| g.install(@stage_dir) }
@@ -103,7 +105,7 @@ class FileInstallTask < Rake::TaskLib
103
105
  @dirs_to_remove_globs.each do |glob|
104
106
  regex = glob2regex(glob)
105
107
  all_dirs.each do |dir|
106
- dir += '/' unless dir =~ /\/$/
108
+ dir += "/" unless dir.end_with?("/")
107
109
  to_delete << Regexp.last_match[1] if regex =~ dir
108
110
  end
109
111
  end
@@ -114,10 +116,8 @@ class FileInstallTask < Rake::TaskLib
114
116
  end
115
117
  end
116
118
 
117
- uninstall_description = 'Uninstall package files'
118
- if @stage_dir
119
- uninstall_description += ' from staging directory'
120
- end
119
+ uninstall_description = "Uninstall package files"
120
+ uninstall_description += " from staging directory" if @stage_dir
121
121
  desc uninstall_description
122
122
  task tasknames[:uninstall] => [tasknames[:uninstall_files],
123
123
  tasknames[:uninstall_dirs]]
@@ -145,7 +145,7 @@ class FileInstallTask < Rake::TaskLib
145
145
 
146
146
  # Install icon files. This method splits up the source file name and
147
147
  # determines where they should be put in the destination hierarchy.
148
- def install_icons(file_globs, dest_dir, theme = 'hicolor', icon_type = 'apps')
148
+ def install_icons(file_globs, dest_dir, theme = "hicolor", icon_type = "apps")
149
149
  file_globs.each do |fg|
150
150
  files = FileList.new(fg)
151
151
  files.each do |f|
@@ -154,7 +154,7 @@ class FileInstallTask < Rake::TaskLib
154
154
  icon_size = Pathname.new(icon_dir).basename
155
155
  icon_dest_dir = "#{dest_dir}/#{theme}/#{icon_size}/#{icon_type}"
156
156
  group = FileGroup.new(icon_dir, f, icon_dest_dir)
157
- group.description = 'icons'
157
+ group.description = "icons"
158
158
  @file_groups << group
159
159
  end
160
160
  end
@@ -169,18 +169,16 @@ class FileInstallTask < Rake::TaskLib
169
169
  private
170
170
 
171
171
  def calculate_ruby_dir
172
- ruby_prefix = RbConfig::CONFIG['prefix']
172
+ ruby_prefix = RbConfig::CONFIG["prefix"]
173
173
 
174
174
  ruby_libdir = if @install_to_rubylibdir
175
- RbConfig::CONFIG['rubylibdir']
175
+ RbConfig::CONFIG["rubylibdir"]
176
176
  else
177
- RbConfig::CONFIG['sitelibdir']
177
+ RbConfig::CONFIG["sitelibdir"]
178
178
  end
179
- if ENV.key?('RUBYLIBDIR')
180
- ruby_libdir = ENV['RUBYLIBDIR']
181
- end
179
+ ruby_libdir = ENV["RUBYLIBDIR"] if ENV.key?("RUBYLIBDIR")
182
180
 
183
- @prefix = ENV['PREFIX'] || ruby_prefix
181
+ @prefix = ENV["PREFIX"] || ruby_prefix
184
182
  if @prefix == ruby_prefix
185
183
  @rubylib = ruby_libdir
186
184
  elsif ruby_libdir.index(ruby_prefix).zero?
@@ -192,12 +190,12 @@ class FileInstallTask < Rake::TaskLib
192
190
  end
193
191
 
194
192
  def glob2regex(pathglob)
195
- pathglob += '/' if pathglob =~ /\*\*$/
196
- real_parts = pathglob.split('**/')
193
+ pathglob += "/" if pathglob.end_with?("**")
194
+ real_parts = pathglob.split("**/")
197
195
  real_parts.each do |part|
198
- part.gsub!('.', '\\.')
199
- part.gsub!('*', '[^\\/]*')
200
- part.gsub!('?', '[^\\/]')
196
+ part.gsub!(".", '\\.')
197
+ part.gsub!("*", '[^\\/]*')
198
+ part.gsub!("?", '[^\\/]')
201
199
  end
202
200
  pattern = real_parts.join("([^\/]+\/)*")
203
201
  /(#{pattern})/
@@ -212,15 +210,16 @@ class FileInstallTask < Rake::TaskLib
212
210
  end
213
211
  end
214
212
 
215
- # Delete the directory at the given Pathname +p+ if all its children
213
+ # Delete the directory at the given Pathname +path+ if all its children
216
214
  # can be similarly deleted, and if it is then empty.
217
- def delete_if_empty(p)
218
- return false unless p.directory?
219
- p.children.each do |c|
215
+ def delete_if_empty(path)
216
+ return false unless path.directory?
217
+
218
+ path.children.each do |c|
220
219
  delete_if_empty(c)
221
220
  end
222
- if p.children.empty?
223
- p.delete # TODO: optional verbose output here
221
+ if path.children.empty?
222
+ path.delete # TODO: optional verbose output here
224
223
  true
225
224
  else
226
225
  false
@@ -230,12 +229,13 @@ class FileInstallTask < Rake::TaskLib
230
229
  class FileGroup
231
230
  attr_reader :mode
232
231
  attr_accessor :description
232
+
233
233
  def initialize(src_dir, file_glob, dest_dir, mode = 0o644)
234
234
  @src_dir = src_dir
235
235
  @file_glob = file_glob
236
236
  @dest_dir = dest_dir
237
237
  @mode = mode
238
- @description = 'files'
238
+ @description = "files"
239
239
  end
240
240
 
241
241
  def to_s
@@ -267,10 +267,8 @@ class FileInstallTask < Rake::TaskLib
267
267
  puts "Installing #{@description} to #{base_dir}#{@dest_dir}"
268
268
  files.each do |f|
269
269
  dest = dest_dir(f, base_dir)
270
- FileUtils.mkdir_p(dest) unless test('d', dest)
271
- if test('f', f)
272
- FileUtils.install(f, dest, mode: mode)
273
- end
270
+ FileUtils.mkdir_p(dest) unless test("d", dest)
271
+ FileUtils.install(f, dest, mode: mode) if test("f", f)
274
272
  end
275
273
  end
276
274
 
@@ -279,7 +277,7 @@ class FileInstallTask < Rake::TaskLib
279
277
  dest = dest_dir(f, base_dir)
280
278
  filename = File.basename(f)
281
279
  file = File.join(dest, filename)
282
- if test('f', file)
280
+ if test("f", file)
283
281
  FileUtils::Verbose.rm_f(file) # , :noop => true)
284
282
  end
285
283
  end
@@ -293,5 +291,5 @@ class FileInstallTask < Rake::TaskLib
293
291
  all_dirs_set << File.dirname(file)
294
292
  end
295
293
  end
296
- end # class FileGroup
297
- end # class FileInstallTask
294
+ end
295
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -*- ruby -*-
2
4
  #--
3
5
  # Copyright (C) 2009 Cathal Mc Ginley
@@ -24,9 +26,9 @@
24
26
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
27
  #++
26
28
 
27
- require 'fileutils'
28
- require 'pathname'
29
- require 'rake/tasklib'
29
+ require "fileutils"
30
+ require "pathname"
31
+ require "rake/tasklib"
30
32
 
31
33
  class GettextGenerateTask < Rake::TaskLib
32
34
  def initialize(projectname)
@@ -37,27 +39,25 @@ class GettextGenerateTask < Rake::TaskLib
37
39
  end
38
40
 
39
41
  def make_task
40
- desc 'Generate gettext localization files'
42
+ desc "Generate gettext localization files"
41
43
  task gettext: @generated_files
42
44
 
43
- if CLOBBER
44
- @generated_files.each { |gen| CLOBBER << gen }
45
- end
45
+ @generated_files.each { |gen| CLOBBER << gen } if CLOBBER
46
46
  end
47
47
 
48
48
  def generate_po_files(po_dir, file_glob, dest_dir)
49
49
  @po_dir = po_dir
50
50
  @po_files_glob = file_glob
51
51
  @mo_dir = dest_dir
52
- @mo_files_regex = /.*\/(.+)\/LC_MESSAGES\/.+\.mo/
52
+ @mo_files_regex = %r{.*/(.+)/LC_MESSAGES/.+\.mo}
53
53
 
54
54
  # create MO files
55
55
  rule(/\.mo$/ => [->(dest) { source_file(dest) }]) do |t|
56
56
  dest_dir = File.dirname(t.name)
57
57
  FileUtils.makedirs(dest_dir) unless FileTest.exists?(dest_dir)
58
58
  puts "Generating #{t.name}"
59
- system("msgfmt #{t.source} -o #{t.name}")
60
- raise "msgfmt failed for #{t.source}" if $CHILD_STATUS.nonzero?
59
+ result = system("msgfmt #{t.source} -o #{t.name}")
60
+ raise "msgfmt failed for #{t.source}" unless result
61
61
  end
62
62
  mo_files.each { |mo| @generated_files << mo }
63
63
  end
@@ -69,15 +69,17 @@ class GettextGenerateTask < Rake::TaskLib
69
69
  def generate_desktop(infile, outfile)
70
70
  @generated_files << outfile
71
71
  file outfile => [infile, *po_files] do |_f|
72
- unless `intltool-merge --version`
73
- raise Exception, 'Need to install intltool'
72
+ begin
73
+ `intltool-merge --version`
74
+ rescue Errno::ENOENT
75
+ raise "Need to install intltool"
74
76
  end
75
77
  system("intltool-merge -d #{@po_dir} #{infile} #{outfile}")
76
78
  end
77
79
  end
78
80
 
79
81
  def locales
80
- po_files.map { |po| File.basename(po).split('.')[0] }
82
+ po_files.map { |po| File.basename(po).split(".")[0] }
81
83
  end
82
84
 
83
85
  def mo_files
@@ -97,60 +99,3 @@ class GettextGenerateTask < Rake::TaskLib
97
99
  po_file_for(Regexp.last_match[1])
98
100
  end
99
101
  end
100
-
101
- # class GettextConfig < BuildConfig
102
- # attr_accessor :po_dir, :po_files_glob
103
- # attr_accessor :mo_dir, :mo_files_regex
104
- # def initialize(build)
105
- # super(build)
106
- # @po_dir = 'po'
107
- # @po_files_glob = "#{@po_dir}/*.po"
108
- # @mo_dir = 'data/locale'
109
- # @mo_files_regex = /.*\/(.+)\/LC_MESSAGES\/.+\.mo/
110
- # end
111
- # def po_files
112
- # FileList[po_files_glob]
113
- # end
114
- # def po_file_for(locale)
115
- # "#{po_dir}/#{locale}.po"
116
- # end
117
- # def locales
118
- # po_files.map { |po| File.basename(po).split('.')[0] }
119
- # end
120
- # def mo_files
121
- # locales.map { |loc| mo_file_for(loc) }
122
- # end
123
- # def mo_file_for(locale)
124
- # "#{mo_dir}/#{locale}/LC_MESSAGES/#{build.name}.mo"
125
- # end
126
- # def source_file(dest_file)
127
- # dest_file =~ mo_files_regex
128
- # po_file_for($1)
129
- # end
130
- # end
131
-
132
- # def define_gettext_tasks
133
- # # extract translations from PO files into other files
134
- # file files.desktop => ["#{files.desktop}.in",
135
- # *@gettext.po_files] do |f|
136
- # raise "Need to install intltool" unless system("intltool-merge -d #{@gettext.po_dir} #{f.name}.in #{f.name}")
137
- # end
138
-
139
- # # create MO files
140
- # rule( /\.mo$/ => [ lambda { |dest| @gettext.source_file(dest) }]) do |t|
141
- # dest_dir = File.dirname(t.name)
142
- # FileUtils.makedirs(dest_dir) unless FileTest.exists?(dest_dir)
143
- # puts "Generating #{t.name}"
144
- # system("msgfmt #{t.source} -o #{t.name}")
145
- # raise "msgfmt failed for #{t.source}" if $? != 0
146
- # end
147
-
148
- # desc "Generate gettext localization files"
149
- # task :gettext => [files.desktop, *@gettext.mo_files]
150
-
151
- # task :clobber_gettext do
152
- # FileUtils.rm_f(files.desktop)
153
- # FileUtils.rm_rf(@gettext.mo_dir)
154
- # end
155
- # task :clobber => [:clobber_gettext]
156
- # end