poweroff_in 0.0.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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in poweroff_in.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alexandre Croteau-Pothier
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # PoweroffIn
2
+
3
+ This is a Simple gem to poweroff a linux system after a certain amount of time.
4
+
5
+ ### Why?
6
+
7
+ I like to listen to music before going to sleep.
8
+ The shutdown command doesn't completly 'shutdown' a laptop and the poweroff command doesn't take a TIME argument.
9
+
10
+ ## Installation
11
+
12
+ Install it yourself as:
13
+
14
+ $ gem install poweroff_in
15
+
16
+ ## Usage
17
+
18
+ You need to execute the command with sudo since poweroff requires sudo privilege.
19
+
20
+ You need to specify an amount of time and the 'type of time' minutes or hour. Minutes is the default.
21
+
22
+
23
+ ### Example usage:
24
+
25
+ $ sudo poweroff_in 10 minutes
26
+
27
+
28
+ $ sudo poweroff_in 10
29
+
30
+
31
+ $ sudo poweroff_in 1 hour
32
+
33
+
34
+ ## Contributing
35
+
36
+ Feel free to contribute.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'poweroff_in'
4
+
5
+ app = PoweroffIn.new ARGV
6
+ app.run
@@ -0,0 +1,65 @@
1
+ require "poweroff_in/version"
2
+ require "ruby-progressbar"
3
+
4
+ class PoweroffIn
5
+ MINUTE = 60
6
+ HOUR = 3600
7
+
8
+ def initialize arguments
9
+ validate arguments
10
+ @amount = arguments[0].to_i
11
+ @time = translate_word_to_time arguments[1]
12
+ @progressbar = ProgressBar.create(:format => '%a %B %p%% %t')
13
+ end
14
+
15
+ def run
16
+ user_is_sudo?
17
+ show_message
18
+ poweroff_after_delay
19
+ end
20
+
21
+ private
22
+
23
+ def validate arguments
24
+ exit_with_usage_info if arguments.empty? or arguments[0] == "-h"
25
+ end
26
+
27
+ def user_is_sudo?
28
+ unless ENV["USER"] == "root"
29
+ p "Please execute as sudo"
30
+ exit_with_usage_info
31
+ end
32
+ end
33
+
34
+ def exit_with_usage_info
35
+ p "Usage: sudo poweroff_in [amount] [minutes(default) or hours]"
36
+ Kernel::exit
37
+ end
38
+
39
+ def translate_word_to_time word
40
+ if word and word.match(/hour/i)
41
+ HOUR
42
+ else
43
+ MINUTE
44
+ end
45
+ end
46
+
47
+ def show_message
48
+ time_in_word = @time == MINUTE ? "minutes" : "hours"
49
+ p "System will poweroff in #{@amount} #{time_in_word}"
50
+ end
51
+
52
+ def poweroff_after_delay
53
+ increment_progressbar_every (@amount*@time).to_f/100
54
+ IO.popen 'sudo poweroff now'
55
+ end
56
+
57
+ def increment_progressbar_every one_percent
58
+ counter = 0
59
+ begin
60
+ @progressbar.increment
61
+ counter+=1
62
+ sleep one_percent
63
+ end while counter < 100
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ class PoweroffIn
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/poweroff_in/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alexandre Croteau-Pothier"]
6
+ gem.email = ["alex@alexcp.com"]
7
+ gem.description = %q{Poweroff after a delay.}
8
+ gem.summary = %q{Poweroff a linux system after a certain amount of time.}
9
+ gem.homepage = "https://github.com/alexcp/poweroff_in"
10
+
11
+ gem.add_dependency 'ruby-progressbar'
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables << 'poweroff_in'
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "poweroff_in"
17
+ gem.require_paths = ["lib","bin"]
18
+ gem.version = PoweroffIn::VERSION
19
+
20
+ gem.requirements << 'A linux System with a sudoer account.'
21
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poweroff_in
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexandre Croteau-Pothier
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ruby-progressbar
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Poweroff after a delay.
31
+ email:
32
+ - alex@alexcp.com
33
+ executables:
34
+ - poweroff_in
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - bin/poweroff_in
44
+ - lib/poweroff_in.rb
45
+ - lib/poweroff_in/version.rb
46
+ - poweroff_in.gemspec
47
+ homepage: https://github.com/alexcp/poweroff_in
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ - bin
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements:
67
+ - A linux System with a sudoer account.
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Poweroff a linux system after a certain amount of time.
73
+ test_files: []