but 0.1.3 → 0.1.8

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
  SHA256:
3
- metadata.gz: 7a401f4f83816e46b9a0a8dd97b84f4da1c1ef3141e20c750d902a98ca7050b5
4
- data.tar.gz: bf75f25a1d4f0eca838d60f7b7f21c1db3ad3e18f1398b3387d7b1d414b4e3a4
3
+ metadata.gz: d1e0e7f89684475a8ab03efce23401e10563fcd76b52ad811007437900892866
4
+ data.tar.gz: 1eb6a7f6f0f809a0e1a573f306702839d20cdc1c044c9ef0f64d2a6d53e9c95c
5
5
  SHA512:
6
- metadata.gz: f6e61db7075302c71a5ac845aeb85433a75fbe44d90e785a81ebf0025ff80bde37e4436678f2a1d445d5438b73b1cc9905ff3222ae33de9683478e06337c3fa1
7
- data.tar.gz: 6b854b4002ec51e9577ab01e0cc0b05280dff03741e1add324d048cad06ce11cae2c036c073ee765c05896e51a622def90f44008f6177145711b63d67f409431
6
+ metadata.gz: 8da2f660ae317bf5be7bbf3709d8ca9b1abf112046dfbfe14b5bd758e1cd50dc85eb9327a27e00c2fa21c92bcdfac0c45485e2b250851daaa7370ab0f8cabc92
7
+ data.tar.gz: 30f680abc3f62da8ae30042a3ab8278496f8ed623a4d986b012e37daee332c8d04b344b05db72576a852165dcd86cfdf15ec967e1a53de0266fb842a69651482
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- but (0.1.3)
4
+ but (0.1.8)
5
5
  colorize
6
6
  ruby-prof
7
+ ruby-progressbar
7
8
  thor
8
9
 
9
10
  GEM
data/README.md CHANGED
@@ -130,7 +130,7 @@ but command --profile MEMORY
130
130
 
131
131
  ### Contributing
132
132
 
133
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/but. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
133
+ Bug reports and pull requests are welcome on GitLab at https://git.computational.bio.uni-giessen.de/rmueller/bcf_user_tools. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
134
134
 
135
135
  ### License
136
136
 
@@ -138,5 +138,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
138
138
 
139
139
  ### Code of Conduct
140
140
 
141
- Everyone interacting in the But project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/but/blob/master/CODE_OF_CONDUCT.md).
141
+ Everyone interacting in the But project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://git.computational.bio.uni-giessen.de/rmueller/bcf_user_tools/-/blob/master/CODE_OF_CONDUCT.md).
142
142
 
@@ -9,6 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["raphael.mueller@computational.bio.uni-giessen.de"]
10
10
  spec.homepage = 'https://git.computational.bio.uni-giessen.de/rmueller/bcf_user_tools'
11
11
  spec.license = "MIT"
12
+ spec.required_ruby_version = '>=2.6.0'
12
13
  spec.summary = "Tools, to help users to improve their experience with the BCF infrastructure."
13
14
  spec.description = "BCF admins have a hard live. Their user's don't keep their $HOMES and other working places clean. It appears that some users don't know that they use too much space in their home or don't clean used directories on cluster (or other) machines. This tools helps users find unused and unwanted directories, which could make BCF admins happier."
14
15
 
@@ -49,6 +50,7 @@ Gem::Specification.new do |spec|
49
50
  spec.add_dependency 'thor'
50
51
  spec.add_dependency 'colorize'
51
52
  spec.add_dependency 'ruby-prof'
53
+ spec.add_dependency 'ruby-progressbar'
52
54
 
53
55
 
54
56
  spec.metadata = { "source_code_uri" => "https://git.computational.bio.uni-giessen.de/rmueller/bcf_user_tools" }
@@ -1,9 +1,11 @@
1
1
  require 'open3'
2
2
  require 'tempfile'
3
3
  require 'colorize'
4
+ require 'ruby-progressbar'
4
5
 
5
6
  module But
6
7
  module HomeKeeper
8
+ BLOCK_SIZE = 1024
7
9
 
8
10
  def self.info(options = {})
9
11
  file = ENV['BUTHOMEKEEPER'] || create_disk_usage_file(options)
@@ -15,9 +17,9 @@ module But
15
17
  total_disc_usage = total_disc_usage.to_i
16
18
 
17
19
  if total_disc_usage >= But::HOMELIMIT
18
- return "Dare you! Your directory #{dir} contains #{total_disc_usage}, which is #{total_disc_usage - But::HOMELIMIT} above the limit of #{But::HOMELIMIT}. Dare you!".red
20
+ return "Dare you! Your directory #{dir} contains ~#{h_readable total_disc_usage}, which is ~#{h_readable (total_disc_usage - But::HOMELIMIT)} above the limit of #{h_readable But::HOMELIMIT}. Dare you!".red
19
21
  else
20
- return "Good job! Your directory #{dir} takes only #{total_disc_usage} disk storage. Good job!".light_green
22
+ return "Good job! Your directory #{dir} takes only ~#{h_readable total_disc_usage} disk storage. Good job!".light_green
21
23
  end
22
24
  end
23
25
 
@@ -26,17 +28,70 @@ module But
26
28
  def self.create_disk_usage_file(options = {})
27
29
  tmpfile = ::Tempfile.new("diskusage")
28
30
  dir = options[:dir] || ENV['HOME']
29
- ::Open3.popen3("du","-d 0", dir) do |stdin, stdout, stderr, wait_thr|
30
31
 
31
- if wait_thr.value != 0
32
- STDERR.write "Exitcode: #{wait_thr.value}\n".light_black
33
- STDERR.write stderr.gets(nil).light_black
32
+ total_lines = `ls -d ~/.*/ ~/*/ | wc -l`.to_i
33
+ #puts total_lines
34
+ progressbar = ProgressBar.create(title: "inspecting #{dir}", total: total_lines ,
35
+ :format => "%a %c/%C %b\u{15E7}%i %p%% %t",
36
+ :progress_mark => ' ',
37
+ :remainder_mark => "\u{FF65}",
38
+ )
39
+
40
+ ::Open3.popen3("du","-d 1", dir) do |stdin, stdout, stderr, wait_thr|
41
+ # inspired by from https://gist.github.com/chrisn/7450808
42
+
43
+ stdin.close_write
44
+ begin
45
+ files = [stdout, stderr]
46
+ until all_eof(files) do
47
+ ready = IO.select(files)
48
+ progressbar.refresh
49
+
50
+ if ready
51
+ readable = ready[0]
52
+ readable.each do |f|
53
+ fileno = f.fileno
54
+
55
+ begin
56
+ data = f.read_nonblock(BLOCK_SIZE)
57
+
58
+ #puts "fileno: #{fileno}, data: #{data.inspect}"
59
+ progressbar.progress += data.lines.count
60
+ progressbar.title = "completed: %s" % data.split(/\s+/).last
61
+ tmpfile.write(data)
62
+ rescue EOFError => e
63
+ #puts "fileno: #{fileno} EOF"
64
+ files.delete f
65
+ end
66
+ end
67
+ end
68
+ end
69
+ rescue IOError => e
70
+ puts "IOError: #{e}"
34
71
  end
35
72
 
36
- tmpfile.write(stdout.gets(nil))
73
+
74
+ #if wait_thr.value != 0
75
+ # STDERR.write "Exitcode: #{wait_thr.value}\n".light_black
76
+ # STDERR.write stderr.gets(nil).light_black
77
+ #end
78
+
79
+ #tmpfile.write(stdout.gets(nil))
37
80
  end
81
+ progressbar.finish
38
82
  tmpfile.rewind
39
83
  return tmpfile.path
40
84
  end
85
+
86
+ private
87
+
88
+ def self.all_eof(files)
89
+ files.find { |f| !f.eof }.nil?
90
+ end
91
+
92
+ def self.h_readable(bytes)
93
+ return "%.2f GB"% (bytes / (1024.0 * 1024.0))
94
+ end
95
+
41
96
  end
42
97
  end
@@ -1,3 +1,3 @@
1
1
  module But
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: but
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raphael Müller
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: ruby-progressbar
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
195
209
  description: BCF admins have a hard live. Their user's don't keep their $HOMES and
196
210
  other working places clean. It appears that some users don't know that they use
197
211
  too much space in their home or don't clean used directories on cluster (or other)
@@ -243,7 +257,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
257
  requirements:
244
258
  - - ">="
245
259
  - !ruby/object:Gem::Version
246
- version: '0'
260
+ version: 2.6.0
247
261
  required_rubygems_version: !ruby/object:Gem::Requirement
248
262
  requirements:
249
263
  - - ">="