progress-bar 0.3.7 → 0.5.0

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
- SHA1:
3
- metadata.gz: 67db22370ee46bd79b0397d0d2bc97fad6cc0ec2
4
- data.tar.gz: 8253f8eceaac27970c3461f4552c178c07ba4903
2
+ SHA256:
3
+ metadata.gz: 418c16be9ef733a3d968eeeeba7d786c634f55443b7e25fb5ff6cc612d7a258f
4
+ data.tar.gz: ed8c34644353846ef1190f9412c9669ac4047576b55cfa64712bf65047e1cbe9
5
5
  SHA512:
6
- metadata.gz: d87c0922a23b65462ef863000c52a115ded381f2f2753547106b0bcf356104c8b43fdf8549c8fcdfc4473273aa805a456f8a041a9ec906c8a93e0fa26fd58681
7
- data.tar.gz: e5eeff9d0f908222cd9d217605896f4c33a1d5c059c2913f8a47e92213ded8d9fc07aba283127cbb8d3aa492f956ef14a9266504af96cd93069d85253af4fcd4
6
+ metadata.gz: 00afdaed674191311bb652f64f2459f831dd7a599dbe3bbb13620f3f62751348518dcbb6d10c3ea6e3a9f218342f049ca1fdb237b0ed7ac07510c30dbef67dbe
7
+ data.tar.gz: 1acad6c43d132077e3dfff52dcfcd50ae0db893b476e1c28783fcee896ed11da7eb6546b3728e0de84acaf4c177cb75b3ca5f8f293e0ad9702507165abb2e700
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .*.sw[pq]
11
+ *.gem
data/Gemfile CHANGED
@@ -1,13 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
- gem 'ruby-dbus'
4
-
5
- # Add dependencies to develop your gem here.
6
- # Include everything needed to run rake, tests, features, etc.
7
- group :development do
8
- gem "shoulda", ">= 0"
9
- gem "rdoc", "~> 3.12"
10
- gem "bundler", "~> 1.0"
11
- gem "jeweler", "~> 2.0.1"
12
- gem "simplecov", ">= 0"
13
- end
3
+ # Specify your gem's dependencies in progress-bar.gemspec
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,82 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ progress-bar (0.5.0)
5
+ ruby-dbus (~> 0)
6
+
1
7
  GEM
2
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
3
9
  specs:
4
- activesupport (4.2.0)
5
- i18n (~> 0.7)
6
- json (~> 1.7, >= 1.7.7)
7
- minitest (~> 5.1)
8
- thread_safe (~> 0.3, >= 0.3.4)
9
- tzinfo (~> 1.1)
10
- addressable (2.3.6)
11
- builder (3.2.2)
12
- descendants_tracker (0.0.4)
13
- thread_safe (~> 0.3, >= 0.3.1)
14
- docile (1.1.5)
15
- faraday (0.9.0)
16
- multipart-post (>= 1.2, < 3)
17
- git (1.2.8)
18
- github_api (0.12.2)
19
- addressable (~> 2.3)
20
- descendants_tracker (~> 0.0.4)
21
- faraday (~> 0.8, < 0.10)
22
- hashie (>= 3.3)
23
- multi_json (>= 1.7.5, < 2.0)
24
- nokogiri (~> 1.6.3)
25
- oauth2
26
- hashie (3.3.2)
27
- highline (1.6.21)
28
- i18n (0.7.0)
29
- jeweler (2.0.1)
30
- builder
31
- bundler (>= 1.0)
32
- git (>= 1.2.5)
33
- github_api
34
- highline (>= 1.6.15)
35
- nokogiri (>= 1.5.10)
36
- rake
37
- rdoc
38
- json (1.8.1)
39
- jwt (1.2.0)
40
- mini_portile (0.6.1)
41
- minitest (5.5.0)
42
- multi_json (1.10.1)
43
- multi_xml (0.5.5)
44
- multipart-post (2.0.0)
45
- nokogiri (1.6.5)
46
- mini_portile (~> 0.6.0)
47
- oauth2 (1.0.0)
48
- faraday (>= 0.8, < 0.10)
49
- jwt (~> 1.0)
50
- multi_json (~> 1.3)
51
- multi_xml (~> 0.5)
52
- rack (~> 1.2)
53
- rack (1.6.0)
54
- rake (10.4.2)
55
- rdoc (3.12.2)
56
- json (~> 1.4)
57
- ruby-dbus (0.11.0)
58
- shoulda (3.5.0)
59
- shoulda-context (~> 1.0, >= 1.0.1)
60
- shoulda-matchers (>= 1.4.1, < 3.0)
61
- shoulda-context (1.2.1)
62
- shoulda-matchers (2.7.0)
63
- activesupport (>= 3.0.0)
64
- simplecov (0.9.1)
65
- docile (~> 1.1.0)
66
- multi_json (~> 1.0)
67
- simplecov-html (~> 0.8.0)
68
- simplecov-html (0.8.0)
69
- thread_safe (0.3.4)
70
- tzinfo (1.2.2)
71
- thread_safe (~> 0.1)
10
+ diff-lcs (1.4.4)
11
+ rake (12.3.3)
12
+ rspec (3.10.0)
13
+ rspec-core (~> 3.10.0)
14
+ rspec-expectations (~> 3.10.0)
15
+ rspec-mocks (~> 3.10.0)
16
+ rspec-core (3.10.1)
17
+ rspec-support (~> 3.10.0)
18
+ rspec-expectations (3.10.1)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.10.0)
21
+ rspec-mocks (3.10.2)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-support (3.10.2)
25
+ ruby-dbus (0.16.0)
72
26
 
73
27
  PLATFORMS
74
28
  ruby
75
29
 
76
30
  DEPENDENCIES
77
- bundler (~> 1.0)
78
- jeweler (~> 2.0.1)
79
- rdoc (~> 3.12)
80
- ruby-dbus
81
- shoulda
82
- simplecov
31
+ progress-bar!
32
+ rake (~> 12)
33
+ rspec (~> 3)
34
+
35
+ BUNDLED WITH
36
+ 2.2.11
data/LICENSE.txt CHANGED
@@ -1,20 +1,165 @@
1
- Copyright (c) 2014 Denis Knauf
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md CHANGED
@@ -1,23 +1,56 @@
1
1
  ProgressBar
2
2
  ===========
3
3
 
4
- Usage
5
- =====
6
-
7
- This example will use your Terminal, if possible.
8
- If your program will be started without a Terminal,
9
- it will use kdialog for display a window.
10
-
11
- pb = ProgressBar.new 100, 'Initial Text...'
12
- pb.i += 5
13
- pb.inc! 5
14
- pb.text = 'Something different'
15
- pb.inc! 20
16
- pb.text = 'Second phase'
17
- pb.inc! 60
18
- pb.text = 'Last Steps'
19
- pb.inc! 20
20
- pb.text = 'Done!'
21
-
22
- If you want to force to use kdialog use ProgressBar::KDialog.new or
23
- if you want to use your Console, use ProgressBar::Console.
4
+ Installation
5
+ ------------
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'progress-bar'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install progress-bar
20
+
21
+ ## Usage
22
+
23
+ There exist three different handlers for ProgressBar: `ProgressBar::KDE`, `ProgressBar::KDialog` and `ProgressBar::Console`.
24
+ These can be used directly, or you can use `ProgressBar.new` to determine the best solution.
25
+
26
+ If the process runs in a terminal, the `ProgressBar::Console` would be the best solution.
27
+ If you run KDE, `ProgressBar::KDE`, which uses JobViewer via DBUS, would be nice.
28
+ Else `ProgressBar::KDialog` will be tried.
29
+ Other handlers could be added in future.
30
+
31
+ ```ruby
32
+ pb = ProgressBar.new 100, 'Initialization...' # You expect 100 units (eg. percent)
33
+ ph.start
34
+ pb.i += 5 # 5 units done
35
+ pb.inc! 5 # additional 5 units done
36
+ pb.text = "Working..."
37
+ pb.i += 80
38
+ pb.text = "Last steps"
39
+ pb.i += 10
40
+ pb.text = "Done!"
41
+ pb.finish
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on [https://git.denkn.at/deac/progress-bar]().
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [LGPL-3.0 License](https://opensource.org/licenses/LGPL-3.0).
data/Rakefile CHANGED
@@ -1,51 +1,2 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
- gem.name = "progress-bar"
18
- gem.homepage = "http://github.com/DenisKnauf/progress-bar"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Progress Bar for terminal and KDE}
21
- gem.description = %Q{Displays a Progress Bar in terminal or via kdialog}
22
- gem.email = %q{#{"de"}nis}+?@+'den'+%Q{kn}+"#{?.}at"
23
- gem.authors = ["Denis Knauf"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
-
35
- desc "Code coverage detail"
36
- task :simplecov do
37
- ENV['COVERAGE'] = "true"
38
- Rake::Task['test'].execute
39
- end
40
-
41
- task :default => :test
42
-
43
- require 'rdoc/task'
44
- Rake::RDocTask.new do |rdoc|
45
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
-
47
- rdoc.rdoc_dir = 'rdoc'
48
- rdoc.title = "progress-bar #{version}"
49
- rdoc.rdoc_files.include('README*')
50
- rdoc.rdoc_files.include('lib/**/*.rb')
51
- end
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/lib/progress-bar.rb CHANGED
@@ -1,23 +1,31 @@
1
1
  require 'dbus'
2
+ require 'pathname'
2
3
 
3
4
  module ProgressBar
4
- def self.new *a
5
- if STDERR.tty?
6
- Console.new *a
7
- elsif 'KDE' == ENV['XDG_CURRENT_DESKTOP']
8
- KDialog.new *a
9
- else
10
- KDialog.new *a
5
+ @klasses ||= []
6
+
7
+ class <<self
8
+ def register klass
9
+ @klasses.push klass
10
+ end
11
+
12
+ def new *a, **o
13
+ @klasses.map {|cl| cl.new *a, **o}.find &:possible?
11
14
  end
12
15
  end
13
16
  end
14
17
 
15
18
  class ProgressBar::Base
16
- attr_reader :max, :i, :text, :error
17
- attr_accessor :start
18
- def initialize max = nil, text = nil
19
- @start, @max, @i, @text, @error = Time.now, max || 100, 0, text || '', nil
19
+ attr_reader :max, :i, :text
20
+ attr_accessor :startts
21
+ def initialize max = nil, text = nil, **_options
22
+ @startts, @max, @i, @text = nil, max || 100, 0, text || ''
23
+ end
24
+
25
+ def start
20
26
  at_exit {finish}
27
+ @startts = Time.now
28
+ self
21
29
  end
22
30
 
23
31
  def i= x
@@ -34,7 +42,7 @@ class ProgressBar::Base
34
42
  alias to_i i
35
43
  alias inc! increment!
36
44
  def done_rel() 100.0*i/max end
37
- def done_dur() Time.now-@start end
45
+ def done_dur() Time.now-@startts end
38
46
 
39
47
  def total_dur
40
48
  done_dur * max / i
@@ -45,21 +53,30 @@ class ProgressBar::Base
45
53
  change_text
46
54
  end
47
55
 
48
- def error= x
49
- @error = x
50
- change_error
51
- end
52
-
56
+ def error( text) end
53
57
  def change_progress() end
54
58
  def change_text() end
55
- def change_error() end
56
59
  def finish() end
60
+ def possible?() false end
57
61
  end
58
62
 
59
63
  class ProgressBar::Console < ProgressBar::Base
60
- def initialize *a
61
- super *a
64
+ attr_reader :outfd, :errfd
65
+
66
+ def initialize *a, outfd: nil, errfd: nil, **options
67
+ @outfd = outfd || STDERR
68
+ @errfd = errfd || @outfd
69
+ super *a, **options
70
+ end
71
+
72
+ def possible?
73
+ @outfd.tty?
74
+ end
75
+
76
+ def start
77
+ super
62
78
  change_text
79
+ self
63
80
  end
64
81
 
65
82
  def format_time t
@@ -75,37 +92,122 @@ class ProgressBar::Console < ProgressBar::Base
75
92
  dd, td = done_dur, total_dur
76
93
  b = ?= * l
77
94
  b[-1] = ?> unless 0 == l or 100 == l
78
- STDOUT.printf "\r\e[J%s / %s [%-*s] %s", format_time(dd), format_time(td), 100, b, text
95
+ @outfd.printf "\r\e[J%s / %s [%-*s] %s", format_time(dd), format_time(td), 100, b, text
79
96
  end
80
97
  alias change_progress change_text
81
98
 
82
- def change_error
83
- STDERR.printf "\r\e[J%s\n", error
84
- change_text
99
+ def error text
100
+ @errfd.printf "\r\e[J%s\n", text
101
+ @errfd.flush
102
+ end
103
+
104
+ def finish
105
+ @outfd.puts
106
+ @outfd.flush
107
+ end
108
+ end
109
+
110
+ class ProgressBar::KDE < ProgressBar::Base
111
+ attr_reader :bus, :service, :view
112
+
113
+ def initialize max, text = nil, title: nil,
114
+ app_name: nil,
115
+ app_icon_name: nil,
116
+ unit: nil,
117
+ is_cancable: nil,
118
+ is_suspendable: nil,
119
+ **_options
120
+
121
+ super max, text
122
+ text = @text
123
+ text = nil if text.nil? or text.empty?
124
+ title = nil if title.nil? or title.empty?
125
+ unit = '' if unit.nil? or unit.empty?
126
+ @title, @text, @unit, @app_name, @app_icon_name, @is_cancable, @is_suspendable =
127
+ title, text, unit, app_name || $0, app_icon_name || '', is_cancable, is_suspendable
128
+ @errors = []
129
+ end
130
+
131
+ def possible?
132
+ 'KDE' == ENV['XDG_CURRENT_DESKTOP']
133
+ end
134
+
135
+ def start
136
+ @finished = false
137
+ @bus = DBus::SessionBus.instance
138
+ @service = @bus['org.kde.JobViewServer']
139
+ jvs = @service['/JobViewServer'] #['org.kde.JobViewServer']
140
+ jvs.introspect
141
+ flags = (@is_cancable ? 0x1 : 0) | (@is_suspendable ? 0x2 : 0)
142
+ view_path = jvs.requestView @app_name, @app_icon_name, flags
143
+ @view = @service[view_path] #['org.kde.JobViewV2']
144
+ @view.introspect
145
+ super
146
+ @view.setTotalAmount @max, @unit
147
+ self
148
+ end
149
+
150
+ def change_text
151
+ @view.setInfoMessage text
152
+ end
153
+
154
+ def change_progress
155
+ @view.setProcessedAmount i, @unit
156
+ @view.setPercent done_rel
157
+ end
158
+
159
+ def error text
160
+ #STDERR.puts @view.object.introspect
161
+ #@view.setError text
162
+ @view.setDescriptionField 0, "Error", text
163
+ #@view.setInfoMessage "#{text}\nError: #{error}"
85
164
  end
86
165
 
87
166
  def finish
88
- STDERR.puts
167
+ return if @finished
168
+ @view.terminate ''
169
+ @finished = true
170
+ end
171
+
172
+ def max= value
173
+ super value
174
+ @view.setTotalAmount value, @unit
89
175
  end
90
176
  end
91
177
 
92
178
  class ProgressBar::KDialog < ProgressBar::Base
93
179
  attr_reader :dialog_service_path, :dialog_object_path, :errors, :dialog_object
94
- def initialize max, text = nil, title = nil
180
+
181
+ def initialize max, text = nil, title: nil, **_options
95
182
  super max, text
96
183
  text = @text
97
- text = nil if text.nil? or text.empty?
184
+ text = nil if text.nil? or text.empty?
98
185
  title = nil if title.nil? or title.empty?
186
+ @title = title
99
187
  @errors = []
100
- args = ['kdialog', *(title ? ['--title', title] : []), '--progressbar', text || '.', max.to_s]
101
- @dialog_service_path, @dialog_object_path = IO.popen( args, 'r', &:readlines).join("\n").split ' '
188
+ end
189
+
190
+ def possible?
191
+ path = Pathname.new `which kdialog`.chomp
192
+ $?.exitstatus and path.executable?
193
+ end
194
+
195
+ def start
196
+ @finished = false
197
+ args = ['kdialog', @title ? ['--title', @title] : [], '--progressbar', @text || '.', @max].flatten.compact.map &:to_s
198
+ @dialog_service_path, @dialog_object_path =
199
+ IO.popen( args, 'r', &:readlines).join( "\n").split ' '
102
200
  @dialog_bus = DBus.session_bus
103
201
  @dialog_service = @dialog_bus[@dialog_service_path]
104
- @dialog_object = @dialog_service.object @dialog_object_path
105
- @dialog_object.introspect
106
- @dialog_object.showCancelButton true
202
+ @dialog_object = @dialog_service[ @dialog_object_path]
203
+ #STDERR.puts "%p" %
204
+ @dialog_object.introspect
205
+ @dialog_object.showCancelButton 1
206
+ super
107
207
  change_text if text.nil?
108
208
  change_progress
209
+ self
210
+
109
211
  rescue DBus::Error
110
212
  raise Interrupt if $!.name == 'org.freedesktop.DBus.Error.ServiceUnknown'
111
213
  raise
@@ -119,8 +221,9 @@ class ProgressBar::KDialog < ProgressBar::Base
119
221
  def kdialog(*a) self.class.kdialog *a end
120
222
 
121
223
  def change_progress()
122
- @dialog_object.Set '', 'value', i
123
- raise Interrupt if @dialog_object.wasCancelled.first
224
+ #@dialog_object.Set 'org.kde.kdialog.ProgressDialog', 'value', i
225
+ @dialog_object['value'] = i
226
+ raise Interrupt if @dialog_object.wasCancelled
124
227
  rescue DBus::Error
125
228
  raise Interrupt if $!.name == 'org.freedesktop.DBus.Error.ServiceUnknown'
126
229
  raise
@@ -128,23 +231,28 @@ class ProgressBar::KDialog < ProgressBar::Base
128
231
 
129
232
  def change_text()
130
233
  @dialog_object.setLabelText text
131
- raise Interrupt if @dialog_object.wasCancelled.first
234
+ raise Interrupt if @dialog_object.wasCancelled
132
235
  rescue DBus::Error
133
236
  raise Interrupt if $!.name == 'org.freedesktop.DBus.Error.ServiceUnknown'
134
237
  raise
135
238
  end
136
239
 
137
- def change_error() @errors.push error end
138
- def finish()
139
- @dialog_object.close rescue DBus::Error
140
- kdialog '--detailederror', "Some errors occured:", errors.join( "<br/>\n") unless errors.empty?
240
+ def error text
241
+ kdialog '--error', text
141
242
  end
142
243
 
143
- def max= val
144
- @dialog_object.Set '', 'maximum', val
244
+ def finish()
245
+ return if @finished
246
+ @dialog_object.close rescue DBus::Error
247
+ @finished = true
145
248
  end
146
249
 
147
- def max
148
- @dialog_object.Get '', 'maximum'
250
+ def max= val
251
+ super val
252
+ @dialog_object['maximum'] = val
149
253
  end
150
254
  end
255
+
256
+ ProgressBar.register ProgressBar::Console
257
+ ProgressBar.register ProgressBar::KDE
258
+ ProgressBar.register ProgressBar::KDialog
@@ -0,0 +1,3 @@
1
+ module ProgressBar
2
+ VERSION = "0.5.0"
3
+ end
data/progress-bar.gemspec CHANGED
@@ -1,65 +1,26 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ require_relative "lib/progress-bar/version"
5
2
 
6
- Gem::Specification.new do |s|
7
- s.name = "progress-bar"
8
- s.version = "0.3.7"
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "progress-bar"
5
+ spec.version = ProgressBar::VERSION
6
+ spec.authors = ["Denis Knauf"]
7
+ spec.email = ["denis+gems@denkn.at"]
9
8
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Denis Knauf"]
12
- s.date = "2014-12-24"
13
- s.description = "Displays a Progress Bar in terminal or via kdialog"
14
- s.email = "\#{\"de\"}nis@denkn.at"
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE.txt",
24
- "README.md",
25
- "Rakefile",
26
- "VERSION",
27
- "lib/progress-bar.rb",
28
- "progress-bar.gemspec",
29
- "test/helper.rb",
30
- "test/test_progress-bar.rb"
31
- ]
32
- s.homepage = "http://github.com/DenisKnauf/progress-bar"
33
- s.licenses = ["MIT"]
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = "2.0.14"
36
- s.summary = "Progress Bar for terminal and KDE"
9
+ spec.summary = %q{Progress Bar for terminal and KDE}
10
+ spec.description = %q{Displays a Progress Bar in terminal, via KDE-JobViewer or via kdialog}
11
+ spec.homepage = "https://git.denkn.at/deac/progress-bar"
12
+ spec.licenses = ["LGPL-3.0"]
37
13
 
38
- if s.respond_to? :specification_version then
39
- s.specification_version = 4
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ #spec.bindir = "bin"
20
+ #spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
40
22
 
41
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_runtime_dependency(%q<ruby-dbus>, [">= 0"])
43
- s.add_development_dependency(%q<shoulda>, [">= 0"])
44
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
45
- s.add_development_dependency(%q<bundler>, ["~> 1.0"])
46
- s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
47
- s.add_development_dependency(%q<simplecov>, [">= 0"])
48
- else
49
- s.add_dependency(%q<ruby-dbus>, [">= 0"])
50
- s.add_dependency(%q<shoulda>, [">= 0"])
51
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
52
- s.add_dependency(%q<bundler>, ["~> 1.0"])
53
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
54
- s.add_dependency(%q<simplecov>, [">= 0"])
55
- end
56
- else
57
- s.add_dependency(%q<ruby-dbus>, [">= 0"])
58
- s.add_dependency(%q<shoulda>, [">= 0"])
59
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
60
- s.add_dependency(%q<bundler>, ["~> 1.0"])
61
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
62
- s.add_dependency(%q<simplecov>, [">= 0"])
63
- end
23
+ spec.add_development_dependency "rake", "~> 12"
24
+ spec.add_development_dependency "rspec", "~> 3"
25
+ spec.add_dependency "ruby-dbus", '~> 0'
64
26
  end
65
-
metadata CHANGED
@@ -1,121 +1,76 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progress-bar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Knauf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-24 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: ruby-dbus
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
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
- - - '>='
17
+ - - "~>"
25
18
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: shoulda
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
19
+ version: '12'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - '>='
24
+ - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '12'
41
27
  - !ruby/object:Gem::Dependency
42
- name: rdoc
28
+ name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ~>
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '3.12'
33
+ version: '3'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ~>
38
+ - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '3.12'
40
+ version: '3'
55
41
  - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '1.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: '1.0'
69
- - !ruby/object:Gem::Dependency
70
- name: jeweler
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ~>
74
- - !ruby/object:Gem::Version
75
- version: 2.0.1
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ~>
81
- - !ruby/object:Gem::Version
82
- version: 2.0.1
83
- - !ruby/object:Gem::Dependency
84
- name: simplecov
42
+ name: ruby-dbus
85
43
  requirement: !ruby/object:Gem::Requirement
86
44
  requirements:
87
- - - '>='
45
+ - - "~>"
88
46
  - !ruby/object:Gem::Version
89
47
  version: '0'
90
- type: :development
48
+ type: :runtime
91
49
  prerelease: false
92
50
  version_requirements: !ruby/object:Gem::Requirement
93
51
  requirements:
94
- - - '>='
52
+ - - "~>"
95
53
  - !ruby/object:Gem::Version
96
54
  version: '0'
97
- description: Displays a Progress Bar in terminal or via kdialog
98
- email: '#{"de"}nis@denkn.at'
55
+ description: Displays a Progress Bar in terminal, via KDE-JobViewer or via kdialog
56
+ email:
57
+ - denis+gems@denkn.at
99
58
  executables: []
100
59
  extensions: []
101
- extra_rdoc_files:
102
- - LICENSE.txt
103
- - README.md
60
+ extra_rdoc_files: []
104
61
  files:
105
- - .document
62
+ - ".gitignore"
106
63
  - Gemfile
107
64
  - Gemfile.lock
108
65
  - LICENSE.txt
109
66
  - README.md
110
67
  - Rakefile
111
- - VERSION
112
68
  - lib/progress-bar.rb
69
+ - lib/progress-bar/version.rb
113
70
  - progress-bar.gemspec
114
- - test/helper.rb
115
- - test/test_progress-bar.rb
116
- homepage: http://github.com/DenisKnauf/progress-bar
71
+ homepage: https://git.denkn.at/deac/progress-bar
117
72
  licenses:
118
- - MIT
73
+ - LGPL-3.0
119
74
  metadata: {}
120
75
  post_install_message:
121
76
  rdoc_options: []
@@ -123,17 +78,16 @@ require_paths:
123
78
  - lib
124
79
  required_ruby_version: !ruby/object:Gem::Requirement
125
80
  requirements:
126
- - - '>='
81
+ - - ">="
127
82
  - !ruby/object:Gem::Version
128
83
  version: '0'
129
84
  required_rubygems_version: !ruby/object:Gem::Requirement
130
85
  requirements:
131
- - - '>='
86
+ - - ">="
132
87
  - !ruby/object:Gem::Version
133
88
  version: '0'
134
89
  requirements: []
135
- rubyforge_project:
136
- rubygems_version: 2.0.14
90
+ rubygems_version: 3.1.2
137
91
  signing_key:
138
92
  specification_version: 4
139
93
  summary: Progress Bar for terminal and KDE
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.7
data/test/helper.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'simplecov'
2
-
3
- module SimpleCov::Configuration
4
- def clean_filters
5
- @filters = []
6
- end
7
- end
8
-
9
- SimpleCov.configure do
10
- clean_filters
11
- load_adapter 'test_frameworks'
12
- end
13
-
14
- ENV["COVERAGE"] && SimpleCov.start do
15
- add_filter "/.rvm/"
16
- end
17
- require 'rubygems'
18
- require 'bundler'
19
- begin
20
- Bundler.setup(:default, :development)
21
- rescue Bundler::BundlerError => e
22
- $stderr.puts e.message
23
- $stderr.puts "Run `bundle install` to install missing gems"
24
- exit e.status_code
25
- end
26
- require 'test/unit'
27
- require 'shoulda'
28
-
29
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
- $LOAD_PATH.unshift(File.dirname(__FILE__))
31
- require 'progress-bar'
32
-
33
- class Test::Unit::TestCase
34
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestProgressBar < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end