gibil 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. data/bin/gibil +6 -4
  2. data/lib/gibil.rb +36 -2
  3. metadata +13 -29
data/bin/gibil CHANGED
@@ -4,10 +4,12 @@
4
4
  require 'gibil'
5
5
 
6
6
  args = ARGV.dup
7
- if args[0] == 'schedule'
8
- `whenever --update-crontab`
9
- puts 'Chrontab updated:'
10
- `crontab -l`
7
+
8
+ case args[0]
9
+ when 'schedule'
10
+ Gibil::Cronify.schedule
11
+ when 'job'
12
+ Gibil::Notification.notify if Gibil::Sensor.temperature > 60
11
13
  else
12
14
  Gibil::Notification.notify
13
15
  end
@@ -25,10 +25,44 @@ module Gibil
25
25
  append: true
26
26
  )
27
27
 
28
- n.urgency = :normal if temp.between?(60, 79)
29
- n.urgency = :critical if temp > 79
28
+ n.urgency = (temp > 80) ? :critical : :normal
30
29
 
31
30
  n.show!
32
31
  end
33
32
  end
33
+
34
+ # Module to write the cronjob
35
+ module Cronify
36
+ # Tries to write the crontab and exits with the appropiate code
37
+ def self.schedule
38
+ cron = <<-END.gsub(/^ {8}/, '')
39
+ # Gibil temperature notification
40
+ 0,10,20,30,40,50 * * * * /bin/bash -l -c 'gibil job'
41
+ # End Gibil temperature notification
42
+ END
43
+
44
+ require 'tempfile'
45
+ file = Tempfile.new('temp_cronfile')
46
+ file.write(cron)
47
+ file.close
48
+
49
+ run(file)
50
+ end
51
+
52
+ def self.run(file)
53
+ if system("crontab #{file.path}")
54
+ puts 'INFO: Wrote crontab file'
55
+ file.unlink
56
+ exit(0)
57
+ else
58
+ warn 'ERROR: Failed to write crontab'
59
+ file.unlink
60
+ exit(1)
61
+ end
62
+ end
63
+
64
+ def self.temp_path(cron)
65
+ file.path
66
+ end
67
+ end
34
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gibil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,65 +16,49 @@ dependencies:
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: '0.8'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: whenever
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
29
+ version: '0.8'
46
30
  - !ruby/object:Gem::Dependency
47
31
  name: minitest
48
32
  requirement: !ruby/object:Gem::Requirement
49
33
  none: false
50
34
  requirements:
51
- - - ! '>='
35
+ - - ~>
52
36
  - !ruby/object:Gem::Version
53
- version: '0'
37
+ version: '5.3'
54
38
  type: :development
55
39
  prerelease: false
56
40
  version_requirements: !ruby/object:Gem::Requirement
57
41
  none: false
58
42
  requirements:
59
- - - ! '>='
43
+ - - ~>
60
44
  - !ruby/object:Gem::Version
61
- version: '0'
45
+ version: '5.3'
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: rubocop
64
48
  requirement: !ruby/object:Gem::Requirement
65
49
  none: false
66
50
  requirements:
67
- - - ! '>='
51
+ - - ~>
68
52
  - !ruby/object:Gem::Version
69
- version: '0'
53
+ version: '0.19'
70
54
  type: :development
71
55
  prerelease: false
72
56
  version_requirements: !ruby/object:Gem::Requirement
73
57
  none: false
74
58
  requirements:
75
- - - ! '>='
59
+ - - ~>
76
60
  - !ruby/object:Gem::Version
77
- version: '0'
61
+ version: '0.19'
78
62
  description: Show a notification of your computer's temperature. It can be programmed
79
63
  as a cronjob, so you can be notified when the temperature is high.
80
64
  email: fernando@picandocodigo.net