init
This commit is contained in:
commit
55d6b8a465
11 changed files with 395 additions and 0 deletions
5
.document
Normal file
5
.document
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
lib/**/*.rb
|
||||||
|
bin/*
|
||||||
|
-
|
||||||
|
features/**/*.feature
|
||||||
|
LICENSE.txt
|
49
.gitignore
vendored
Normal file
49
.gitignore
vendored
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
# rcov generated
|
||||||
|
coverage
|
||||||
|
coverage.data
|
||||||
|
|
||||||
|
# rdoc generated
|
||||||
|
rdoc
|
||||||
|
|
||||||
|
# yard generated
|
||||||
|
doc
|
||||||
|
.yardoc
|
||||||
|
|
||||||
|
# bundler
|
||||||
|
.bundle
|
||||||
|
|
||||||
|
# jeweler generated
|
||||||
|
pkg
|
||||||
|
|
||||||
|
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
||||||
|
#
|
||||||
|
# * Create a file at ~/.gitignore
|
||||||
|
# * Include files you want ignored
|
||||||
|
# * Run: git config --global core.excludesfile ~/.gitignore
|
||||||
|
#
|
||||||
|
# After doing this, these files will be ignored in all your git projects,
|
||||||
|
# saving you from having to 'pollute' every project you touch with them
|
||||||
|
#
|
||||||
|
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
||||||
|
#
|
||||||
|
# For MacOS:
|
||||||
|
#
|
||||||
|
#.DS_Store
|
||||||
|
|
||||||
|
# For TextMate
|
||||||
|
#*.tmproj
|
||||||
|
#tmtags
|
||||||
|
|
||||||
|
# For emacs:
|
||||||
|
#*~
|
||||||
|
#\#*
|
||||||
|
#.\#*
|
||||||
|
|
||||||
|
# For vim:
|
||||||
|
#*.swp
|
||||||
|
|
||||||
|
# For redcar:
|
||||||
|
#.redcar
|
||||||
|
|
||||||
|
# For rubinius:
|
||||||
|
#*.rbc
|
13
Gemfile
Normal file
13
Gemfile
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
source "http://rubygems.org"
|
||||||
|
|
||||||
|
gem 'ruby-dbus'
|
||||||
|
|
||||||
|
# Add dependencies to develop your gem here.
|
||||||
|
# Include everything needed to run rake, tests, features, etc.
|
||||||
|
group :development do
|
||||||
|
gem "shoulda", ">= 0"
|
||||||
|
gem "rdoc", "~> 3.12"
|
||||||
|
gem "bundler", "~> 1.0"
|
||||||
|
gem "jeweler", "~> 2.0.1"
|
||||||
|
gem "simplecov", ">= 0"
|
||||||
|
end
|
82
Gemfile.lock
Normal file
82
Gemfile.lock
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
GEM
|
||||||
|
remote: http://rubygems.org/
|
||||||
|
specs:
|
||||||
|
activesupport (4.2.0)
|
||||||
|
i18n (~> 0.7)
|
||||||
|
json (~> 1.7, >= 1.7.7)
|
||||||
|
minitest (~> 5.1)
|
||||||
|
thread_safe (~> 0.3, >= 0.3.4)
|
||||||
|
tzinfo (~> 1.1)
|
||||||
|
addressable (2.3.6)
|
||||||
|
builder (3.2.2)
|
||||||
|
descendants_tracker (0.0.4)
|
||||||
|
thread_safe (~> 0.3, >= 0.3.1)
|
||||||
|
docile (1.1.5)
|
||||||
|
faraday (0.9.0)
|
||||||
|
multipart-post (>= 1.2, < 3)
|
||||||
|
git (1.2.8)
|
||||||
|
github_api (0.12.2)
|
||||||
|
addressable (~> 2.3)
|
||||||
|
descendants_tracker (~> 0.0.4)
|
||||||
|
faraday (~> 0.8, < 0.10)
|
||||||
|
hashie (>= 3.3)
|
||||||
|
multi_json (>= 1.7.5, < 2.0)
|
||||||
|
nokogiri (~> 1.6.3)
|
||||||
|
oauth2
|
||||||
|
hashie (3.3.2)
|
||||||
|
highline (1.6.21)
|
||||||
|
i18n (0.7.0)
|
||||||
|
jeweler (2.0.1)
|
||||||
|
builder
|
||||||
|
bundler (>= 1.0)
|
||||||
|
git (>= 1.2.5)
|
||||||
|
github_api
|
||||||
|
highline (>= 1.6.15)
|
||||||
|
nokogiri (>= 1.5.10)
|
||||||
|
rake
|
||||||
|
rdoc
|
||||||
|
json (1.8.1)
|
||||||
|
jwt (1.2.0)
|
||||||
|
mini_portile (0.6.1)
|
||||||
|
minitest (5.5.0)
|
||||||
|
multi_json (1.10.1)
|
||||||
|
multi_xml (0.5.5)
|
||||||
|
multipart-post (2.0.0)
|
||||||
|
nokogiri (1.6.5)
|
||||||
|
mini_portile (~> 0.6.0)
|
||||||
|
oauth2 (1.0.0)
|
||||||
|
faraday (>= 0.8, < 0.10)
|
||||||
|
jwt (~> 1.0)
|
||||||
|
multi_json (~> 1.3)
|
||||||
|
multi_xml (~> 0.5)
|
||||||
|
rack (~> 1.2)
|
||||||
|
rack (1.6.0)
|
||||||
|
rake (10.4.2)
|
||||||
|
rdoc (3.12.2)
|
||||||
|
json (~> 1.4)
|
||||||
|
ruby-dbus (0.11.0)
|
||||||
|
shoulda (3.5.0)
|
||||||
|
shoulda-context (~> 1.0, >= 1.0.1)
|
||||||
|
shoulda-matchers (>= 1.4.1, < 3.0)
|
||||||
|
shoulda-context (1.2.1)
|
||||||
|
shoulda-matchers (2.7.0)
|
||||||
|
activesupport (>= 3.0.0)
|
||||||
|
simplecov (0.9.1)
|
||||||
|
docile (~> 1.1.0)
|
||||||
|
multi_json (~> 1.0)
|
||||||
|
simplecov-html (~> 0.8.0)
|
||||||
|
simplecov-html (0.8.0)
|
||||||
|
thread_safe (0.3.4)
|
||||||
|
tzinfo (1.2.2)
|
||||||
|
thread_safe (~> 0.1)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
ruby
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
bundler (~> 1.0)
|
||||||
|
jeweler (~> 2.0.1)
|
||||||
|
rdoc (~> 3.12)
|
||||||
|
ruby-dbus
|
||||||
|
shoulda
|
||||||
|
simplecov
|
20
LICENSE.txt
Normal file
20
LICENSE.txt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
Copyright (c) 2014 Denis Knauf
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
README.rdoc
Normal file
19
README.rdoc
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
= progress-bar
|
||||||
|
|
||||||
|
Description goes here.
|
||||||
|
|
||||||
|
== Contributing to progress-bar
|
||||||
|
|
||||||
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
||||||
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
||||||
|
* Fork the project.
|
||||||
|
* Start a feature/bugfix branch.
|
||||||
|
* Commit and push until you are happy with your contribution.
|
||||||
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
||||||
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
||||||
|
|
||||||
|
== Copyright
|
||||||
|
|
||||||
|
Copyright (c) 2014 Denis Knauf. See LICENSE.txt for
|
||||||
|
further details.
|
||||||
|
|
51
Rakefile
Normal file
51
Rakefile
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
require 'rubygems'
|
||||||
|
require 'bundler'
|
||||||
|
begin
|
||||||
|
Bundler.setup(:default, :development)
|
||||||
|
rescue Bundler::BundlerError => e
|
||||||
|
$stderr.puts e.message
|
||||||
|
$stderr.puts "Run `bundle install` to install missing gems"
|
||||||
|
exit e.status_code
|
||||||
|
end
|
||||||
|
require 'rake'
|
||||||
|
|
||||||
|
require 'jeweler'
|
||||||
|
Jeweler::Tasks.new do |gem|
|
||||||
|
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
||||||
|
gem.name = "progress-bar"
|
||||||
|
gem.homepage = "http://github.com/DenisKnauf/progress-bar"
|
||||||
|
gem.license = "MIT"
|
||||||
|
gem.summary = %Q{Progress Bar for terminal and KDE}
|
||||||
|
gem.description = %Q{TODO: longer description of your gem}
|
||||||
|
gem.email = %q{#{"de"}nis}+?@+'den'+%Q{kn}+"#{?.}at"
|
||||||
|
gem.authors = ["Denis Knauf"]
|
||||||
|
# dependencies defined in Gemfile
|
||||||
|
end
|
||||||
|
Jeweler::RubygemsDotOrgTasks.new
|
||||||
|
|
||||||
|
require 'rake/testtask'
|
||||||
|
Rake::TestTask.new(:test) do |test|
|
||||||
|
test.libs << 'lib' << 'test'
|
||||||
|
test.pattern = 'test/**/test_*.rb'
|
||||||
|
test.verbose = true
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Code coverage detail"
|
||||||
|
task :simplecov do
|
||||||
|
ENV['COVERAGE'] = "true"
|
||||||
|
Rake::Task['test'].execute
|
||||||
|
end
|
||||||
|
|
||||||
|
task :default => :test
|
||||||
|
|
||||||
|
require 'rdoc/task'
|
||||||
|
Rake::RDocTask.new do |rdoc|
|
||||||
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
||||||
|
|
||||||
|
rdoc.rdoc_dir = 'rdoc'
|
||||||
|
rdoc.title = "progress-bar #{version}"
|
||||||
|
rdoc.rdoc_files.include('README*')
|
||||||
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
||||||
|
end
|
1
VERSION
Normal file
1
VERSION
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0.1.0
|
114
lib/progress-bar.rb
Normal file
114
lib/progress-bar.rb
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
require 'dbus'
|
||||||
|
|
||||||
|
class Progress
|
||||||
|
attr_reader :max, :i, :text, :error
|
||||||
|
attr_accessor :start
|
||||||
|
def initialize max = nil, text = nil
|
||||||
|
@start, @max, @i, @text, @error = Time.now, max || 100, 0, text || '', nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def i= x
|
||||||
|
@i = x.to_i
|
||||||
|
change_progress
|
||||||
|
end
|
||||||
|
|
||||||
|
def increment!( x = nil) self.i += (x || 1) end
|
||||||
|
alias to_i i
|
||||||
|
alias inc! increment!
|
||||||
|
def done_rel() 100.0*i/max end
|
||||||
|
def done_dur() (Time.now-@start).seconds end
|
||||||
|
|
||||||
|
def total_dur
|
||||||
|
done_dur * max / i
|
||||||
|
end
|
||||||
|
|
||||||
|
def text= x
|
||||||
|
@text = x
|
||||||
|
change_text
|
||||||
|
end
|
||||||
|
|
||||||
|
def error= x
|
||||||
|
@error = x
|
||||||
|
change_error
|
||||||
|
end
|
||||||
|
|
||||||
|
def change_progress() end
|
||||||
|
def change_text() end
|
||||||
|
def change_error() end
|
||||||
|
def finish() end
|
||||||
|
end
|
||||||
|
|
||||||
|
class ConsoleProgress < Progress
|
||||||
|
def initialize *a
|
||||||
|
super *a
|
||||||
|
change_text
|
||||||
|
end
|
||||||
|
|
||||||
|
def format_time t
|
||||||
|
if t.finite?
|
||||||
|
sprintf "%02d:%02d:%02d", t/1.hour, t/1.minute % 1.hour, t % 1.minute
|
||||||
|
else
|
||||||
|
"--:--:--"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def change_text
|
||||||
|
l = (100.0*i/max).to_i
|
||||||
|
dd, td = done_dur, total_dur
|
||||||
|
STDOUT.printf "\r\e[J%s / %s [%s>%s] %s", format_time(dd), format_time(td), '='*l, ' '*(100-l), text
|
||||||
|
end
|
||||||
|
alias change_progress change_text
|
||||||
|
|
||||||
|
def change_error
|
||||||
|
STDERR.printf "\r\e[J%s\n", error
|
||||||
|
change_text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class KDialogProgress < Progress
|
||||||
|
attr_reader :dialog_service_path, :dialog_object_path, :errors, :dialog_object
|
||||||
|
def initialize *a
|
||||||
|
super *a
|
||||||
|
@errors = []
|
||||||
|
args = %w[kdialog --progressbar] + [text, max.to_s]
|
||||||
|
@dialog_service_path, @dialog_object_path = IO.popen( args, 'r', &:readlines).join("\n").split ' '
|
||||||
|
@dialog_bus = DBus.session_bus
|
||||||
|
@dialog_service = @dialog_bus[@dialog_service_path]
|
||||||
|
@dialog_object = @dialog_service.object @dialog_object_path
|
||||||
|
@dialog_object.introspect
|
||||||
|
@dialog_object.showCancelButton true
|
||||||
|
change_progress
|
||||||
|
rescue DBus::Error
|
||||||
|
raise Interrupt if $!.name == 'org.freedesktop.DBus.Error.ServiceUnknown'
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.kdialog *a
|
||||||
|
windowid = ENV['WINDOWID']
|
||||||
|
windowid = (windowid.is_a?(String) && !windowid.empty?) ? ['--attach', windowid] : []
|
||||||
|
system 'kdialog', *windowid, *a
|
||||||
|
end
|
||||||
|
def kdialog(*a) self.class.kdialog *a end
|
||||||
|
|
||||||
|
def change_progress()
|
||||||
|
@dialog_object.Set '', 'value', i
|
||||||
|
raise Interrupt if @dialog_object.wasCancelled.first
|
||||||
|
rescue DBus::Error
|
||||||
|
raise Interrupt if $!.name == 'org.freedesktop.DBus.Error.ServiceUnknown'
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
|
||||||
|
def change_text()
|
||||||
|
@dialog_object.setLabelText text
|
||||||
|
raise Interrupt if @dialog_object.wasCancelled.first
|
||||||
|
rescue DBus::Error
|
||||||
|
raise Interrupt if $!.name == 'org.freedesktop.DBus.Error.ServiceUnknown'
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
|
||||||
|
def change_error() @errors.push error end
|
||||||
|
def finish()
|
||||||
|
@dialog_object.close rescue DBus::Error
|
||||||
|
kdialog '--detailederror', "Some errors occured:", errors.join( "<br/>\n") unless errors.empty?
|
||||||
|
end
|
||||||
|
end
|
34
test/helper.rb
Normal file
34
test/helper.rb
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
require 'simplecov'
|
||||||
|
|
||||||
|
module SimpleCov::Configuration
|
||||||
|
def clean_filters
|
||||||
|
@filters = []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
SimpleCov.configure do
|
||||||
|
clean_filters
|
||||||
|
load_adapter 'test_frameworks'
|
||||||
|
end
|
||||||
|
|
||||||
|
ENV["COVERAGE"] && SimpleCov.start do
|
||||||
|
add_filter "/.rvm/"
|
||||||
|
end
|
||||||
|
require 'rubygems'
|
||||||
|
require 'bundler'
|
||||||
|
begin
|
||||||
|
Bundler.setup(:default, :development)
|
||||||
|
rescue Bundler::BundlerError => e
|
||||||
|
$stderr.puts e.message
|
||||||
|
$stderr.puts "Run `bundle install` to install missing gems"
|
||||||
|
exit e.status_code
|
||||||
|
end
|
||||||
|
require 'test/unit'
|
||||||
|
require 'shoulda'
|
||||||
|
|
||||||
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||||
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
||||||
|
require 'progress-bar'
|
||||||
|
|
||||||
|
class Test::Unit::TestCase
|
||||||
|
end
|
7
test/test_progress-bar.rb
Normal file
7
test/test_progress-bar.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'helper'
|
||||||
|
|
||||||
|
class TestProgressBar < Test::Unit::TestCase
|
||||||
|
should "probably rename this file and start testing for real" do
|
||||||
|
flunk "hey buddy, you should probably rename this file and start testing for real"
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue