breaktime 0.1.3 → 0.1.4

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.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Breaktime
2
2
 
3
- Breaktime loves your eyes. That's why it gives them a screen break every so often - as often as you like. It hides in the background, waiting for it's moment to shine. When it's time for you to take a break it opens a dialog box with a timer counting down from 10, giving you the chance to cancel. But when the timer hits zero your screensaver will pop up, forcing you to go and make some tea/coffee/mojitos.
3
+ Breaktime loves your eyes. That's why it gives them a screen break every so often - as often as you like. It hides in the background, waiting for it's moment to shine. When it's time for you to take a break it opens a dialog box with a timer counting down from 10, giving you the chance to cancel or delay the break by 5 minutes. But when the timer hits zero your screensaver will pop up, forcing you to go and make some tea/coffee/mojitos.
4
4
 
5
5
  You can set how often it runs, which day(s) of the week it runs, and which system command you want to execute when it's time for a break. All of this can be configured with some lovely YAML.
6
6
 
@@ -25,24 +25,35 @@ SYNOPSIS
25
25
  breaktime (start|stop|dialog|now) [options]+
26
26
 
27
27
  DESCRIPTION
28
- Give your eyes scheduled screen breaks
28
+ Give your eyes scheduled screen breaks by starting up the screensaver at
29
+ regular intervals. By default it will give you a break every 60 minutes.
30
+ It is configurable via a YAML file which sits at $HOME/.breaktime.yml by
31
+ default.
32
+
33
+ USAGE
34
+ breaktime (start) - start breaktime, as a daemon by default
35
+ breaktime stop - stop a daemonized process
36
+ breaktime now - run the command to have a break instantly
37
+ breaktime dialog - show the countdown dialog box
29
38
 
30
39
  PARAMETERS
31
- --config, -c <s>: Configuration yaml file (default: /home/jon/.breaktime.yml)
32
- --level, -l <s>: Output level = (debug|info|warn|error|fatal) (default: info)
33
- --help, -h: Show this message
40
+ --config, -c <s>: Configuration yaml file (default: /home/jon/.breaktime.yml)
41
+ --pid-file, -p <s>: PID file path, used when daemonizing (default: /home/jon/breaktime.pid)
42
+ --log-file, -l <s>: Log file path (default: /home/jon/breaktime.log)
43
+ --level, -o <s>: Output level = (debug|info|warn|error|fatal) (default: info)
44
+ --help, -h: Show this message
34
45
  ```
35
46
 
36
47
  Simply running `breaktime` on its own should work - it will run every 60 minutes by default, and will try and work out the right screensaver command for your OS and window manager. If it can't work out your OS, then you can just set the **command** in the YAML file (read on).
37
48
 
49
+ You can set the log and pid file that will be used when daemonizing the process. This will allow you to see what's going on, and will allow only one instance of breaktime to run, respectively.
50
+
38
51
  If you want to do a bit more fine-tuning, create a YAML file at `$HOME/.breaktime.yml` that looks like this (everything's optional):
39
52
 
40
53
  ```yml
41
54
  command: xscreensaver-command -a
42
55
  interval: 40
43
56
  daemonize: true
44
- log_file: /path/to/log/file.log
45
- pid_file: /path/to/pid/file.pid
46
57
  days:
47
58
  - monday
48
59
  - tuesday
@@ -54,8 +65,6 @@ days:
54
65
  * **command** is the system command run every break time
55
66
  * **interval** is the time, in minutes, between each break
56
67
  * **daemonize** says whether the scheduling should run as a background process (daemon)
57
- * **log_file** specifies the file that output is written to (only if **daemonize** is true)
58
- * **pid_file** specifies the file that contains the PID (only if **daemonize** is true)
59
68
  * **days** allows you to specify which days of the week to run it
60
69
 
61
70
  If you want your YAML file to be elsewhere, then just pass it as the `--config` parameter to the breaktime command.
@@ -12,6 +12,7 @@ module Breaktime
12
12
  EX_LINUX_WM_UNKNOWN = 3 # Unknown window manager (linux)
13
13
  EX_SIGNAL = 128 # Process signal caught
14
14
  EX_INTERRUPT = 130 # Control-C caught
15
+ EX_BREAK_DELAYED = 253 # Delay from the countdown GUI
15
16
  EX_BREAK_CANCELLED = 254 # Cancel from the countdown GUI
16
17
  EX_CLI = 255 # CLI option errors
17
18
 
@@ -7,7 +7,8 @@ class Breaktime::CLI
7
7
  SUB_COMMANDS = %w(start stop dialog now)
8
8
 
9
9
  # Default location of YAML config file.
10
- DEFAULT_CONFIG = ENV['HOME'] + File::SEPARATOR + ".breaktime.yml"
10
+ HOME = ENV['HOME'] + File::SEPARATOR
11
+ DEFAULT_CONFIG = HOME + '.breaktime.yml'
11
12
 
12
13
  def initialize
13
14
  @options = parse_cli_options
@@ -26,8 +27,8 @@ SYNOPSIS
26
27
  breaktime (#{SUB_COMMANDS.join("|")}) [options]+
27
28
 
28
29
  DESCRIPTION
29
- Give your eyes scheduled screen breaks by starting up the screensaver at
30
- regular intervals. By default it will give you a break every 60 minutes.
30
+ Give your eyes scheduled screen breaks by starting up the screensaver at
31
+ regular intervals. By default it will give you a break every 60 minutes.
31
32
  It is configurable via a YAML file which sits at $HOME/.breaktime.yml by
32
33
  default.
33
34
 
@@ -40,14 +41,24 @@ USAGE
40
41
  PARAMETERS
41
42
  BAN
42
43
 
43
- opt :config,
44
- "Configuration yaml file",
45
- :short => '-c',
44
+ opt :config,
45
+ "Configuration yaml file",
46
+ :short => '-c',
46
47
  :default => DEFAULT_CONFIG
47
48
 
48
- opt :level,
49
- "Output level = (debug|info|warn|error|fatal)",
50
- :short => '-l',
49
+ opt :pid_file,
50
+ "PID file path, used when daemonizing",
51
+ :short => '-p',
52
+ :default => HOME + "breaktime.pid"
53
+
54
+ opt :log_file,
55
+ "Log file path",
56
+ :short => '-l',
57
+ :default => HOME + "breaktime.log"
58
+
59
+ opt :level,
60
+ "Output level = (debug|info|warn|error|fatal)",
61
+ :short => '-o',
51
62
  :default => 'info'
52
63
 
53
64
  end
@@ -13,11 +13,6 @@ module Breaktime
13
13
  background white
14
14
  flow :margin => 4 do
15
15
  @sent = para str % seconds
16
-
17
- button "Cancel" do
18
- exit Breaktime::EX_BREAK_CANCELLED
19
- end
20
-
21
16
  every 1 do |i|
22
17
  if i >= seconds
23
18
  exit Breaktime::EX_OK
@@ -26,5 +21,15 @@ module Breaktime
26
21
  end
27
22
  end
28
23
  end
24
+ flow do
25
+ button "Cancel" do
26
+ exit Breaktime::EX_BREAK_CANCELLED
27
+ end
28
+
29
+ button "Gimme 5", :align => :right do
30
+ exit Breaktime::EX_BREAK_DELAYED
31
+ end
32
+ end
33
+
29
34
  end
30
35
  end
@@ -12,8 +12,6 @@ class Breaktime::Main
12
12
 
13
13
  # Default options that can be overridden in the YAML file.
14
14
  DEFAULT_OPTIONS = {'interval' => 60,
15
- 'pid_path' => ENV['HOME'] + File::SEPARATOR + "breaktime.pid",
16
- 'log_path' => ENV['HOME'] + File::SEPARATOR + "breaktime.log",
17
15
  'daemonize' => true,
18
16
  'days' => ['monday',
19
17
  'tuesday',
@@ -31,6 +29,9 @@ class Breaktime::Main
31
29
  set_log_level @cli.options[:level]
32
30
 
33
31
  parse_yaml_file
32
+
33
+ @options['log_path'] = @cli.options[:log_file]
34
+ @options['pid_path'] = @cli.options[:pid_file]
34
35
  end
35
36
 
36
37
  # Exit with a trollop message.
@@ -102,8 +103,8 @@ class Breaktime::Main
102
103
  #
103
104
  # Uses Dante for daemonizing.
104
105
  def startd
105
- dante_opts = {:daemonize => @options['daemonize'],
106
- :pid_path => @options['pid_path'],
106
+ dante_opts = {:daemonize => @options['daemonize'],
107
+ :pid_path => @options['pid_path'],
107
108
  :log_path => @options['log_path']}
108
109
 
109
110
  if dante_opts[:daemonize]
@@ -133,7 +134,7 @@ class Breaktime::Main
133
134
  # Create a new Main object and run the mode given as a CLI parameter.
134
135
  #
135
136
  # Also rescue exceptions and display helpful messages.
136
- #
137
+ #
137
138
  # TODO: tidy this up
138
139
  def start
139
140
  main = self.new
@@ -57,10 +57,14 @@ class Breaktime::Schedule
57
57
  else
58
58
  @log.error { "Failed to run breaktime with the `now` mode" }
59
59
  end
60
+ when Breaktime::EX_BREAK_DELAYED
61
+ @log.info { "Delaying break by 5 minutes" }
62
+ sleep(300)
63
+ run_dialog
60
64
  when Breaktime::EX_BREAK_CANCELLED
61
65
  @log.warn { "Cancelled screen break" }
62
66
  else
63
- @log.error { "Failed to run breaktime with the `dialog` mode" }
67
+ @log.error { "Failed to run breaktime with the `dialog` mode: return code #{retcode_d}" }
64
68
  end
65
69
  end
66
70
 
@@ -68,16 +72,12 @@ class Breaktime::Schedule
68
72
  #
69
73
  # The exit code is returned.
70
74
  def exec_self(mode, args = {})
71
- arg_str = ''
72
- @cli_options.merge(args).each do |n,v|
73
- if v && !n.to_s.include?("_given")
74
- arg_str += " --#{n} #{v}"
75
- end
76
- end
75
+ opts = @cli_options.merge(args)
76
+ arg_str = "--config #{opts[:config]} --level #{opts[:level]}"
77
77
  exec_str = "#{$PROGRAM_NAME} #{mode} #{arg_str}"
78
78
  @log.debug { "Executing `#{exec_str}`" }
79
79
  system exec_str
80
- $?
80
+ $?.exitstatus
81
81
  end
82
82
 
83
83
 
@@ -1,3 +1,3 @@
1
1
  module Breaktime
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breaktime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: green_shoes