windows-shutdown-timer 1.0.2 → 1.0.3

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
  SHA1:
3
- metadata.gz: 52442da748edaeceb1a97d10acbe2e2ae094b8fd
4
- data.tar.gz: f5845cb3bb577784dc4da751714c604873b9c186
3
+ metadata.gz: f6bb12218d76cf41b3a10d5d1e29b7a872850976
4
+ data.tar.gz: 805aa77ee11cd70235c99dd9e1450bb1da726fe3
5
5
  SHA512:
6
- metadata.gz: 89edfbd6601a26ff1f51a22f5e6731e6539c03c7534aed609f7e9f0ddb91cdb5c21e9e46b7291edd21ab108d3dff84ddf07c5d9165d87a2187ca7aa5b34563ea
7
- data.tar.gz: db038d8b63cf474b04be0c4de6dc96d628b775ab87e68047855416268489d69b1ec6547d41529508c9f4f65f77e1ca2c18d5bc3ff412a42c8f76b31351e56835
6
+ metadata.gz: a767438c139758e832e1d251f984dc6f208da89e5b657cc1933c90be69644ccf6d7901f94eb293cdd7efd9ccbc52b48edd4dbc0c950866fc925bce761d56f4dc
7
+ data.tar.gz: 855cc1a5a51388e437befe9c36a1cd0a8d7e13f2f7f2e62f4d72fb1b6f051e76dacadefaaa5ec2ca24acdba98450f0d7babb543df684f604d6c6044e4b1dbf94
@@ -1,6 +1,6 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'windows-shutdown-timer'
4
-
5
- starter = WindowsShutdownTimer::ShutdownStarter.new(ARGV)
6
- starter.start_timer
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'windows-shutdown-timer'
4
+
5
+ starter = WindowsShutdownTimer::ShutdownStarter.new(ARGV)
6
+ starter.start_timer
@@ -1,88 +1,91 @@
1
- require 'optparse'
2
- require 'net/http'
3
- require 'fileutils'
4
- require 'zip'
5
-
6
- module WindowsShutdownTimer
7
- # Shutdown!
8
- class ShutdownStarter
9
-
10
- INSOMNIA = 'Insomnia.exe'
11
- PATH_TO_TEMP = Dir.tmpdir + '/windows-shutdown-timer'
12
- PATH_TO_INSOMNIA = PATH_TO_TEMP + '/' + INSOMNIA
13
- PATH = 'insomnia/64-bit'
14
- COMMAND_SHUTDOWN = 'shutdown /s /t '
15
- COMMAND_CANCEL_SHUTDOWN = 'shutdown /a'
16
- COMMAND_INSOMNIA = "start #{PATH_TO_INSOMNIA}"
17
-
18
- def initialize(arguments)
19
-
20
- # Get the first arg as the time
21
- @time = %w(-h --help -c).include?(arguments.first) ? nil : arguments.shift
22
-
23
- create_options_parser(arguments)
24
- end
25
-
26
- def create_options_parser(args)
27
- args.options do |opts|
28
- opts.banner = 'Usage: windows-shutdown-timer MINUTES_UNTIL_SHUTDOWN [OPTIONS]'
29
- opts.separator ''
30
- opts.separator 'Options'
31
- opts.on('-c', '--cancel', 'Cancel a pending shutdown') do
32
- @time = 0
33
- end
34
- opts.on('-h', '--help', 'Displays help') do
35
- puts opts.help
36
- exit
37
- end
38
- opts.parse!
39
- end
40
- end
41
-
42
- def start_timer
43
- unless File.file?(PATH_TO_INSOMNIA)
44
- puts 'Downloading Insomnia.exe'
45
- download('dlaa.me', '/Samples/Insomnia/Insomnia.zip', 'Insomnia.zip')
46
- unzip('Insomnia.zip', 'insomnia')
47
- FileUtils.mkdir(PATH_TO_TEMP)
48
- FileUtils.mv('insomnia/64-bit/Insomnia.exe', PATH_TO_INSOMNIA)
49
- # Cleanup
50
- FileUtils.rm_rf('insomnia')
51
- FileUtils.rm('Insomnia.zip')
52
- end
53
- if @time == nil
54
- puts 'Please enter the number of minutes until shutdown (0 to cancel):'
55
- @time = gets
56
- end
57
- if @time.to_i == 0
58
- `#{COMMAND_CANCEL_SHUTDOWN}`
59
- elsif @time.to_i == -1
60
- `#{COMMAND_INSOMNIA}`
61
- else
62
- time_in_seconds = @time.to_i * 60
63
- `#{COMMAND_SHUTDOWN} #{time_in_seconds}`
64
- `#{COMMAND_INSOMNIA}`
65
- end
66
- end
67
-
68
- def download(base_url, path, file_name)
69
- Net::HTTP.start(base_url) do |http|
70
- resp = http.get(path)
71
- open(file_name, 'wb') do |file|
72
- file.write(resp.body)
73
- end
74
- end
75
- end
76
-
77
- def unzip(file, destination)
78
- Zip::File.open(file) do |zip_file|
79
- zip_file.each do |f|
80
- f_path = File.join(destination, f.name)
81
- FileUtils.mkdir_p(File.dirname(f_path))
82
- zip_file.extract(f, f_path) unless File.exist?(f_path)
83
- end
84
- end
85
- end
86
-
87
- end
88
- end
1
+ require 'optparse'
2
+ require 'net/http'
3
+ require 'fileutils'
4
+ require 'zip'
5
+
6
+ module WindowsShutdownTimer
7
+ # Shutdown!
8
+ class ShutdownStarter
9
+
10
+ INSOMNIA = 'Insomnia.exe'
11
+ PATH_TO_TEMP = Dir.tmpdir + '/windows-shutdown-timer'
12
+ PATH_TO_INSOMNIA = PATH_TO_TEMP + '/' + INSOMNIA
13
+ PATH = 'insomnia/64-bit'
14
+ COMMAND_SHUTDOWN = 'shutdown /s /t '
15
+ COMMAND_CANCEL_SHUTDOWN = 'shutdown /a'
16
+ COMMAND_INSOMNIA = "start #{PATH_TO_INSOMNIA}"
17
+
18
+ def initialize(arguments)
19
+
20
+ # Get the first arg as the time
21
+ @time = %w(-h --help -c).include?(arguments.first) ? nil : arguments.shift
22
+
23
+ create_options_parser(arguments)
24
+ end
25
+
26
+ def create_options_parser(args)
27
+ args.options do |opts|
28
+ opts.banner = 'Usage: windows-shutdown-timer MINUTES_UNTIL_SHUTDOWN [OPTIONS]'
29
+ opts.separator ''
30
+ opts.separator 'Options'
31
+ opts.on('-c', '--cancel', 'Cancel a pending shutdown') do
32
+ @time = 0
33
+ end
34
+ opts.on('-i', '--insomnia', 'Just runs Insomnia') do
35
+ @time = -1
36
+ end
37
+ opts.on('-h', '--help', 'Displays help') do
38
+ puts opts.help
39
+ exit
40
+ end
41
+ opts.parse!
42
+ end
43
+ end
44
+
45
+ def start_timer
46
+ unless File.file?(PATH_TO_INSOMNIA)
47
+ puts 'Downloading Insomnia.exe'
48
+ download('dlaa.me', '/Samples/Insomnia/Insomnia.zip', 'Insomnia.zip')
49
+ unzip('Insomnia.zip', 'insomnia')
50
+ FileUtils.mkdir(PATH_TO_TEMP)
51
+ FileUtils.mv('insomnia/64-bit/Insomnia.exe', PATH_TO_INSOMNIA)
52
+ # Cleanup
53
+ FileUtils.rm_rf('insomnia')
54
+ FileUtils.rm('Insomnia.zip')
55
+ end
56
+ if @time == nil
57
+ puts 'Please enter the number of minutes until shutdown (0 to cancel):'
58
+ @time = gets
59
+ end
60
+ if @time.to_i == 0
61
+ `#{COMMAND_CANCEL_SHUTDOWN}`
62
+ elsif @time.to_i == -1
63
+ `#{COMMAND_INSOMNIA}`
64
+ else
65
+ time_in_seconds = @time.to_i * 60
66
+ `#{COMMAND_SHUTDOWN} #{time_in_seconds}`
67
+ `#{COMMAND_INSOMNIA}`
68
+ end
69
+ end
70
+
71
+ def download(base_url, path, file_name)
72
+ Net::HTTP.start(base_url) do |http|
73
+ resp = http.get(path)
74
+ open(file_name, 'wb') do |file|
75
+ file.write(resp.body)
76
+ end
77
+ end
78
+ end
79
+
80
+ def unzip(file, destination)
81
+ Zip::File.open(file) do |zip_file|
82
+ zip_file.each do |f|
83
+ f_path = File.join(destination, f.name)
84
+ FileUtils.mkdir_p(File.dirname(f_path))
85
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
86
+ end
87
+ end
88
+ end
89
+
90
+ end
91
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: windows-shutdown-timer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Carlson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-20 00:00:00.000000000 Z
11
+ date: 2018-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -30,7 +30,7 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.0.0
33
- description:
33
+ description: Shut down Windows machine after keeping it awake
34
34
  email:
35
35
  - jawnnypoo@gmail.com
36
36
  executables:
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  requirements: []
63
63
  rubyforge_project:
64
- rubygems_version: 2.6.11
64
+ rubygems_version: 2.4.5.2
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: Starts a timer, keeping the Windows machine awake and shutting it down when