dle 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 954b6dbb956a5a13cab35c61df14f1d614f246d2
4
- data.tar.gz: 5e80a17b73437a40587f6be58b1d0f48d87d33bf
3
+ metadata.gz: e4e369f0d5b31fd3d9ae966eb044321f9a48a3b2
4
+ data.tar.gz: 785f54970608d82c8c443059a3fc85214caeb83e
5
5
  SHA512:
6
- metadata.gz: 1a75351e1d3d18792ed530564364a773a8d5e7e83fe65cea779c232c6f35ad448184c93ef33f82085482bba4616962aea4283cb5d9390ca781b47d25eacbcafe
7
- data.tar.gz: 2e13b0f57002f7e517cbbbc166cd1aec9bd41d42a7cd6960711f19a18306d495f769e1cd36f98a5a818c18fcd58659e91fe151ae8a454517fd55501c1004e041
6
+ metadata.gz: 826305d9aafac83e780768cfa73bdf98b7f16ebae0e67a368e9715cb92d13205d240b6df3cb9273cbb24215f864afc1acc48b0182daae0e70fef8495c20242e7
7
+ data.tar.gz: 933374bee70087e1b3fa5292916f2d8d520aff847613fc72638b1d0643a7930652e7972e45099d645135c895f323b72057c05aa765b86d2538430712dae8a3df
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/bin/dle CHANGED
@@ -1,3 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "dle"
3
- Dle::Application.dispatch(ENV, ARGV)
3
+ begin
4
+ Dle::Application.dispatch(ENV, ARGV)
5
+ rescue Interrupt
6
+ puts("\n\nInterrupted")
7
+ exit 1
8
+ end
data/lib/dle.rb CHANGED
@@ -3,8 +3,10 @@ require "yaml"
3
3
  require "find"
4
4
  require "optparse"
5
5
  require "securerandom"
6
+ require "ostruct"
7
+ require "tempfile"
8
+ begin ; require "pry" ; rescue LoadError ; end
6
9
 
7
- require "pry"
8
10
  require "active_support/core_ext/object/blank"
9
11
  require "active_support/core_ext/object/try"
10
12
 
@@ -21,4 +23,5 @@ require "dle/application"
21
23
 
22
24
  module Dle
23
25
  ROOT = Pathname.new(File.expand_path("../..", __FILE__))
26
+ BASH_ENABLED = "#{ENV["SHELL"]}".downcase["bash"]
24
27
  end
@@ -8,6 +8,7 @@ module Dle
8
8
  class Application
9
9
  attr_reader :opts
10
10
  include Dispatch
11
+ include Helpers
11
12
 
12
13
  # =========
13
14
  # = Setup =
@@ -16,7 +17,11 @@ module Dle
16
17
  new(*a) do |app|
17
18
  app.parse_params
18
19
  app.log "core ready"
19
- app.dispatch
20
+ begin
21
+ app.dispatch
22
+ rescue Interrupt
23
+ app.abort("Interrupted", 1)
24
+ end
20
25
  end
21
26
  end
22
27
 
@@ -69,7 +69,7 @@ module Dle
69
69
  base_dir = ARGV[0].present? ? File.expand_path(ARGV[0].to_s) : ARGV[0].to_s
70
70
  if !FileTest.directory?(base_dir)
71
71
  if base_dir.present?
72
- abort c(ARGV[0].to_s, :magenta) << c(" is not a valid directory!", :red)
72
+ abort c(ARGV[0].to_s, :magenta) << c(" is not a valid directory!", :red), 1
73
73
  else
74
74
  dispatch(:help)
75
75
  abort "Please provide a base directory.", 1
@@ -78,8 +78,21 @@ module Dle
78
78
 
79
79
  # index filesystem
80
80
  log("index #{c base_dir, :magenta}")
81
- @fs = Filesystem.new(base_dir, dotfiles: @opts[:dotfiles])
81
+ logger.ensure_prefix c("[index]\t", :magenta) do
82
+ @fs = Filesystem.new(base_dir, dotfiles: @opts[:dotfiles])
83
+
84
+ notifier do
85
+ loop do
86
+ logger.raw("\033]0;#{human_number @fs.index.count} nodes indexed\007", :print) if BASH_ENABLED
87
+ sleep 1
88
+ end
89
+ end.perform do
90
+ @fs.reindex!
91
+ @fs.opts[:verbose] = false
92
+ end
93
+ end
82
94
  abort("Base directory is empty or not readable", 1) if @fs.index.empty?
95
+ log("indexed #{c "#{human_number @fs.index.count} nodes", :magenta}") if @fs.index.count > 1000
83
96
 
84
97
  file = "#{Dir.tmpdir}/#{SecureRandom.urlsafe_base64}"
85
98
  begin
@@ -87,6 +100,7 @@ module Dle
87
100
  if @opts[:input_file]
88
101
  ifile = File.expand_path(@opts[:input_file])
89
102
  if FileTest.file?(ifile) && FileTest.readable?(ifile)
103
+ log "processing file..."
90
104
  @dlfile = DlFile.parse(ifile)
91
105
  else
92
106
  abort "Input file not readable: " << c(ifile, :magenta)
@@ -94,10 +108,16 @@ module Dle
94
108
  else
95
109
  FileUtils.mkdir_p(File.dirname(file)) if !FileTest.exist?(File.dirname(file))
96
110
  if !FileTest.exist?(file) || File.read(file).strip.empty?
97
- File.open(file, "w") {|f| f.write @fs.to_dlfile }
111
+ notifier do
112
+ sleep 3
113
+ log "writing result list to file..."
114
+ end.perform do
115
+ File.open(file, "w") {|f| f.write @fs.to_dlfile }
116
+ end
98
117
  end
99
118
  log "open list for editing..."
100
119
  open_editor(file)
120
+ log "processing file..."
101
121
  @dlfile = DlFile.parse(file)
102
122
  end
103
123
 
@@ -138,12 +158,28 @@ module Dle
138
158
 
139
159
  # apply changes
140
160
  log "#{@opts[:simulate] ? "Simulating" : "Applying"} changes..."
141
- @delta.each do |action, snodes|
142
- logger.ensure_prefix c("[apply-#{action}]\t", :magenta) do
143
- snodes.each do |snode|
144
- Filesystem::Destructive.new(self, action, @fs, snode).perform
161
+ total_actions = @delta.map{|_, nodes| nodes.count }.inject(&:+)
162
+ actions_performed = 0
163
+ begin
164
+ notifier do
165
+ loop do
166
+ if BASH_ENABLED
167
+ logger.raw("\033]0;#{@opts[:simulate] ? "Simulated" : "Peformed"} #{human_number actions_performed}/#{human_number total_actions} changes\007", :print)
168
+ end
169
+ sleep 1
170
+ end
171
+ end.perform do
172
+ @delta.each do |action, snodes|
173
+ logger.ensure_prefix c("[apply-#{action}]\t", :magenta) do
174
+ snodes.each do |snode|
175
+ actions_performed += 1
176
+ Filesystem::Destructive.new(self, action, @fs, snode).perform
177
+ end
178
+ end
145
179
  end
146
180
  end
181
+ ensure
182
+ log "#{@opts[:simulate] ? "Simulated" : "Peformed"} #{human_number actions_performed} changes..."
147
183
  end
148
184
  end
149
185
  end
@@ -23,8 +23,8 @@ module Dle
23
23
  def initialize base_dir, opts = {}
24
24
  raise ArgumentError, "#{base_dir} is not a directory" unless FileTest.directory?(base_dir)
25
25
  @base_dir = File.expand_path(base_dir).freeze
26
- @opts = { dotfiles: true }.merge(opts)
27
- reindex!
26
+ @opts = { dotfiles: true, verbose: true }.merge(opts)
27
+ @index = {}
28
28
  end
29
29
 
30
30
  def reindex!
@@ -103,7 +103,13 @@ module Dle
103
103
  protected
104
104
 
105
105
  def index_node path
106
- Node.new(self, path).tap{|node| @index[node.inode] = node }
106
+ begin
107
+ Node.new(self, path).tap{|node| @index[node.inode] = node }
108
+ rescue Errno::EPERM
109
+ warn "Operation not permitted - #{path}" if @opts[:verbose]
110
+ rescue Errno::ENOENT
111
+ warn "No such file or directory (broken symlink?) - #{path}" if @opts[:verbose]
112
+ end
107
113
  end
108
114
  end
109
115
  end
@@ -12,6 +12,25 @@ module Dle
12
12
  ((s > 9 || s.modulo(1) < 0.1 ? '%d' : '%.1f') % s) + ' ' + BYTE_UNITS[i]
13
13
  end
14
14
 
15
+ def human_number(n)
16
+ n.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse
17
+ end
18
+
19
+ def notifier &block
20
+ OpenStruct.new.tap do |o|
21
+ o.callback = block
22
+
23
+ def o.perform &block
24
+ t = Thread.new(&callback)
25
+ begin
26
+ block.call(t)
27
+ ensure
28
+ t.kill
29
+ end
30
+ end
31
+ end
32
+ end
33
+
15
34
  def render_table table, headers = []
16
35
  [].tap do |r|
17
36
  col_sizes = table.map{|col| col.map(&:to_s).map(&:length).max }
@@ -1,4 +1,4 @@
1
1
  module Dle
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  UPDATE_URL = "https://raw.githubusercontent.com/2called-chaos/dle/master/VERSION"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Pachnit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry