localshelf 0.0.1.pre

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7aef35c4ce45d54162ad3c1d4f067f73264e5099
4
+ data.tar.gz: 74512b56476e859dffaa8630094b7dac1e5dce88
5
+ SHA512:
6
+ metadata.gz: d9449e94cdcdf840211da8f6b4ecfd292c6260b91439888238601e5febdc272f0d71d52eb7d13707a4f5ab922be9f69aac0a13002a8b0cf18e0ec1702681e33a
7
+ data.tar.gz: 30f3f7113f177f18b49aca432a2063fdc4b8314b5903851d363239a156d9d02a75fbeb6103e0c9f276df5ef566b1823381b1051e5824dc481de7b98f6fc94cdd
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in localshelf.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Weera Wu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Localshelf
2
+
3
+ Ebook shelf for a group.
4
+
5
+ Localshelf allows users to manage and share their ebooks within a local network
6
+ through its web interface.
7
+
8
+ Only EPUB format is supported currently.
9
+
10
+ ## Installation
11
+
12
+ Execute this line to install:
13
+
14
+ $ gem install localshelf
15
+
16
+ ## Usage
17
+
18
+ Create a bookshelf:
19
+
20
+ $ localshelf init
21
+ $ localshelf create OfficeShelf
22
+
23
+ Import ebooks to your bookshelf:
24
+
25
+ $ localshelf import path/to/folder/
26
+
27
+ Share your bookshelf with others:
28
+
29
+ $ localshelf server
30
+
31
+ Then check out http://<your-ip-address>:4567/ to see your collection.
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/localshelf/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ end
7
+
8
+ task :default => :test
9
+
data/bin/localshelf ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Exit cleanly from an early interrupt
4
+ Signal.trap("INT") { exit 1 }
5
+
6
+ require 'localshelf'
7
+ require 'localshelf/cli'
8
+ Localshelf::CLI.start(ARGV, :debug => true)
@@ -0,0 +1,17 @@
1
+ module Localshelf
2
+ class Book < ActiveRecord::Base
3
+ belongs_to :bookshelf
4
+ has_many :formats
5
+ validates :title, :identifier, presence: true
6
+
7
+ def target_location
8
+ File.join(bookshelf.location, identifier)
9
+ end
10
+
11
+ def construct!
12
+ return false unless persisted? && valid?
13
+ FileUtils.mkdir_p(target_location)
14
+ formats.to_a.count(&:construct!)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module Localshelf
2
+ class Bookshelf < ActiveRecord::Base
3
+ has_many :books
4
+ validates :name, :location, presence: true, uniqueness: true
5
+
6
+ def target_location
7
+ location
8
+ end
9
+
10
+ def construct!
11
+ return false unless persisted? && valid?
12
+ FileUtils.mkdir_p(target_location)
13
+ books.to_a.count(&:construct!)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,136 @@
1
+ require 'thor'
2
+ require 'rack'
3
+ require 'socket'
4
+ require 'active_record'
5
+ require 'sqlite3'
6
+ require 'localshelf/bookshelf'
7
+ require 'localshelf/book'
8
+ require 'localshelf/format'
9
+
10
+ module Localshelf
11
+ class CLI < Thor
12
+ include Thor::Actions
13
+
14
+ LOCALSHELF_HOME = File.expand_path("~/Localshelf")
15
+ IP_ADDRESS = Socket.ip_address_list.detect(&:ipv4_private?).ip_address
16
+
17
+ desc "load_config", "Load Localshelf configs"
18
+ def load_config
19
+ abort(" ! Localshelf has not been initialized yet.") unless initialized?
20
+
21
+ I18n.enforce_available_locales = false
22
+
23
+ ActiveRecord::Base.establish_connection(
24
+ adapter: "sqlite3",
25
+ database: File.join(LOCALSHELF_HOME, "Localshelf.sqlite3")
26
+ )
27
+ end
28
+
29
+ desc "init", "Initialize Localshelf application"
30
+ def init
31
+ abort(" ! Localshelf has already been initialized.") if initialized?
32
+
33
+ say("Initializing Localshelf at #{LOCALSHELF_HOME}")
34
+ FileUtils.mkdir_p(LOCALSHELF_HOME)
35
+
36
+ invoke :load_config, []
37
+
38
+ ActiveRecord::Schema.define do
39
+ create_table "bookshelves", force: true do |t|
40
+ t.string "name"
41
+ t.string "location"
42
+ t.datetime "created_at", null: false
43
+ t.datetime "updated_at", null: false
44
+ end
45
+
46
+ create_table "books", force: true do |t|
47
+ t.integer "bookshelf_id"
48
+ t.string "title"
49
+ t.string "language"
50
+ t.string "identifier"
51
+ t.string "creator"
52
+ t.string "cover_location"
53
+ t.datetime "created_at", null: false
54
+ t.datetime "updated_at", null: false
55
+ end
56
+ add_index "books", ["bookshelf_id"], name: "index_books_on_bookshelf_id"
57
+
58
+ create_table "formats", force: true do |t|
59
+ t.integer "book_id"
60
+ t.string "checksum"
61
+ t.string "location"
62
+ t.string "original_location"
63
+ t.integer "size"
64
+ t.string "type"
65
+ t.datetime "created_at", null: false
66
+ t.datetime "updated_at", null: false
67
+ end
68
+ add_index "formats", ["book_id"], name: "index_formats_on_book_id"
69
+ add_index "formats", ["checksum"], name: "index_formats_on_checksum", unique: true
70
+ end
71
+ end
72
+
73
+ desc "create [NAME]", "Create a new bookshelf"
74
+ def create(name="Default")
75
+ invoke(:load_config, [])
76
+
77
+ location = File.join(LOCALSHELF_HOME, name)
78
+ say("Creating #{name} bookshelf at #{location}")
79
+
80
+ bookshelf = Bookshelf.new(name: name, location: location)
81
+ unless bookshelf.save
82
+ abort(" ! Cannot create Bookshelf: #{bookshelf.errors.full_messages}")
83
+ end
84
+ bookshelf.construct!
85
+ end
86
+
87
+ # TODO Add support for wildcard argument
88
+ desc "import FILES", "Import books to Localshelf"
89
+ def import(files)
90
+ invoke :load_config, []
91
+
92
+ files = File.expand_path(files)
93
+ book_files = files unless File.directory?(files)
94
+ book_files ||= File.join(files, "*.{epub,EPUB}") # TODO
95
+ bookshelf = Bookshelf.first # TODO
96
+
97
+ Dir[book_files].each do |file|
98
+ filename = File.basename(file)
99
+
100
+ if Format.exists?(original_location: file)
101
+ say("Skipping #{filename}")
102
+ next
103
+ else
104
+ say("Importing #{filename} to #{bookshelf.name}")
105
+ format = Epub.new(original_location: file) # TODO
106
+ unless format.save
107
+ abort(" ! Cannot create Format: #{format.errors.full_messages}")
108
+ end
109
+
110
+ metadata = format.extract_metadata
111
+ book = bookshelf.books.find_by(identifier: metadata[:identifier])
112
+ book ||= bookshelf.books.build(metadata)
113
+ book.formats << format
114
+
115
+ unless book.save
116
+ abort(" ! Cannot create Book: #{book.errors.full_messages}")
117
+ end
118
+ book.construct!
119
+ end
120
+ end
121
+ end
122
+
123
+ desc "server", "Share your bookshelf on http://#{IP_ADDRESS}:8080"
124
+ def server
125
+ app = Rack::Directory.new(LOCALSHELF_HOME)
126
+ Rack::Handler::WEBrick.run(app)
127
+ end
128
+
129
+ private
130
+
131
+ def initialized?
132
+ Dir.exists?(LOCALSHELF_HOME)
133
+ end
134
+
135
+ end
136
+ end
@@ -0,0 +1,77 @@
1
+ require 'epubinfo'
2
+
3
+ module Localshelf
4
+ class Format < ActiveRecord::Base
5
+ belongs_to :book
6
+ validates :original_location, presence: true
7
+ validate :original_location_exists
8
+ before_create :set_metadata
9
+
10
+ def target_location
11
+ target_extname = File.extname(original_location).downcase
12
+ target_filename = [checksum, target_extname].join
13
+ File.join(book.bookshelf.location, book.identifier, target_filename)
14
+ end
15
+
16
+ def construct!
17
+ return false unless persisted? && valid?
18
+ return false if File.exists?(target_location)
19
+ FileUtils.cp(original_location, target_location)
20
+ update(location: target_location)
21
+ end
22
+
23
+ private
24
+
25
+ def original_location_exists
26
+ unless File.exists?(original_location)
27
+ errors.add(:original_location, "doesn't exist")
28
+ end
29
+ end
30
+
31
+ def set_metadata
32
+ self.checksum ||= "%x" % ( Integer( `cksum '#{original_location}'`[/^\d+/] ) & 0xffffffff )
33
+ self.size ||= File.size(original_location)
34
+ end
35
+ end
36
+
37
+ class Epub < Format
38
+ validates :original_location, format: { with: /epub\z/i }
39
+
40
+ def extract_metadata
41
+ {
42
+ title: parser.titles.first,
43
+ language: parser.languages.first,
44
+ identifier: parser.identifiers.first.identifier.gsub(/\D+/, ""),
45
+ creator: parser.creators.map(&:name).join(", ")
46
+ }
47
+ end
48
+
49
+ def construct!
50
+ super
51
+
52
+ # TODO
53
+ return unless parser.cover
54
+ target_extname = File.extname(parser.cover.original_file_name).downcase
55
+ target_location = File.join(
56
+ book.bookshelf.location,
57
+ book.identifier,
58
+ ["cover", target_extname].join
59
+ )
60
+ unless File.exists?(target_location)
61
+ parser.cover.tempfile { |f| FileUtils.cp(f.path, target_location) }
62
+ book.update(cover_location: target_location)
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def parser
69
+ return @_parser if @_parser
70
+ raise "No location" unless original_location?
71
+ EPUBInfo.get(original_location)
72
+ end
73
+ end
74
+
75
+ class Pdf < Format
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module Localshelf
2
+ VERSION = "0.0.1.pre"
3
+ end
data/lib/localshelf.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "localshelf/version"
2
+
3
+ module Localshelf
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'localshelf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "localshelf"
8
+ spec.version = Localshelf::VERSION
9
+ spec.authors = ["Weera Wu"]
10
+ spec.email = ["weera@oozou.com"]
11
+ spec.summary = %q{Ebook shelf for a group}
12
+ spec.description = %q{Localshelf allows users to manage and share their ebooks within a local network through its web interface.}
13
+ spec.homepage = "https://github.com/wulab/localshelf"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "thor"
22
+ spec.add_runtime_dependency "rack"
23
+ spec.add_runtime_dependency "activerecord"
24
+ spec.add_runtime_dependency "sqlite3"
25
+ spec.add_runtime_dependency "epubinfo"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.6"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "minitest"
30
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'localshelf'
3
+
4
+ require 'minitest/autorun'
@@ -0,0 +1,11 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestLocalshelf < MiniTest::Unit::TestCase
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::Localshelf::VERSION
6
+ end
7
+
8
+ def test_it_does_something_useful
9
+ assert false
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: localshelf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - Weera Wu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: epubinfo
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Localshelf allows users to manage and share their ebooks within a local
126
+ network through its web interface.
127
+ email:
128
+ - weera@oozou.com
129
+ executables:
130
+ - localshelf
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/localshelf
141
+ - lib/localshelf.rb
142
+ - lib/localshelf/book.rb
143
+ - lib/localshelf/bookshelf.rb
144
+ - lib/localshelf/cli.rb
145
+ - lib/localshelf/format.rb
146
+ - lib/localshelf/version.rb
147
+ - localshelf.gemspec
148
+ - test/minitest_helper.rb
149
+ - test/test_localshelf.rb
150
+ homepage: https://github.com/wulab/localshelf
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">"
166
+ - !ruby/object:Gem::Version
167
+ version: 1.3.1
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.2.2
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Ebook shelf for a group
174
+ test_files:
175
+ - test/minitest_helper.rb
176
+ - test/test_localshelf.rb