photish 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31149e215cc2087c36f281ad5a1984ad2ce5f45b
4
- data.tar.gz: 64ee1e2e49df780d17533a63bf3d17e8346fa7ea
3
+ metadata.gz: f08162db8cbc022f3aecdd04c4efe502efe834c9
4
+ data.tar.gz: 1fbde379d36f30cda00c4f4c5d36890b03c88bd8
5
5
  SHA512:
6
- metadata.gz: 6f9e9849870e9dcaaf562a5e5b13e6d931bddea503f00e2351958c8bbe763cbe7191c1322a0173a87cc2a02fbacb3fbf1ca6ddfe7cfc20d9e1be72f60625fe47
7
- data.tar.gz: e937262b5fa4c831585831ff2161412bb6f50a10ca729b83513159f2bbaf28148e95a3fd58f9b21a0009b4be1782b888b55cbff71bbfc1e772df1c70bf964e6e
6
+ metadata.gz: 2ae6a4943986519c5164ec030aa0580efe9a3ed02510d5d5e3e21e6214f3b2c6a9c9dcd311a2da8fe6dbdcec2d92f6ec90f5460508ff25389cf4cf3a047a7310
7
+ data.tar.gz: efe37a0593db07a2b51a4f660d0da47a09e72c049c10c132a041d60b2ee524e973a9fea33c546bdb68b04f9c684da86bc73ad621b557e7de0899f78ec7cdcc87
data/README.md CHANGED
@@ -66,6 +66,7 @@ and running:
66
66
  - [Caching](#caching)
67
67
  - [Automatic Rengeneration](#automatic-regeneration)
68
68
  - [Forced Regeneration](#forced-regeneration)
69
+ - [Crude Performance Measures](#crude-performance-measures)
69
70
  - [Host](#host)
70
71
  - [Rake Task](#rake-task)
71
72
  - [Plugins](#plugins)
@@ -314,7 +315,7 @@ Field | Purpose
314
315
  `templates/photo` | the photo template file in the `site/_templates` folder, must be overridden if using a different template engine
315
316
  `logging` | a listing of the various logging options
316
317
  `logging/colorize` | when outputting to `STDOUT`, `true` to use color, `false` for none
317
- `logging/level` | the default logging level, it is advised to keep this at `info`
318
+ `logging/level` | the default logging level, it is advised to keep this at `info`, supported are `debug`, `info`, `warn`, `error` and `fatal`
318
319
  `logging/output` | the appenders for the logger, `stdout` goes to `STDOUT`, `file` goes to `log/photish.log`
319
320
  `url` | a listing of the various url options
320
321
  `url/host` | if you would like URLs generated with a specific host prefix, you can define it here, otherwise leave it as '/' or do not set this configuration at all
@@ -494,17 +495,19 @@ and threads can be used to rapidly speed up generation. However, if the
494
495
  collection has a small number of photos and pages, workers and threads will
495
496
  increase the generation time as loading a new ruby process and creating
496
497
  multiple threads may have a higher setup time then just generating everything
497
- in a single ruby process.
498
+ in a single ruby process and thread.
498
499
 
499
500
  The number of workers and threads is configurable in the [config
500
501
  file](#config-file-options) with the `workers` and `threads` options. By
501
- default, Photish will spawn a worker for each processor detected on the
502
- computer. It will then create 2 threads per worker. As each worker spawns it's
503
- own thread, for a computer with 4 processors, 4 workers will be created, each
504
- with 2 threads, which means in total Photish will manage 8 threads and
505
- potentially run 8 Image Magick processes concurrently. When tweaking the number
506
- of workers and threads it is important to consider IO bottlenecks as this will
507
- most likely be the limiting factor in performance.
502
+ default, Photish will spawn a thread for each processor detected on the
503
+ computer. It will then run this on a single worker.
504
+
505
+ When configuring more than 1 worker, it is important to remember that each
506
+ worker will spawn their own set of threads, if 4 workers are created, each with
507
+ 2 threads, it means in total Photish will manage 8 threads and potentially run
508
+ 8 Image Magick processes concurrently. When tweaking the number of workers and
509
+ threads it is important to consider IO bottlenecks as this will most likely be
510
+ the limiting factor in performance.
508
511
 
509
512
  #### Caching
510
513
 
@@ -516,7 +519,7 @@ The cache file is stored in the `output_dir` and is named `.changes.yml`.
516
519
 
517
520
  ##### Automatic Regeneration
518
521
 
519
- Images are regenerated when they are modified, renamed or moved.
522
+ Images are regenerated when a photo is modified, renamed or moved.
520
523
 
521
524
  Changing the `qualities` option in the config file will also trigger a full
522
525
  regeneration of all images.
@@ -533,6 +536,33 @@ on every change:
533
536
 
534
537
  $ photish host --force
535
538
 
539
+ ### Crude Performance Measures
540
+
541
+ Below are some crude performance measures to get a ballpark idea of how
542
+ Photish performs when generating for a large collection.
543
+
544
+ **Benchmark Computer:**
545
+
546
+ MacBook Pro (Retina, 13-inch, Early 2015)
547
+ 2.7 GHz Intel Core i5 (4 processors)
548
+ 8 GB 1867 MHz DDR3
549
+
550
+
551
+ Photos | Size (M) | Workers | Threads | Total Threads | Time (Seconds)
552
+ --------|----------|-----------|---------|---------------|----------------
553
+ 934 | 464 | 1 | 1 | 1 | 601
554
+ 934 | 464 | 2 | 1 | 2 | 367
555
+ 934 | 464 | 4 | 1 | 4 | 312
556
+ 934 | 464 | 8 | 1 | 8 | 328
557
+ 934 | 464 | 1 | 2 | 2 | 346
558
+ 934 | 464 | 1 | 4 | 4 | **288**
559
+ 934 | 464 | 1 | 8 | 8 | 290
560
+ 934 | 464 | 2 | 2 | 4 | 309
561
+
562
+ It is interesting to note the 20-30 second difference between using 4 workers
563
+ vs. 4 threads. The time difference is due to the setup time of creating a whole
564
+ new ruby process for each worker.
565
+
536
566
  ### Host
537
567
 
538
568
  To test and view your changes locally, the host command can be used to run a
@@ -587,7 +617,6 @@ called inside the template, it will render the message in bold wrapped in the
587
617
  **site/_plugins/shout.rb**
588
618
  ```ruby
589
619
  module Photish::Plugin::Shout
590
-
591
620
  def self.is_for?(type)
592
621
  Photish::Plugin::Type::Photo == type
593
622
  end
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ require "rspec/core/rake_task"
3
3
  require 'cucumber'
4
4
  require 'cucumber/rake/task'
5
5
  require 'photish/rake/task'
6
+ require 'metric_fu'
6
7
 
7
8
  RSpec::Core::RakeTask.new(:spec)
8
9
 
@@ -25,7 +26,8 @@ end
25
26
  task :default => [:clean,
26
27
  :spec,
27
28
  :features,
28
- :gather_coverage]
29
+ :gather_coverage,
30
+ 'metrics:all']
29
31
 
30
32
  namespace :photish do
31
33
  Photish::Rake::Task.new(:init, 'Creates a basic project') do |t|
data/TODO.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  ## In Progress
4
4
 
5
- 1. Look at error handling, exiting and cleanup (files, processes and threads)
6
-
7
5
  ## Backlog
8
6
 
9
7
  1. Plugin as a gem to deploy to github pages, netlify, amazon s3
@@ -22,7 +22,9 @@ module Photish
22
22
  end
23
23
 
24
24
  def flush_to_disk
25
- File.open(worker_db_file, 'w') { |f| f.write(worker_db.to_yaml) }
25
+ File.open(worker_db_file(worker_index), 'w') do
26
+ |f| f.write(worker_db.to_yaml)
27
+ end
26
28
  end
27
29
 
28
30
  def preload
@@ -37,6 +39,10 @@ module Photish
37
39
  :worker_index,
38
40
  :worker_db
39
41
 
42
+ delegate :db_file,
43
+ :worker_db_file,
44
+ to: :manifest_db_file
45
+
40
46
  def checksum_of_file(file_path)
41
47
  cache.fetch(file_path.hash) do |key|
42
48
  cache[key] = version_hash.to_s +
@@ -49,12 +55,8 @@ module Photish
49
55
  @db = File.exist?(db_file) ? YAML.load_file(db_file) : {}
50
56
  end
51
57
 
52
- def db_file
53
- ManifestDbFile.db_file(output_dir)
54
- end
55
-
56
- def worker_db_file
57
- ManifestDbFile.worker_db_file(output_dir, worker_index)
58
+ def manifest_db_file
59
+ ManifestDbFile.new(output_dir)
58
60
  end
59
61
  end
60
62
  end
@@ -1,33 +1,36 @@
1
1
  module Photish
2
2
  module Cache
3
- module ManifestDbFile
4
- def concat_db_files(output_dir, workers)
3
+ class ManifestDbFile
4
+ def initialize(output_dir)
5
+ @output_dir = output_dir
6
+ end
7
+
8
+ def concat_db_files(workers)
5
9
  changes = (1..workers).inject({}) do |accumulator, worker_index|
6
- file = worker_db_file(output_dir, worker_index)
10
+ file = worker_db_file(worker_index)
7
11
  accumulator.merge!(YAML.load_file(file)) if File.exist?(file)
8
12
  accumulator
9
13
  end
10
- File.open(db_file(output_dir), 'w') { |f| f.write(changes.to_yaml) }
14
+ File.open(db_file, 'w') { |f| f.write(changes.to_yaml) }
11
15
  end
12
16
 
13
- def clear(output_dir)
14
- FileUtils.rm_rf(db_file(output_dir))
17
+ def clear
18
+ FileUtils.rm_rf(db_file)
15
19
  end
16
20
 
17
- def db_file(output_dir)
21
+ def db_file
18
22
  FileUtils.mkdir_p(output_dir)
19
23
  File.join(output_dir, '.changes.yml')
20
24
  end
21
25
 
22
- def worker_db_file(output_dir, index)
26
+ def worker_db_file(index)
23
27
  FileUtils.mkdir_p(output_dir)
24
28
  File.join(output_dir, ".changes.#{index}.yml")
25
29
  end
26
30
 
27
- module_function :concat_db_files,
28
- :db_file,
29
- :worker_db_file,
30
- :clear
31
+ private
32
+
33
+ attr_reader :output_dir
31
34
  end
32
35
  end
33
36
  end
@@ -1,25 +1,23 @@
1
1
  module Photish
2
2
  module Command
3
3
  class Base
4
+ include Log::Loggable
5
+ include Log::SafeBlock
6
+
4
7
  def initialize(runtime_config)
5
8
  @runtime_config = runtime_config
6
- @log = Logging.logger[self]
7
9
  end
8
10
 
9
11
  def execute
10
12
  setup_logging
11
- begin
13
+ handle_errors(self.class.name) do
12
14
  run
13
- rescue => e
14
- log.fatal "An exception occured #{e.class} \"#{e.message}\" #{e.backtrace.join("\n")}"
15
- exit(false)
16
15
  end
17
16
  end
18
17
 
19
18
  protected
20
19
 
21
- attr_reader :runtime_config,
22
- :log
20
+ attr_reader :runtime_config
23
21
 
24
22
  delegate :config,
25
23
  :version_hash,
@@ -32,7 +30,7 @@ module Photish
32
30
  end
33
31
 
34
32
  def setup_logging
35
- Log::Logger.instance.setup_logging(config)
33
+ Log::LogSetup.instance.configure(config.logging)
36
34
  end
37
35
  end
38
36
  end
@@ -23,7 +23,7 @@ module Photish
23
23
  end
24
24
 
25
25
  def load_all_plugins
26
- Plugin::Repository.reload(log, site_dir)
26
+ Plugin::Repository.instance.reload(site_dir)
27
27
  end
28
28
 
29
29
  def engine_class
@@ -33,7 +33,7 @@ module Photish
33
33
  end
34
34
 
35
35
  def deploy_plugins
36
- Plugin::Repository.plugins_for(deploy_plugin_type)
36
+ Plugin::Repository.instance.plugins_for(deploy_plugin_type)
37
37
  end
38
38
 
39
39
  def deploy_plugin_type
@@ -2,13 +2,13 @@ module Photish
2
2
  module Command
3
3
  class Generate < Base
4
4
  def run
5
- log.info "Starting generation with #{workers} workers"
5
+ log.info "Generating with #{workers} workers and #{threads} threads"
6
6
 
7
- clear_cache if force_regeneration?
7
+ clear if force_regeneration?
8
8
  spawn_all_workers
9
9
  load_all_plugins
10
10
  wait_for_workers_to_complete
11
- concat_db_files
11
+ concat_db_files(workers)
12
12
  perform_serial_generation
13
13
 
14
14
  log.info "Generation completed successfully"
@@ -24,18 +24,19 @@ module Photish
24
24
  :photish_executable,
25
25
  :workers,
26
26
  :force,
27
+ :threads,
27
28
  to: :config
28
29
 
30
+ delegate :concat_db_files,
31
+ :clear,
32
+ to: :manifest_db_file
33
+
29
34
  def force_regeneration?
30
35
  force == true
31
36
  end
32
37
 
33
- def clear_cache
34
- Cache::ManifestDbFile.clear(output_dir)
35
- end
36
-
37
38
  def load_all_plugins
38
- Plugin::Repository.reload(log, site_dir)
39
+ Plugin::Repository.instance.reload(site_dir)
39
40
  end
40
41
 
41
42
  def spawn_all_workers
@@ -81,8 +82,8 @@ module Photish
81
82
  "--worker_index=#{worker_index}"].join(' ')
82
83
  end
83
84
 
84
- def concat_db_files
85
- Cache::ManifestDbFile.concat_db_files(output_dir, workers)
85
+ def manifest_db_file
86
+ Cache::ManifestDbFile.new(output_dir)
86
87
  end
87
88
  end
88
89
  end
@@ -2,8 +2,6 @@ module Photish
2
2
  module Command
3
3
  class Host < Base
4
4
  def run
5
- Photish::Log::Logger.instance.setup_logging(config)
6
-
7
5
  log.info "Site will be running at http://0.0.0.0:#{port}/"
8
6
  log.info "Monitoring paths #{paths_to_monitor}"
9
7
 
@@ -33,14 +31,20 @@ module Photish
33
31
 
34
32
  def regenerate_thread
35
33
  @regenerate_thread ||= Thread.new do
36
- loop do
37
- queue.pop
38
- queue.clear
39
- regenerate_entire_site
34
+ handle_errors('Regenerate Thread') do
35
+ regenerate_loop
40
36
  end
41
37
  end
42
38
  end
43
39
 
40
+ def regenerate_loop
41
+ loop do
42
+ queue.pop
43
+ queue.clear
44
+ regenerate_entire_site
45
+ end
46
+ end
47
+
44
48
  def server
45
49
  @server ||= WEBrick::HTTPServer.new(Port: port,
46
50
  DocumentRoot: output_dir,
@@ -49,14 +53,25 @@ module Photish
49
53
  end
50
54
 
51
55
  def listener
52
- @listener ||= Listen.to(*paths_to_monitor) do |modified, added, removed|
53
- log.info "File was modified #{modified}" if modified.present?
54
- log.info "File was added #{added}" if added.present?
55
- log.info "File was removed #{removed}" if removed.present?
56
- queue.push(modified || added || removed)
56
+ @listener ||= Listen.to(*paths_to_monitor) do |mod, add, del|
57
+ handle_errors('File Change Listener') do
58
+ handle_change(mod, add, del)
59
+ end
57
60
  end
58
61
  end
59
62
 
63
+ def handle_change(mod, add, del)
64
+ changes = changes_as_hash(mod, add, del)
65
+ log.info "File change detected: #{changes}}"
66
+ queue.push(changes)
67
+ end
68
+
69
+ def changes_as_hash(mod, add, del)
70
+ { modified: mod,
71
+ added: add,
72
+ removed: del, }
73
+ end
74
+
60
75
  def paths_to_monitor
61
76
  [site_dir,
62
77
  photo_dir]
@@ -21,8 +21,8 @@ module Photish
21
21
  to: :config
22
22
 
23
23
  def load_all_plugins
24
- return if Plugin::Repository.loaded?
25
- Plugin::Repository.reload(log, site_dir)
24
+ return if Plugin::Repository.instance.loaded?
25
+ Plugin::Repository.instance.reload(site_dir)
26
26
  end
27
27
 
28
28
  def render_whole_site
@@ -12,38 +12,54 @@ module Photish
12
12
  worker_index: 0,
13
13
  force: false,
14
14
  photish_executable: photish_executable,
15
- qualities: [
16
- { name: 'Original',
17
- params: [] },
18
- { name: 'Low',
19
- params: ['-resize', '200x200'] }
20
- ],
21
- templates: {
22
- layout: 'layout.slim',
23
- collection: 'collection.slim',
24
- album: 'album.slim',
25
- photo: 'photo.slim'
26
- },
27
- logging: {
28
- colorize: true,
29
- output: ['stdout', 'file'],
30
- level: 'info'
31
- },
32
- url: {
33
- host: '',
34
- base: nil
35
- }
15
+ qualities: qualities,
16
+ templates: templates,
17
+ logging: logging,
18
+ url: url
36
19
  }
37
20
  end
38
21
 
39
22
  private
40
23
 
24
+ def url
25
+ {
26
+ host: '',
27
+ base: nil
28
+ }
29
+ end
30
+
31
+ def logging
32
+ {
33
+ colorize: true,
34
+ output: ['stdout', 'file'],
35
+ level: 'info'
36
+ }
37
+ end
38
+
39
+ def templates
40
+ {
41
+ layout: 'layout.slim',
42
+ collection: 'collection.slim',
43
+ album: 'album.slim',
44
+ photo: 'photo.slim'
45
+ }
46
+ end
47
+
48
+ def qualities
49
+ [
50
+ { name: 'Original',
51
+ params: [] },
52
+ { name: 'Low',
53
+ params: ['-resize', '200x200'] }
54
+ ]
55
+ end
56
+
41
57
  def workers
42
- processor_count / 2
58
+ 1
43
59
  end
44
60
 
45
61
  def threads
46
- 2
62
+ processor_count
47
63
  end
48
64
 
49
65
  def processor_count
@@ -1,9 +1,7 @@
1
1
  module Photish
2
2
  module Log
3
3
  class AccessLog
4
- def initialize
5
- @log = Logging.logger[self]
6
- end
4
+ include Loggable
7
5
 
8
6
  def <<(message)
9
7
  log.info message.chomp
@@ -0,0 +1,87 @@
1
+ module Photish
2
+ module Log
3
+ class Formatter
4
+ def initialize(color)
5
+ @color = color
6
+ end
7
+
8
+ def call(severity, datetime, progname, msg)
9
+ LogLine.new(@color, severity, datetime, progname, msg).format
10
+ end
11
+
12
+ private
13
+
14
+ class LogLine
15
+ def initialize(color, severity, datetime, progname, msg)
16
+ @color = color
17
+ @severity = severity
18
+ @datetime = datetime
19
+ @progname = progname
20
+ @msg = msg
21
+ end
22
+
23
+ def format
24
+ line = ''
25
+ line << timestamp
26
+ line << pid
27
+ line << severity
28
+ line << progname
29
+ line << msg
30
+ line
31
+ end
32
+
33
+ private
34
+
35
+ SEV = {
36
+ 'DEBUG' => [:green, :default],
37
+ 'INFO' => [:green, :default],
38
+ 'WARN' => [:yellow, :default],
39
+ 'ERROR' => [:red, :default],
40
+ 'FATAL' => [:white, :red ],
41
+ }
42
+
43
+ def color?
44
+ !!@color
45
+ end
46
+
47
+ def severity
48
+ str = "#{@severity}"
49
+ str = str.colorize(color: SEV[@severity].first,
50
+ background: SEV[@severity].last) if color?
51
+ " #{str} "
52
+ end
53
+
54
+ def timestamp
55
+ str = "[#{@datetime.strftime("%Y-%m-%dT%H:%M:%S.%L")}]"
56
+ str = str.colorize(:cyan) if color?
57
+ str
58
+ end
59
+
60
+ def pid
61
+ str = "[#{Process.pid.to_s.rjust(5, '0')}]"
62
+ str = str.colorize(:light_magenta) if color?
63
+ str
64
+ end
65
+
66
+ def progname
67
+ str = "#{@progname}"
68
+ str = str.colorize(:magenta) if color?
69
+ str
70
+ end
71
+
72
+ def msg
73
+ str = ': '
74
+ if @msg.kind_of?(Exception)
75
+ str << "#{@msg.class} \"#{@msg.message}\"\n"
76
+ str << "#{@msg.backtrace.join("\n")}"
77
+ else
78
+ str << "#{@msg}"
79
+ end
80
+ str << "\n"
81
+ str = str.colorize(:light_blue) if color?
82
+ str
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,79 @@
1
+ module Photish
2
+ module Log
3
+ class LogSetup
4
+ LEVEL = {
5
+ debug: Logger::DEBUG,
6
+ info: Logger::INFO,
7
+ warn: Logger::WARN,
8
+ error: Logger::ERROR,
9
+ fatal: Logger::FATAL,
10
+ }
11
+
12
+ include Singleton
13
+
14
+ attr_accessor :setup_complete
15
+
16
+ def initialize
17
+ @config = nil
18
+ end
19
+
20
+ def configure(incoming_config)
21
+ return if config
22
+ @config = incoming_config
23
+ end
24
+
25
+ def new_logger(name)
26
+ logger = setup_new_logger(name, null_file)
27
+ logger.extend(stdout_broadcast(name)) if output_to_stdout?
28
+ logger.extend(file_broadcast(name)) if output_to_file?
29
+ logger
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :config
35
+
36
+ delegate :output,
37
+ :level,
38
+ :colorize,
39
+ to: :config
40
+
41
+ def null_file
42
+ File.open(File::NULL, 'w')
43
+ end
44
+
45
+ def setup_new_logger(name, stream)
46
+ logger = ActiveSupport::Logger.new(stream)
47
+ logger.progname = name
48
+ logger.level = logging_level
49
+ logger
50
+ end
51
+
52
+ def file_broadcast(name)
53
+ file = File.join('log', 'photish.log')
54
+ FileUtils.mkdir_p('log')
55
+ logger = setup_new_logger(name, file)
56
+ logger.formatter = Log::Formatter.new(false)
57
+ ActiveSupport::Logger.broadcast(logger)
58
+ end
59
+
60
+ def stdout_broadcast(name)
61
+ logger = setup_new_logger(name, STDOUT)
62
+ logger.formatter = Log::Formatter.new(colorize)
63
+ ActiveSupport::Logger.broadcast(logger)
64
+ end
65
+
66
+ def logging_level
67
+ LEVEL.fetch(level.try(:to_sym))
68
+ end
69
+
70
+ def output_to_stdout?
71
+ output.include?('stdout')
72
+ end
73
+
74
+ def output_to_file?
75
+ output.include?('file')
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,9 @@
1
+ module Photish
2
+ module Log
3
+ module Loggable
4
+ def log
5
+ @log ||= LogSetup.instance.new_logger(self.class.name)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module Photish
2
+ module Log
3
+ module SafeBlock
4
+ def handle_errors(name)
5
+ begin
6
+ yield
7
+ @runtime_error_occured = false
8
+ rescue Exception => e
9
+ log.fatal "#{name} died due to exception"
10
+ log.fatal e unless e.kind_of?(SystemExit)
11
+ Thread.list.each(&:kill)
12
+ exit(1)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,10 +2,15 @@ module Photish
2
2
  module Plugin
3
3
  module Pluginable
4
4
  def initialize(*_args)
5
- Photish::Plugin::Repository.plugins_for(self.plugin_type).each do |moduol|
5
+ plugins_for_type.each do |moduol|
6
6
  self.class.send(:include, moduol)
7
7
  end
8
8
  end
9
+
10
+ def plugins_for_type
11
+ Photish::Plugin::Repository.instance
12
+ .plugins_for(self.plugin_type)
13
+ end
9
14
  end
10
15
  end
11
16
  end
@@ -2,32 +2,14 @@ module Photish
2
2
  module Plugin
3
3
  class Repository
4
4
  include Singleton
5
+ include Log::Loggable
5
6
 
6
- class << self
7
- def reload(log, site_dir)
8
- self.instance.reload(log, site_dir)
9
- end
10
-
11
- def plugins_for(type)
12
- self.instance.plugins_for(type)
13
- end
14
-
15
- def loaded?
16
- self.instance.loaded?
17
- end
18
- end
19
-
20
- def reload(log, site_dir)
7
+ def reload(site_dir)
21
8
  log.info "Loading plugins..."
22
- Dir[File.join(site_dir, '_plugins', '*.rb')].each do |file|
23
- load file
24
- end
25
9
 
26
- @all_plugins = nil
27
-
28
- all_plugins.each do |plugin|
29
- log.info "Found plugin #{plugin}"
30
- end
10
+ load_each_plugin_file(site_dir)
11
+ clear_plugin_cache
12
+ load_each_plugin_constant
31
13
  end
32
14
 
33
15
  def plugins_for(type)
@@ -45,6 +27,22 @@ module Photish
45
27
 
46
28
  private
47
29
 
30
+ def load_each_plugin_constant
31
+ all_plugins.each do |plugin|
32
+ log.info "Found plugin #{plugin}"
33
+ end
34
+ end
35
+
36
+ def clear_plugin_cache
37
+ @all_plugins = nil
38
+ end
39
+
40
+ def load_each_plugin_file(site_dir)
41
+ Dir[File.join(site_dir, '_plugins', '*.rb')].each do |file|
42
+ load file
43
+ end
44
+ end
45
+
48
46
  def constants
49
47
  Photish::Plugin.constants
50
48
  end
@@ -1,12 +1,13 @@
1
1
  module Photish
2
2
  module Render
3
3
  class ImageConversion
4
+ include Log::Loggable
5
+
4
6
  def initialize(output_dir, worker_index, version_hash, threads)
5
7
  @output_dir = output_dir
6
8
  @worker_index = worker_index
7
9
  @version_hash = version_hash
8
10
  @threads = threads
9
- @log = Logging.logger[self]
10
11
  end
11
12
 
12
13
  def render(images)
@@ -21,7 +22,6 @@ module Photish
21
22
  private
22
23
 
23
24
  attr_reader :output_dir,
24
- :log,
25
25
  :worker_index,
26
26
  :version_hash,
27
27
  :threads
@@ -34,7 +34,9 @@ module Photish
34
34
 
35
35
  def spawn_thread_instances(image_queue)
36
36
  (0...threads).map do
37
- Thread.new { process_images(image_queue) }
37
+ Thread.new do
38
+ process_images(image_queue)
39
+ end
38
40
  end
39
41
  end
40
42
 
@@ -1,11 +1,12 @@
1
1
  module Photish
2
2
  module Render
3
3
  class Page
4
+ include Log::Loggable
5
+
4
6
  def initialize(layout_file, template_file, output_dir)
5
7
  @layout_file = layout_file
6
8
  @template_file = template_file
7
9
  @output_dir = output_dir
8
- @log = Logging.logger[self]
9
10
  end
10
11
 
11
12
  def render(models)
@@ -17,8 +18,7 @@ module Photish
17
18
 
18
19
  attr_reader :template_file,
19
20
  :layout_file,
20
- :output_dir,
21
- :log
21
+ :output_dir
22
22
 
23
23
  def render_all(models)
24
24
  Array(models).each do |model|
@@ -1,3 +1,3 @@
1
1
  module Photish
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
data/lib/photish.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # 3rd Party
2
2
  require 'mini_magick'
3
- require 'logging'
4
3
  require 'tilt'
5
4
  require 'rake'
6
5
  require 'active_support'
@@ -17,8 +16,14 @@ require 'mime-types'
17
16
  require 'thread'
18
17
  require 'thwait'
19
18
  require 'slim'
19
+ require 'colorize'
20
20
 
21
21
  # Photish
22
+ require 'photish/log/loggable'
23
+ require 'photish/log/formatter'
24
+ require 'photish/log/log_setup'
25
+ require 'photish/log/access_log'
26
+ require 'photish/log/safe_block'
22
27
  require 'photish/plugin/type'
23
28
  require 'photish/plugin/pluginable'
24
29
  require 'photish/plugin/repository'
@@ -29,10 +34,6 @@ require 'photish/command/host'
29
34
  require 'photish/command/init'
30
35
  require 'photish/command/deploy'
31
36
  require 'photish/cli/interface'
32
- require 'photish/log/logger'
33
- require 'photish/log/logger'
34
- require 'photish/log/access_log'
35
- require 'photish/log/logger'
36
37
  require 'photish/config/default_config'
37
38
  require 'photish/config/file_config'
38
39
  require 'photish/config/file_config_location'
data/photish.gemspec CHANGED
@@ -29,10 +29,10 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "mini_magick", "~> 4.3"
30
30
  spec.add_dependency "mini_exiftool", "~> 2.5"
31
31
  spec.add_dependency "recursive-open-struct", "~> 1.0"
32
- spec.add_dependency "logging", "~> 2.0"
33
32
  spec.add_dependency "listen", "~> 3.0"
34
33
  spec.add_dependency "facter", "~> 2.4"
35
34
  spec.add_dependency "mime-types", "~> 3.0"
35
+ spec.add_dependency "colorize", "~> 0.7.7"
36
36
 
37
37
  spec.add_development_dependency "anemone", "~> 0.7"
38
38
  spec.add_development_dependency "bundler", "~> 1.10"
@@ -43,4 +43,5 @@ Gem::Specification.new do |spec|
43
43
  spec.add_development_dependency "retriable"
44
44
  spec.add_development_dependency "codeclimate-test-reporter"
45
45
  spec.add_development_dependency "rspec-html-matchers"
46
+ spec.add_development_dependency "metric_fu"
46
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: photish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Lawson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-24 00:00:00.000000000 Z
11
+ date: 2015-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -109,61 +109,61 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: logging
112
+ name: listen
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '2.0'
117
+ version: '3.0'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '2.0'
124
+ version: '3.0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: listen
126
+ name: facter
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '3.0'
131
+ version: '2.4'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '3.0'
138
+ version: '2.4'
139
139
  - !ruby/object:Gem::Dependency
140
- name: facter
140
+ name: mime-types
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '2.4'
145
+ version: '3.0'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '2.4'
152
+ version: '3.0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: mime-types
154
+ name: colorize
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '3.0'
159
+ version: 0.7.7
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '3.0'
166
+ version: 0.7.7
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: anemone
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -290,6 +290,20 @@ dependencies:
290
290
  - - ">="
291
291
  - !ruby/object:Gem::Version
292
292
  version: '0'
293
+ - !ruby/object:Gem::Dependency
294
+ name: metric_fu
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - ">="
298
+ - !ruby/object:Gem::Version
299
+ version: '0'
300
+ type: :development
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
293
307
  description: |-
294
308
  Photish is a simple, convention based (but
295
309
  configurable) static photo site generator.
@@ -364,7 +378,10 @@ files:
364
378
  - lib/photish/gallery/traits/metadatable.rb
365
379
  - lib/photish/gallery/traits/urlable.rb
366
380
  - lib/photish/log/access_log.rb
367
- - lib/photish/log/logger.rb
381
+ - lib/photish/log/formatter.rb
382
+ - lib/photish/log/log_setup.rb
383
+ - lib/photish/log/loggable.rb
384
+ - lib/photish/log/safe_block.rb
368
385
  - lib/photish/plugin/pluginable.rb
369
386
  - lib/photish/plugin/repository.rb
370
387
  - lib/photish/plugin/type.rb
@@ -1,78 +0,0 @@
1
- module Photish
2
- module Log
3
- class Logger
4
- include Singleton
5
-
6
- attr_accessor :setup_complete
7
-
8
- def initialize
9
- @setup_complete = false
10
- end
11
-
12
- def setup_logging(config)
13
- return if setup_complete
14
-
15
- setup_color_scheme if colorize?(config)
16
- setup_stdout_output if output_to_stdout?(config)
17
- setup_file_output if output_to_file?(config)
18
-
19
- Logging.logger.root.level = logging_level(config)
20
- self.setup_complete = true
21
- end
22
-
23
- private
24
-
25
- def logging_level(config)
26
- config.logging.level.try(:to_sym)
27
- end
28
-
29
- def colorize?(config)
30
- config.logging.colorize
31
- end
32
-
33
- def output_to_stdout?(config)
34
- config.logging.output.include?('stdout')
35
- end
36
-
37
- def output_to_file?(config)
38
- config.logging.output.include?('file')
39
- end
40
-
41
- def setup_color_scheme
42
- Logging.color_scheme('bright',
43
- levels: {
44
- info: :green,
45
- warn: :yellow,
46
- error: :red,
47
- fatal: [:white, :on_red]
48
- },
49
- date: :blue,
50
- logger: :cyan,
51
- message: :magenta
52
- )
53
- end
54
-
55
- def setup_stdout_output
56
- stdout_appender = Logging.appenders.stdout(
57
- 'stdout',
58
- layout: Logging.layouts.pattern(
59
- pattern: '[%d][%p][%t] %-5l %c: %m\n',
60
- color_scheme: 'bright'
61
- )
62
- )
63
- Logging.logger.root.add_appenders(stdout_appender)
64
- end
65
-
66
- def setup_file_output
67
- FileUtils.mkdir_p('log')
68
- file_appender = Logging.appenders.file(
69
- 'log/photish.log',
70
- layout: Logging.layouts.pattern(
71
- pattern: '[%d][%p][%t] %-5l %c: %m\n',
72
- )
73
- )
74
- Logging.logger.root.add_appenders(file_appender)
75
- end
76
- end
77
- end
78
- end