sifttter-redux 0.4.6 → 0.4.7

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: 6089e8d0f4bb6e878a213306b36f3b1794ac7bbf
4
- data.tar.gz: 8d429c68df6b8cb9d5cdb825baad4d96e5ff64c1
3
+ metadata.gz: 3f5212c6ef9ead91e8f71e3e2292f2e9aca80f29
4
+ data.tar.gz: a49f77302bd648f7fcbd742c0d8be1687b373fae
5
5
  SHA512:
6
- metadata.gz: 0078c8d8e1253ba99f334d6d87d13bd1718db76f578d3ee2e4ac7acd3ff38c59c915d0ba98393b14e15772207a7ed50e0d1fc4c0ecb6dd8719412a1c5a9c8230
7
- data.tar.gz: c4f4d97e124a3990a2e3d6fb541899d5f3a2b095fda56783699f13b5401e2c3c3fcf7212f57ecfd41a85a7b67b821fa88033675c21e0e0ba7d78feaf929f56c0
6
+ metadata.gz: 51a7a13606982a278551f2d2094ab16c459396987160b0a5fdd39697f334364842b044da24797c7a41c86fa345b8ca1918fe230f751b904d8e8f64ad5cf07d8f
7
+ data.tar.gz: 3e5e4007131430433b69b902593f837f396f49c3c1fcd4f6f728145f8969ec4fe5aaff676089676463409ae2431d8d1696289707d72d2efd5675e08790cfdf25
data/HISTORY.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.4.7 (2014-03-14)
2
+
3
+ * Reworked logging to not require Methadone
4
+ * Logging more verbose and configurable in ~/.sifttter_redux
5
+ * Dropbox Uploader updates
6
+ * Added support for path completion when prompting user to enter a filepath
7
+ * Cleaned up error handling to be displayed to user at single point
8
+
1
9
  # 0.4.6 (2014-03-13)
2
10
 
3
11
  * Added new error messaaging if Sifttter remote path is invalid
data/README.md CHANGED
@@ -37,7 +37,7 @@ SYNOPSIS
37
37
  srd [global options] command [command options] [arguments...]
38
38
 
39
39
  VERSION
40
- 0.4.6
40
+ 0.4.7
41
41
 
42
42
  GLOBAL OPTIONS
43
43
  --help - Show this message
@@ -81,10 +81,10 @@ Initialization will perform the following steps:
81
81
 
82
82
  1. Download [Dropbox Uploader](https://github.com/andreafabrizi/Dropbox-Uploader "Dropbox-Uploder") to a location of your choice.
83
83
  2. Automatically configure Dropbox Uploader.
84
- 3. Collect some user preferences:
85
- * The location on your filesystem where Sifttter files will be temporarily stored
84
+ 3. Collect some user paths:
85
+ * The location on your filesystem where Sifttter files will be temporarily stored (**tab completion works here!**)
86
86
  * The location of your Sifttter files in Dropbox
87
- * The location on your filesystem where Day One files will be temporarily stored
87
+ * The location on your filesystem where Day One files will be temporarily stored (**tab completion works here!**)
88
88
  * The location of your Day One files in Dropbox
89
89
 
90
90
  ## Pathing
data/bin/srd CHANGED
@@ -33,12 +33,11 @@
33
33
  # OTHER DEALINGS IN THE SOFTWARE.
34
34
  #--------------------------------------------------------------------
35
35
  require 'gli'
36
- require 'methadone'
36
+ require 'logger'
37
37
  require 'sifttter_redux'
38
38
  require 'securerandom'
39
39
 
40
40
  include GLI::App
41
- include Methadone::CLILogging
42
41
  include SifttterRedux
43
42
 
44
43
  # ======================================================
@@ -63,9 +62,9 @@ switch([:verbose], desc: 'Turns on verbose output')
63
62
  pre do |global, command, options, args|
64
63
  # Load SifttterRedux configuration module.
65
64
  Configuration::load(SRD_CONFIG_FILEPATH)
66
-
67
- # Load Methadone CLILogging module.
68
- Methadone::CLILogging::change_logger(Methadone::CLILogger.new(SRD_LOG_FILEPATH, SRD_LOG_FILEPATH))
65
+
66
+ # Set up logging.
67
+ CLIMessage::activate_logging
69
68
 
70
69
  if File.exists?(SRD_CONFIG_FILEPATH)
71
70
  current_version = Gem::Version.new(Configuration['sifttter_redux']['version'])
@@ -77,18 +76,15 @@ pre do |global, command, options, args|
77
76
  CLIMessage::info("Don't worry; when prompted, your current values for")
78
77
  CLIMessage::info("existing config options will be presented (so it'll")
79
78
  CLIMessage::info('be easier to fly through the upgrade).')
80
- CLIMessage::prompt('Press enter to continue')
79
+ CLIMessage::prompt('Press enter to continue: ')
81
80
  SifttterRedux::init(true)
82
- exit!
81
+ exit!(0)
83
82
  end
84
-
85
- # Load Dropbox Uploader module.
86
- DBU.load(Configuration['db_uploader']['exe_filepath'])
87
83
  else
88
84
  # Force the user to init if they try to run any command other than `init` first.
89
85
  CLIMessage::info('Initializing Sifttter Redux first...') unless command.name_for_help[0] == 'init'
90
86
  SifttterRedux::init
91
- exit!
87
+ exit!(0)
92
88
  end
93
89
 
94
90
  true
@@ -117,36 +113,49 @@ command :exec do |c|
117
113
  c.action do |global_options, options, args|
118
114
  SifttterRedux.verbose = global_options[:verbose] || options[:verbose]
119
115
 
120
- dates = SifttterRedux::get_dates_from_options(options)
121
- unless dates.nil?
122
- first_date = dates.first
123
- second_date = dates.reverse_each.first
124
-
125
- date_string = first_date.strftime('%B %d, %Y')
126
- date_string << " to #{ second_date.strftime('%B %d, %Y') }" if first_date != second_date
127
- CLIMessage::info("Creating #{ first_date == second_date ? 'entry' : 'entries' }: #{ date_string }")
128
-
129
- # Download Sifttter files from Dropbox.
130
- DBU.local_target = Configuration['sifttter_redux']['sifttter_local_filepath']
131
- DBU.remote_target = Configuration['sifttter_redux']['sifttter_remote_filepath']
132
- DBU.message = 'Downloading Sifttter files...'
133
- DBU.download
134
-
135
- # Process a new Sifttter entry for each date.
136
- dates.each do |date|
137
- Sifttter::run(date)
116
+ begin
117
+ dates = SifttterRedux::get_dates_from_options(options)
118
+ unless dates.nil?
119
+ first_date = dates.first
120
+ second_date = dates.reverse_each.first
121
+
122
+ date_string = first_date.strftime('%B %d, %Y')
123
+ date_string << " to #{ second_date.strftime('%B %d, %Y') }" if first_date != second_date
124
+ CLIMessage::info("Creating #{ first_date == second_date ? 'entry' : 'entries' }: #{ date_string }")
125
+
126
+ # Download Sifttter files from Dropbox.
127
+ dbu = DropboxUploader.new(Configuration['db_uploader']['exe_filepath'])
128
+ dbu.verbose = SifttterRedux.verbose
129
+ dbu.local_target = Configuration['sifttter_redux']['sifttter_local_filepath']
130
+ dbu.remote_target = Configuration['sifttter_redux']['sifttter_remote_filepath']
131
+ dbu.message = 'Downloading Sifttter files...'
132
+
133
+ CLIMessage::info_block(dbu.message || dbu::DEFAULT_MESSAGE, 'Done.', SifttterRedux.verbose) do
134
+ dbu.download
135
+ end
136
+
137
+ # Process a new Sifttter entry for each date.
138
+ dates.each do |date|
139
+ Sifttter::run(date)
140
+ end
141
+
142
+ # Upload any Day One entries to Dropbox (if there are any).
143
+ unless Dir[Configuration['sifttter_redux']['dayone_local_filepath'] + '/*'].empty?
144
+ dbu.local_target = "#{ Configuration['sifttter_redux']['dayone_local_filepath'] }/*"
145
+ dbu.remote_target = Configuration['sifttter_redux']['dayone_remote_filepath']
146
+ dbu.message = 'Uploading Day One entries to Dropbox...'
147
+
148
+ CLIMessage::info_block(dbu.message || dbu::DEFAULT_MESSAGE, 'Done.', SifttterRedux.verbose) do
149
+ dbu.upload
150
+ end
151
+ end
152
+
153
+ # Remove any downloaded local files that we no longer need.
154
+ SifttterRedux::cleanup_temp_files
138
155
  end
139
-
140
- # Upload any Day One entries to Dropbox (if there are any).
141
- unless Dir[Configuration['sifttter_redux']['dayone_local_filepath'] + '/*'].empty?
142
- DBU.local_target = "#{ Configuration['sifttter_redux']['dayone_local_filepath'] }/*"
143
- DBU.remote_target = Configuration['sifttter_redux']['dayone_remote_filepath']
144
- DBU.message = 'Uploading Day One entries to Dropbox...'
145
- DBU.upload
146
- end
147
-
148
- # Remove any downloaded local files that we no longer need.
149
- SifttterRedux::cleanup_temp_files
156
+ rescue StandardError => e
157
+ CLIMessage::error(e.to_s)
158
+ exit!(1)
150
159
  end
151
160
  end
152
161
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'string_extensions.rb')
1
+ require 'readline'
2
2
 
3
3
  module SifttterRedux
4
4
  # ======================================================
@@ -9,6 +9,37 @@ module SifttterRedux
9
9
  # ====================================================
10
10
  # Methods
11
11
  # ====================================================
12
+ # ----------------------------------------------------
13
+ # activate_logging method
14
+ #
15
+ # Creates a simple logger to use
16
+ # @return Void
17
+ # ----------------------------------------------------
18
+ def self.activate_logging
19
+ @@logger = Logger.new(File.join(ENV['HOME'], '.sifttter_redux_log'))
20
+ end
21
+
22
+ # ----------------------------------------------------
23
+ # deactivate_logging method
24
+ #
25
+ # Stops logging to file.
26
+ # @return Void
27
+ # ----------------------------------------------------
28
+ def self.deactivate_logging
29
+ @@logger = nil
30
+ end
31
+
32
+ # ----------------------------------------------------
33
+ # debug method
34
+ #
35
+ # Logs a debug message to the logfile.
36
+ # @param m The message to log
37
+ # @return Void
38
+ # ----------------------------------------------------
39
+ def self.debug(m)
40
+ @@logger.debug(m.blue) unless @@logger.nil?
41
+ end
42
+
12
43
  # ----------------------------------------------------
13
44
  # error method
14
45
  #
@@ -16,9 +47,9 @@ module SifttterRedux
16
47
  # @param m The message to output
17
48
  # @return Void
18
49
  # ----------------------------------------------------
19
- def self.error(m, log = true)
20
- Methadone::CLILogging.error(m) if log
21
- puts "---> ERROR: #{ m }".red
50
+ def self.error(m)
51
+ puts "# #{ m }".red
52
+ @@logger.error(m.red) unless @@logger.nil?
22
53
  end
23
54
 
24
55
  # ----------------------------------------------------
@@ -28,9 +59,9 @@ module SifttterRedux
28
59
  # @param m The message to output
29
60
  # @return Void
30
61
  # ----------------------------------------------------
31
- def self.info(m, log = true)
32
- Methadone::CLILogging.info(m) if log
33
- puts "---> INFO: #{ m }".blue
62
+ def self.info(m)
63
+ puts "# #{ m }".blue
64
+ @@logger.debug(m.blue) unless @@logger.nil?
34
65
  end
35
66
 
36
67
  # ----------------------------------------------------
@@ -42,25 +73,23 @@ module SifttterRedux
42
73
  # @param multiline Whether the message should be multiline
43
74
  # @return Void
44
75
  # ----------------------------------------------------
45
- def self.info_block(m1, m2 = 'Done.', multiline = false, log = true)
76
+ def self.info_block(m1, m2 = 'Done.', multiline = false)
46
77
  if block_given?
47
78
  if multiline
48
- info(m1, log)
79
+ info(m1)
49
80
  else
50
- print "---> INFO: #{ m1 }".blue
81
+ print "# #{ m1 }".blue
51
82
  end
52
83
 
53
84
  yield
54
85
 
55
86
  if multiline
56
- info(m2, log)
87
+ info(m2)
57
88
  else
58
89
  puts m2.blue
59
90
  end
60
91
  else
61
- error = 'Did not specify a valid block'
62
- Methadone::CLILogging.error(error) if log
63
- fail ArgumentError, error
92
+ fail ArgumentError, 'Did not specify a valid block'
64
93
  end
65
94
  end
66
95
 
@@ -73,29 +102,61 @@ module SifttterRedux
73
102
  # @param default The default option
74
103
  # @return String
75
104
  # ----------------------------------------------------
76
- def self.prompt(prompt, default = nil, log = true)
77
- print "#{ prompt } #{ default.nil? ? '' : "[default: #{ default }]:" } ".blue
105
+ def self.prompt(prompt, default = nil)
106
+ print "# #{ prompt } #{ default.nil? ? '' : "[default: #{ default }]:" } ".green
78
107
  choice = $stdin.gets.chomp
79
108
  if choice.empty?
80
109
  r = default
81
110
  else
82
111
  r = choice
83
112
  end
113
+ @@logger.debug("Answer to \"#{ prompt }\": #{ r }") unless @@logger.nil?
114
+ r
115
+ end
84
116
 
85
- Methadone::CLILogging.info("Answer to '#{ prompt }': #{r}") if log
117
+ # ----------------------------------------------------
118
+ # prompt_for_filepath method
119
+ #
120
+ # Outputs a prompt, collects the user's response, and
121
+ # returns it; adds in readline support for path
122
+ # completion.
123
+ #
124
+ # "ruby readline filename tab completion" - William Morgan
125
+ # http://masanjin.net/blog/ruby-readline-tab-completion
126
+ #
127
+ # @param prompt The prompt to output
128
+ # @param default The default option
129
+ # @param start_dir The directory in which to start
130
+ # @return String
131
+ # ----------------------------------------------------
132
+ def self.prompt_for_filepath(prompt, default = nil, start_dir = '')
133
+ Readline.completion_append_character = nil
134
+ Readline.completion_proc = lambda do |prefix|
135
+ files = Dir["#{start_dir}#{prefix}*"]
136
+ files.
137
+ map { |f| File.expand_path(f) }.
138
+ map { |f| File.directory?(f) ? f + "/" : f }
139
+ end
140
+ choice = Readline.readline("# #{ prompt } #{ default.nil? ? '' : "[default: #{ default }]:" } ".green)
141
+ if choice.empty?
142
+ r = default
143
+ else
144
+ r = choice
145
+ end
146
+ @@logger.debug("Answer to \"#{ prompt }\": #{ r }") unless @@logger.nil?
86
147
  r
87
148
  end
88
149
 
89
150
  # ----------------------------------------------------
90
151
  # section method
91
152
  #
92
- # Outputs a formatted-orange section message.
153
+ # Outputs a formatted-purple section message.
93
154
  # @param m The message to output
94
155
  # @return Void
95
156
  # ----------------------------------------------------
96
- def self.section(m, log = true)
97
- Methadone::CLILogging.info(m) if log
98
- puts "#### #{ m }".purple
157
+ def self.section(m)
158
+ puts "---> #{ m }".purple
159
+ @@logger.debug(m.purple) unless @@logger.nil?
99
160
  end
100
161
 
101
162
  # ----------------------------------------------------
@@ -108,18 +169,17 @@ module SifttterRedux
108
169
  # @param multiline A multiline message or not
109
170
  # @return Void
110
171
  # ----------------------------------------------------
111
- def self.section_block(m, multiline = true, log = true)
172
+ def self.section_block(m, multiline = true)
112
173
  if block_given?
113
174
  if multiline
114
- section(m, log)
175
+ section(m)
115
176
  else
116
- print "#### #{ m }".purple
177
+ print "---> #{ m }".purple
117
178
  end
118
179
 
119
180
  yield
120
181
  else
121
182
  error = 'Did not specify a valid block'
122
- Methadone::CLILogging.error(error) if log
123
183
  fail ArgumentError, error
124
184
  end
125
185
  end
@@ -131,9 +191,9 @@ module SifttterRedux
131
191
  # @param m The message to output
132
192
  # @return Void
133
193
  # ----------------------------------------------------
134
- def self.success(m, log = true)
135
- Methadone::CLILogging.info(m) if log
136
- puts "---> SUCCESS: #{ m }".green
194
+ def self.success(m)
195
+ puts "# #{ m }".green
196
+ @@logger.debug(m.green) unless @@logger.nil?
137
197
  end
138
198
 
139
199
  # ----------------------------------------------------
@@ -143,9 +203,75 @@ module SifttterRedux
143
203
  # @param m The message to output
144
204
  # @return Void
145
205
  # ----------------------------------------------------
146
- def self.warning(m, log = true)
147
- Methadone::CLILogging.warn(m) if log
148
- puts "---> WARNING: #{ m }".yellow
206
+ def self.warning(m)
207
+ puts "# #{ m }".yellow
208
+ @@logger.warn(m.yellow) unless @@logger.nil?
149
209
  end
150
210
  end
151
211
  end
212
+
213
+ # ======================================================
214
+ # String Class
215
+ # ======================================================
216
+ class String
217
+ # ----------------------------------------------------
218
+ # colorize method
219
+ #
220
+ # Outputs a string in a formatted color.
221
+ # @param color_code The code to use
222
+ # @return Void
223
+ # ----------------------------------------------------
224
+ def colorize(color_code)
225
+ "\e[#{ color_code }m#{ self }\e[0m"
226
+ end
227
+
228
+ # ----------------------------------------------------
229
+ # blue method
230
+ #
231
+ # Convenience method to output a blue string
232
+ # @return Void
233
+ # ----------------------------------------------------
234
+ def blue
235
+ colorize(34)
236
+ end
237
+
238
+ # ----------------------------------------------------
239
+ # green method
240
+ #
241
+ # Convenience method to output a green string
242
+ # @return Void
243
+ # ----------------------------------------------------
244
+ def green
245
+ colorize(32)
246
+ end
247
+
248
+ # ----------------------------------------------------
249
+ # purple method
250
+ #
251
+ # Convenience method to output a purple string
252
+ # @return Void
253
+ # ----------------------------------------------------
254
+ def purple
255
+ colorize(35)
256
+ end
257
+
258
+ # ----------------------------------------------------
259
+ # red method
260
+ #
261
+ # Convenience method to output a red string
262
+ # @return Void
263
+ # ----------------------------------------------------
264
+ def red
265
+ colorize(31)
266
+ end
267
+
268
+ # ----------------------------------------------------
269
+ # yellow method
270
+ #
271
+ # Convenience method to output a yellow string
272
+ # @return Void
273
+ # ----------------------------------------------------
274
+ def yellow
275
+ colorize(33)
276
+ end
277
+ end
@@ -21,7 +21,6 @@ module SifttterRedux
21
21
  def self.last_n_days(num_days, include_today = false)
22
22
  if num_days < 0
23
23
  error = 'Cannot specify a negative number of days'
24
- Methadone::CLILogging.error(error)
25
24
  fail ArgumentError, error
26
25
  end
27
26
 
@@ -44,7 +43,6 @@ module SifttterRedux
44
43
  def self.last_n_weeks(num_weeks = 0, include_today = false)
45
44
  if num_weeks < 0
46
45
  error = 'Cannot specify a negative number of weeks'
47
- Methadone::CLILogging.error(error)
48
46
  fail ArgumentError, error
49
47
  end
50
48
 
@@ -76,7 +74,6 @@ module SifttterRedux
76
74
  def self.range(start_date, end_date, include_today = false)
77
75
  if start_date.nil? && !end_date.nil?
78
76
  error = "You can't specify -t without specifying -f"
79
- Methadone::CLILogging.error(error)
80
77
  fail ArgumentError, error
81
78
  end
82
79
 
@@ -85,7 +82,6 @@ module SifttterRedux
85
82
  rescue
86
83
  unless start_date.nil?
87
84
  error = "Invalid date provided to Chronic: #{ start_date }"
88
- Methadone::CLILogging.error(error)
89
85
  fail ArgumentError, error
90
86
  end
91
87
  nil
@@ -96,7 +92,6 @@ module SifttterRedux
96
92
  rescue
97
93
  unless end_date.nil?
98
94
  error = "Invalid date provided to Chronic: #{ end_date }"
99
- Methadone::CLILogging.error(error)
100
95
  fail ArgumentError, error
101
96
  end
102
97
  nil
@@ -104,7 +99,6 @@ module SifttterRedux
104
99
 
105
100
  if chronic_end_date && chronic_start_date > chronic_end_date
106
101
  error = 'The start date must be before or equal to the end date'
107
- Methadone::CLILogging.error(error)
108
102
  fail ArgumentError, error
109
103
  end
110
104
 
@@ -0,0 +1,77 @@
1
+ module SifttterRedux
2
+ # ======================================================
3
+ # DropboxUploader Class
4
+ #
5
+ # Wrapper class for the Dropbox Uploader project
6
+ # ======================================================
7
+ class DropboxUploader
8
+ # ====================================================
9
+ # Constants
10
+ # ====================================================
11
+ CONFIG_FILEPATH = File.join(ENV['HOME'], '.dropbox_uploader')
12
+ DEFAULT_MESSAGE = 'RUNNING DROPBOX UPLOADER'
13
+
14
+ # ====================================================
15
+ # Attributes
16
+ # ====================================================
17
+ attr_accessor :local_target, :remote_target, :message, :verbose
18
+
19
+ # ====================================================
20
+ # Methods
21
+ # ====================================================
22
+ # ----------------------------------------------------
23
+ # initialize method
24
+ #
25
+ # Loads the location of dropbox_uploader.sh.
26
+ # @param dbu_path The local filepath to the script
27
+ # @logger A Logger to use
28
+ # @return Void
29
+ # ----------------------------------------------------
30
+ def initialize(dbu_path, logger = nil)
31
+ @dbu = dbu_path
32
+ @logger = logger
33
+ end
34
+
35
+ # ----------------------------------------------------
36
+ # download method
37
+ #
38
+ # Downloads files from Dropbox (assumes that both
39
+ # local_target and remote_target have been set).
40
+ # @return Void
41
+ # ----------------------------------------------------
42
+ def download
43
+ if !@local_target.nil? && !@remote_target.nil?
44
+ if @verbose
45
+ system "#{ @dbu } download #{ @remote_target } #{ @local_target }"
46
+ else
47
+ exec = `#{ @dbu } download #{ @remote_target } #{ @local_target }`
48
+ end
49
+ else
50
+ error_msg = 'Local and remote targets cannot be nil'
51
+ @logger.error(error_msg) if @logger
52
+ fail StandardError, error_msg
53
+ end
54
+ end
55
+
56
+ # ----------------------------------------------------
57
+ # upload method
58
+ #
59
+ # Uploads files tro Dropbox (assumes that both
60
+ # local_target and remote_target have been set).
61
+ # @return Void
62
+ # ----------------------------------------------------
63
+ def upload
64
+ if !@local_target.nil? && !@remote_target.nil?
65
+ if @verbose
66
+ system "#{ @dbu } upload #{ @local_target } #{ @remote_target }"
67
+ else
68
+ exec = `#{ @dbu } upload #{ @local_target }" "#{ @remote_target }`
69
+ end
70
+ else
71
+ error_msg = 'Local and remote targets cannot be nil'
72
+ @logger.error(error_msg) if @logger
73
+ fail StandardError, error_msg
74
+ end
75
+ end
76
+ end
77
+ end
@@ -48,8 +48,7 @@ module SifttterRedux
48
48
 
49
49
  files = `find #{ Configuration['sifttter_redux']['sifttter_local_filepath'] } -type f -name "*.txt" | grep -v -i daily | sort`
50
50
  if files.empty?
51
- m = "Couldn't download Sifttter files; is #{ Configuration['sifttter_redux']['sifttter_remote_filepath'] } the correct remote filepath?"
52
- CLIMessage.error(m)
51
+ CLIMessage::error("No Sifttter files to parse; is #{ Configuration['sifttter_redux']['sifttter_remote_filepath'] } the correct remote filepath?")
53
52
  return
54
53
  end
55
54
 
@@ -1,4 +1,4 @@
1
1
  module SifttterRedux
2
- VERSION = '0.4.6'
3
- NEWEST_CONFIG_VERSION = '0.4.3'
2
+ VERSION = '0.4.7'
3
+ NEWEST_CONFIG_VERSION = '0.4.7'
4
4
  end
@@ -1,9 +1,9 @@
1
- require 'sifttter_redux/cli_message.rb'
2
- require 'sifttter_redux/configuration.rb'
3
- require 'sifttter_redux/date_range_maker.rb'
4
- require 'sifttter_redux/dbu.rb'
5
- require 'sifttter_redux/sifttter.rb'
6
- require 'sifttter_redux/version.rb'
1
+ require 'sifttter_redux/cli_message'
2
+ require 'sifttter_redux/configuration'
3
+ require 'sifttter_redux/date_range_maker'
4
+ require 'sifttter_redux/dropbox_uploader'
5
+ require 'sifttter_redux/sifttter'
6
+ require 'sifttter_redux/version'
7
7
 
8
8
  # ======================================================
9
9
  # SifttterRedux Module
@@ -17,6 +17,7 @@ module SifttterRedux
17
17
  # ====================================================
18
18
  # Constants
19
19
  # ====================================================
20
+ DBU_CONFIG_FILEPATH = File.join(ENV['HOME'], '.dropbox_uploader')
20
21
  DBU_LOCAL_FILEPATH = '/usr/local/opt'
21
22
 
22
23
  DO_LOCAL_FILEPATH = '/tmp/dayone'
@@ -43,7 +44,63 @@ module SifttterRedux
43
44
  Configuration['sifttter_redux']['sifttter_local_filepath']
44
45
  ]
45
46
 
46
- CLIMessage::info_block('Removing temporary local files...') { dirs.each { |d| FileUtils.rm_rf(d) } }
47
+ CLIMessage::info_block('Removing temporary local files...') do
48
+ dirs.each do |d|
49
+ FileUtils.rm_rf(d)
50
+ CLIMessage::debug("Removed directory: #{ d }")
51
+ end
52
+ end
53
+ end
54
+
55
+ # ----------------------------------------------------
56
+ # install_wizard method
57
+ #
58
+ # Runs a wizard that installs Dropbox Uploader on the
59
+ # local filesystem.
60
+ # @return Void
61
+ # ----------------------------------------------------
62
+ def self.dbu_install_wizard(reinit = false)
63
+ valid_path_chosen = false
64
+
65
+ CLIMessage::section_block('CONFIGURING DROPBOX UPLOADER...') do
66
+ until valid_path_chosen
67
+ # Prompt the user for a location to save Dropbox Uploader.
68
+ if reinit && !Configuration['db_uploader']['base_filepath'].nil?
69
+ default = Configuration['db_uploader']['base_filepath']
70
+ else
71
+ default = DBU_LOCAL_FILEPATH
72
+ end
73
+ path = CLIMessage::prompt_for_filepath('Location for Dropbox-Uploader', default)
74
+ path = default if path.empty?
75
+ path.chop! if path.end_with?('/')
76
+
77
+ # If the entered directory exists, clone the repository.
78
+ if File.directory?(path)
79
+ valid_path_chosen = true
80
+
81
+ dbu_path = File.join(path, 'Dropbox-Uploader')
82
+ executable_path = File.join(dbu_path, 'dropbox_uploader.sh')
83
+
84
+ if File.directory?(dbu_path)
85
+ CLIMessage::warning("Using pre-existing Dropbox Uploader at #{ dbu_path }...")
86
+ else
87
+ CLIMessage::info_block("Downloading Dropbox Uploader to #{ dbu_path }...", 'Done.', true) do
88
+ system "git clone https://github.com/andreafabrizi/Dropbox-Uploader.git #{ dbu_path }"
89
+ end
90
+ end
91
+
92
+ # If the user has never configured Dropbox Uploader, have them do it here.
93
+ unless File.exists?(DBU_CONFIG_FILEPATH)
94
+ CLIMessage::info_block('Initializing Dropbox Uploader...') { system "#{ executable_path }" }
95
+ end
96
+
97
+ Configuration::add_section('db_uploader') unless reinit
98
+ Configuration['db_uploader'].merge!('base_filepath' => path, 'dbu_filepath' => dbu_path, 'exe_filepath' => executable_path)
99
+ else
100
+ CLIMessage::error("Sorry, but #{ path } isn't a valid directory.")
101
+ end
102
+ end
103
+ end
47
104
  end
48
105
 
49
106
  # ----------------------------------------------------
@@ -58,36 +115,35 @@ module SifttterRedux
58
115
  CLIMessage::section_block('EXECUTING...') do
59
116
  if options[:c] || options[:n] || options[:w] || options[:y] || options[:f] || options[:t]
60
117
  # Yesterday
61
- DateRangeMaker.yesterday if options[:y]
118
+ r = DateRangeMaker.yesterday if options[:y]
62
119
 
63
120
  # Current Week
64
- DateRangeMaker.last_n_weeks(0, options[:i]) if options[:c]
121
+ r = DateRangeMaker.last_n_weeks(0, options[:i]) if options[:c]
65
122
 
66
123
  # Last N Days
67
- DateRangeMaker.last_n_days(options[:n].to_i, options[:i]) if options[:n]
124
+ r = DateRangeMaker.last_n_days(options[:n].to_i, options[:i]) if options[:n]
68
125
 
69
126
  # Last N Weeks
70
- DateRangeMaker.last_n_weeks(options[:w].to_i, options[:i]) if options[:w]
127
+ r = DateRangeMaker.last_n_weeks(options[:w].to_i, options[:i]) if options[:w]
71
128
 
72
129
  # Custom Range
73
130
  if (options[:f] || options[:t])
74
- begin
75
- _dates = DateRangeMaker.range(options[:f], options[:t], options[:i])
76
-
77
- if _dates.last > Date.today
78
- long_message = "Ignoring overextended end date and using today's date (#{ Date.today })..."
79
- CLIMessage::warning(long_message)
80
- (_dates.first..Date.today)
81
- else
82
- (_dates.first.._dates.last)
83
- end
84
- rescue ArgumentError => e
85
- CLIMessage::error(e)
131
+ _dates = DateRangeMaker.range(options[:f], options[:t], options[:i])
132
+
133
+ if _dates.last > Date.today
134
+ long_message = "Ignoring overextended end date and using today's date (#{ Date.today })..."
135
+ CLIMessage::warning(long_message)
136
+ r = (_dates.first..Date.today)
137
+ else
138
+ r = (_dates.first.._dates.last)
86
139
  end
87
140
  end
88
141
  else
89
- DateRangeMaker.today
142
+ r = DateRangeMaker.today
90
143
  end
144
+
145
+ CLIMessage::debug("Date range: #{ r }")
146
+ r
91
147
  end
92
148
  end
93
149
 
@@ -103,10 +159,14 @@ module SifttterRedux
103
159
  Configuration::reset
104
160
  Configuration::add_section('sifttter_redux')
105
161
  end
106
- Configuration['sifttter_redux'].merge!('version' => VERSION, 'config_location' => Configuration::config_path)
162
+ Configuration['sifttter_redux'].merge!({
163
+ 'config_location' => Configuration::config_path,
164
+ 'log_level' => 'WARN',
165
+ 'version' => VERSION,
166
+ })
107
167
 
108
168
  # Run the wizard to download Dropbox Uploader.
109
- DBU::install_wizard(reinit = reinit)
169
+ dbu_install_wizard(reinit = reinit)
110
170
 
111
171
  # Collect other misc. preferences.
112
172
  CLIMessage::section_block('COLLECTING PREFERENCES...') do
@@ -139,13 +199,14 @@ module SifttterRedux
139
199
 
140
200
  pref_prompts.each do |prompt|
141
201
  d = reinit ? Configuration[prompt[:section]][prompt[:key]] : prompt[:default]
142
- pref = CLIMessage::prompt(prompt[:prompt], d)
202
+ pref = CLIMessage::prompt_for_filepath(prompt[:prompt], d)
143
203
 
144
204
  Configuration[prompt[:section]].merge!(prompt[:key] => File.expand_path(pref))
205
+ CLIMessage::debug("Value for #{ prompt[:key] }: #{ pref }")
145
206
  end
146
207
  end
147
208
 
148
- Methadone::CLILogging.info("Configuration values: #{ Configuration::dump }")
209
+ CLIMessage::debug("Configuration values: #{ Configuration::dump }")
149
210
  Configuration::save
150
211
  end
151
212
  end
@@ -24,5 +24,4 @@ spec = Gem::Specification.new do |s|
24
24
  s.add_development_dependency('rake', '~> 0')
25
25
  s.add_runtime_dependency('chronic', '0.10.2')
26
26
  s.add_runtime_dependency('gli','2.9.0')
27
- s.add_runtime_dependency('methadone', '1.3.2')
28
27
  end
@@ -1,52 +1,54 @@
1
- require 'methadone'
1
+ require 'readline'
2
2
  require 'test_helper'
3
3
  require File.join(File.dirname(__FILE__), '..', 'lib/sifttter_redux/cli_message.rb')
4
4
 
5
- include Methadone::CLILogging
6
-
7
5
  class CLIMessageTest < Test::Unit::TestCase
6
+ def setup
7
+ SifttterRedux::CLIMessage::deactivate_logging
8
+ end
9
+
8
10
  def test_error_message
9
- assert_output('---> ERROR: test'.red + "\n") { SifttterRedux::CLIMessage::error('test', false) }
11
+ assert_output('# test'.red + "\n") { SifttterRedux::CLIMessage::error('test') }
10
12
  end
11
13
 
12
14
  def test_info_message
13
- assert_output('---> INFO: test'.blue + "\n") { SifttterRedux::CLIMessage::info('test', false) }
15
+ assert_output('# test'.blue + "\n") { SifttterRedux::CLIMessage::info('test') }
14
16
  end
15
17
 
16
18
  def test_info_block_single_line
17
- assert_output("---> INFO: start".blue + "body\n" + 'end'.blue + "\n") do
18
- SifttterRedux::CLIMessage::info_block('start', 'end', false, false) { puts 'body' }
19
+ assert_output("# start".blue + "body\n" + 'end'.blue + "\n") do
20
+ SifttterRedux::CLIMessage::info_block('start', 'end') { puts 'body' }
19
21
  end
20
22
  end
21
23
 
22
24
  def test_info_block_multiline
23
- assert_output("---> INFO: start".blue + "\nbody\n" + '---> INFO: end'.blue + "\n") do
24
- SifttterRedux::CLIMessage::info_block('start', 'end', true, false) { puts 'body' }
25
+ assert_output("# start".blue + "\nbody\n" + '# end'.blue + "\n") do
26
+ SifttterRedux::CLIMessage::info_block('start', 'end', true) { puts 'body' }
25
27
  end
26
28
  end
27
29
 
28
30
  def test_info_block_no_block
29
31
  assert_raise ArgumentError do
30
- SifttterRedux::CLIMessage::info_block('start', 'end', true, false)
32
+ SifttterRedux::CLIMessage::info_block('start', 'end', true)
31
33
  end
32
34
  end
33
35
 
34
36
  def test_section_message
35
- assert_output('#### test'.purple + "\n") { SifttterRedux::CLIMessage::section('test', false) }
37
+ assert_output('---> test'.purple + "\n") { SifttterRedux::CLIMessage::section('test') }
36
38
  end
37
39
 
38
40
  def test_section_block_single_line
39
- assert_output("#### section".purple + "\nbody\n") do
40
- SifttterRedux::CLIMessage::section_block('section', true, false) { puts 'body' }
41
+ assert_output("---> section".purple + "\nbody\n") do
42
+ SifttterRedux::CLIMessage::section_block('section', true) { puts 'body' }
41
43
  end
42
44
  end
43
45
 
44
46
  def test_success_message
45
- assert_output('---> SUCCESS: test'.green + "\n") { SifttterRedux::CLIMessage::success('test', false) }
47
+ assert_output('# test'.green + "\n") { SifttterRedux::CLIMessage::success('test') }
46
48
  end
47
49
 
48
50
  def test_warning_message
49
- assert_output('---> WARNING: test'.yellow + "\n") { SifttterRedux::CLIMessage::warning('test', false) }
51
+ assert_output('# test'.yellow + "\n") { SifttterRedux::CLIMessage::warning('test') }
50
52
  end
51
53
 
52
54
  def test_prompt
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sifttter-redux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Bach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-13 00:00:00.000000000 Z
11
+ date: 2014-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.9.0
55
- - !ruby/object:Gem::Dependency
56
- name: methadone
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '='
60
- - !ruby/object:Gem::Version
61
- version: 1.3.2
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '='
67
- - !ruby/object:Gem::Version
68
- version: 1.3.2
69
55
  description: A customized IFTTT-to-Day One service that allows for smart installation
70
56
  and automated running on a standalone *NIX device (such as a Raspberry Pi).
71
57
  email: bachya1208@gmail.com
@@ -89,9 +75,8 @@ files:
89
75
  - lib/sifttter_redux/cli_message.rb
90
76
  - lib/sifttter_redux/configuration.rb
91
77
  - lib/sifttter_redux/date_range_maker.rb
92
- - lib/sifttter_redux/dbu.rb
78
+ - lib/sifttter_redux/dropbox_uploader.rb
93
79
  - lib/sifttter_redux/sifttter.rb
94
- - lib/sifttter_redux/string_extensions.rb
95
80
  - lib/sifttter_redux/version.rb
96
81
  - sifttter_redux.gemspec
97
82
  - test/cli_message_test.rb
@@ -1,160 +0,0 @@
1
- module SifttterRedux
2
- # ======================================================
3
- # DBU Module
4
- #
5
- # Wrapper module for the Dropbox Uploader project
6
- # ======================================================
7
- module DBU
8
- # ====================================================
9
- # Constants
10
- # ====================================================
11
- CONFIG_FILEPATH = File.join(ENV['HOME'], '.dropbox_uploader')
12
- DEFAULT_MESSAGE = 'RUNNING DROPBOX UPLOADER'
13
-
14
- # ====================================================
15
- # Methods
16
- # ====================================================
17
- # ----------------------------------------------------
18
- # download method
19
- #
20
- # Downloads the files at the remote Dropbox filepath
21
- # to a filepath on the local filesystem.
22
- # @return Void
23
- # ----------------------------------------------------
24
- def self.download
25
- if !@local_path.nil? && !@remote_path.nil?
26
- CLIMessage::info_block(@message ||= DEFAULT_MESSAGE, 'Done.', SifttterRedux.verbose) do
27
- if SifttterRedux.verbose
28
- system "#{ @dbu } download #{ @remote_path } #{ @local_path }"
29
- else
30
- exec = `#{ @dbu } download #{ @remote_path } #{ @local_path }`
31
- end
32
- end
33
- else
34
- error = 'Local and remote DBU targets cannot be nil'
35
- Methadone::CLILogging.error(error)
36
- fail ArgumentError, error
37
- end
38
- end
39
-
40
- # ----------------------------------------------------
41
- # install_wizard method
42
- #
43
- # Runs a wizard that installs Dropbox Uploader on the
44
- # local filesystem.
45
- # @return Void
46
- # ----------------------------------------------------
47
- def self.install_wizard(reinit = false)
48
- valid_path_chosen = false
49
-
50
- CLIMessage::section_block('CONFIGURING DROPBOX UPLOADER...') do
51
- until valid_path_chosen
52
- # Prompt the user for a location to save Dropbox Uploader.
53
- if reinit && !Configuration['db_uploader']['base_filepath'].nil?
54
- default = Configuration['db_uploader']['base_filepath']
55
- else
56
- default = DBU_LOCAL_FILEPATH
57
- end
58
- path = CLIMessage::prompt('Location for Dropbox-Uploader', default)
59
- path.chop! if path.end_with?('/')
60
-
61
- # If the entered directory exists, clone the repository.
62
- if File.directory?(path)
63
- valid_path_chosen = true
64
-
65
- dbu_path = File.join(path, 'Dropbox-Uploader')
66
- executable_path = File.join(dbu_path, 'dropbox_uploader.sh')
67
-
68
- if File.directory?(dbu_path)
69
- CLIMessage::warning("Using pre-existing Dropbox Uploader at #{ dbu_path }...")
70
- else
71
- CLIMessage::info_block("Downloading Dropbox Uploader to #{ dbu_path }...", 'Done.', true) do
72
- system "git clone https://github.com/andreafabrizi/Dropbox-Uploader.git #{ dbu_path }"
73
- end
74
- end
75
-
76
- # If the user has never configured Dropbox Uploader, have them do it here.
77
- unless File.exists?(CONFIG_FILEPATH)
78
- CLIMessage::info_block('Initializing Dropbox Uploader...') { system "#{ executable_path }" }
79
- end
80
-
81
- Configuration::add_section('db_uploader') unless reinit
82
- Configuration['db_uploader'].merge!('base_filepath' => path, 'dbu_filepath' => dbu_path, 'exe_filepath' => executable_path)
83
- else
84
- CLIMessage::error("Sorry, but #{ path } isn't a valid directory.")
85
- end
86
- end
87
- end
88
- end
89
-
90
- # ----------------------------------------------------
91
- # load method
92
- #
93
- # Loads the location of dropbox_uploader.sh.
94
- # @param dbu_path The local filepath to the script
95
- # @return Void
96
- # ----------------------------------------------------
97
- def self.load(dbu_path)
98
- @dbu = dbu_path
99
- end
100
-
101
- # ----------------------------------------------------
102
- # set_local_target method
103
- #
104
- # Sets the local filesystem path to which files will
105
- # be downloaded.
106
- # @param path A local filepath
107
- # @return Void
108
- # ----------------------------------------------------
109
- def self.local_target=(path)
110
- @local_path = path
111
- end
112
-
113
- # ----------------------------------------------------
114
- # set_message method
115
- #
116
- # Sets the message to be displayed just before
117
- # downloading commences.
118
- # @param message The string to display
119
- # @return Void
120
- # ----------------------------------------------------
121
- def self.message=(message)
122
- @message = message
123
- end
124
-
125
- # ----------------------------------------------------
126
- # set_remote_target method
127
- #
128
- # Sets the remote Dropbox path from which files will
129
- # be downloaded.
130
- # @param path A remote Dropbox filepath
131
- # @return Void
132
- # ----------------------------------------------------
133
- def self.remote_target=(path)
134
- @remote_path = path
135
- end
136
-
137
- # ----------------------------------------------------
138
- # upload method
139
- #
140
- # Uploads the files from the local filesystem path to
141
- # the remote Dropbox path.
142
- # @return Void
143
- # ----------------------------------------------------
144
- def self.upload
145
- if !@local_path.nil? && !@remote_path.nil?
146
- CLIMessage::info_block(@message ||= DEFAULT_MESSAGE, 'Done.', SifttterRedux.verbose) do
147
- if SifttterRedux.verbose
148
- system "#{ @dbu } upload #{ @local_path } #{ @remote_path }"
149
- else
150
- exec = `#{ @dbu } upload #{ @local_path } #{ @remote_path }`
151
- end
152
- end
153
- else
154
- error = 'Local and remote DBU targets cannot be nil'
155
- Methadone::CLILogging.error(error)
156
- fail ArgumentError, error
157
- end
158
- end
159
- end
160
- end
@@ -1,65 +0,0 @@
1
- # ======================================================
2
- # String Class
3
- # ======================================================
4
- class String
5
- # ----------------------------------------------------
6
- # colorize method
7
- #
8
- # Outputs a string in a formatted color.
9
- # @param color_code The code to use
10
- # @return Void
11
- # ----------------------------------------------------
12
- def colorize(color_code)
13
- "\e[#{ color_code }m#{ self }\e[0m"
14
- end
15
-
16
- # ----------------------------------------------------
17
- # blue method
18
- #
19
- # Convenience method to output a blue string
20
- # @return Void
21
- # ----------------------------------------------------
22
- def blue
23
- colorize(34)
24
- end
25
-
26
- # ----------------------------------------------------
27
- # green method
28
- #
29
- # Convenience method to output a green string
30
- # @return Void
31
- # ----------------------------------------------------
32
- def green
33
- colorize(32)
34
- end
35
-
36
- # ----------------------------------------------------
37
- # purple method
38
- #
39
- # Convenience method to output a purple string
40
- # @return Void
41
- # ----------------------------------------------------
42
- def purple
43
- colorize(35)
44
- end
45
-
46
- # ----------------------------------------------------
47
- # red method
48
- #
49
- # Convenience method to output a red string
50
- # @return Void
51
- # ----------------------------------------------------
52
- def red
53
- colorize(31)
54
- end
55
-
56
- # ----------------------------------------------------
57
- # yellow method
58
- #
59
- # Convenience method to output a yellow string
60
- # @return Void
61
- # ----------------------------------------------------
62
- def yellow
63
- colorize(33)
64
- end
65
- end