sifttter-redux 0.5.4 → 0.6

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.
@@ -1,77 +0,0 @@
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
@@ -1,6 +0,0 @@
1
- module SifttterRedux
2
- DESCRIPTION = 'A customized IFTTT-to-Day One service that allows for smart installation and automated running on a standalone *NIX device (such as a Raspberry Pi).'
3
- SUMMARY = 'Automated IFTTT to Day One engine.'
4
- VERSION = '0.5.4'
5
- NEWEST_CONFIG_VERSION = '0.5.4'
6
- end
@@ -1,218 +0,0 @@
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
-
8
- # ======================================================
9
- # SifttterRedux Module
10
- #
11
- # Wrapper module for all other modules in this project
12
- # ======================================================
13
-
14
- module SifttterRedux
15
- attr_accessor :verbose
16
-
17
- # ====================================================
18
- # Constants
19
- # ====================================================
20
- DBU_CONFIG_FILEPATH = File.join(ENV['HOME'], '.dropbox_uploader')
21
- DBU_LOCAL_FILEPATH = '/usr/local/opt'
22
-
23
- DO_LOCAL_FILEPATH = '/tmp/dayone'
24
- DO_REMOTE_FILEPATH = "/Apps/Day\\ One/Journal.dayone/entries"
25
-
26
- SFT_LOCAL_FILEPATH = '/tmp/sifttter'
27
- SFT_REMOTE_FILEPATH = '/Apps/ifttt/sifttter'
28
-
29
- SRD_CONFIG_FILEPATH = File.join(ENV['HOME'], '.sifttter_redux')
30
- SRD_LOG_FILEPATH = File.join(ENV['HOME'], '.sifttter_redux_log')
31
-
32
- # ====================================================
33
- # Methods
34
- # ====================================================
35
- # ----------------------------------------------------
36
- # cleanup_temp_files method
37
- #
38
- # Removes temporary directories and their contents
39
- # @return Void
40
- # ----------------------------------------------------
41
- def self.cleanup_temp_files
42
- dirs = [
43
- Configuration::sifttter_redux[:dayone_local_filepath],
44
- Configuration::sifttter_redux[:sifttter_local_filepath]
45
- ]
46
-
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(init_from_scratch = 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 init_from_scratch && !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('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 init_from_scratch
98
- Configuration::db_uploader.merge!({
99
- base_filepath: path,
100
- dbu_filepath: dbu_path,
101
- exe_filepath: executable_path
102
- })
103
- else
104
- CLIMessage::error("Sorry, but #{ path } isn't a valid directory.")
105
- end
106
- end
107
- end
108
- end
109
-
110
- # ----------------------------------------------------
111
- # get_dates_from_options method
112
- #
113
- # Creates a date range from the supplied command line
114
- # options.
115
- # @param options A Hash of command line options
116
- # @return Range
117
- # ----------------------------------------------------
118
- def self.get_dates_from_options(options)
119
- CLIMessage::section_block('EXECUTING...') do
120
- if options[:c] || options[:n] || options[:w] || options[:y] || options[:f] || options[:t]
121
- # Yesterday
122
- r = DateRangeMaker.yesterday if options[:y]
123
-
124
- # Current Week
125
- r = DateRangeMaker.last_n_weeks(0, options[:i]) if options[:c]
126
-
127
- # Last N Days
128
- r = DateRangeMaker.last_n_days(options[:n].to_i, options[:i]) if options[:n]
129
-
130
- # Last N Weeks
131
- r = DateRangeMaker.last_n_weeks(options[:w].to_i, options[:i]) if options[:w]
132
-
133
- # Custom Range
134
- if (options[:f] || options[:t])
135
- _dates = DateRangeMaker.range(options[:f], options[:t], options[:i])
136
-
137
- if _dates.last > Date.today
138
- long_message = "Ignoring overextended end date and using today's date (#{ Date.today })..."
139
- CLIMessage::warning(long_message)
140
- r = (_dates.first..Date.today)
141
- else
142
- r = (_dates.first.._dates.last)
143
- end
144
- end
145
- else
146
- r = DateRangeMaker.today
147
- end
148
-
149
- CLIMessage::debug("Date range: #{ r }")
150
- r
151
- end
152
- end
153
-
154
- # ----------------------------------------------------
155
- # initialize_procedures method
156
- #
157
- # Initializes Sifttter Redux by downloading and
158
- # collecting all necessary items and info.
159
- # @return Void
160
- # ----------------------------------------------------
161
- def self.init(init_from_scratch = false)
162
- if init_from_scratch
163
- Configuration::reset
164
- Configuration::add_section(:sifttter_redux)
165
- end
166
-
167
- Configuration::sifttter_redux.merge!({
168
- config_location: Configuration::config_path,
169
- log_level: 'WARN',
170
- version: VERSION,
171
- })
172
-
173
- # Run the wizard to download Dropbox Uploader.
174
- dbu_install_wizard(init_from_scratch = init_from_scratch)
175
-
176
- # Collect other misc. preferences.
177
- CLIMessage::section_block('COLLECTING PREFERENCES...') do
178
- pref_prompts = [
179
- {
180
- prompt: 'Temporary path to download Sifttter files to',
181
- default: SFT_LOCAL_FILEPATH,
182
- key: :sifttter_local_filepath,
183
- section: :sifttter_redux
184
- },
185
- {
186
- prompt: 'Path to Sifttter files in Dropbox',
187
- default: SFT_REMOTE_FILEPATH,
188
- key: :sifttter_remote_filepath,
189
- section: :sifttter_redux
190
- },
191
- {
192
- prompt: 'Temporary path to download Day One files to',
193
- default: DO_LOCAL_FILEPATH,
194
- key: :dayone_local_filepath,
195
- section: :sifttter_redux
196
- },
197
- {
198
- prompt: 'Path to Day One files in Dropbox',
199
- default: DO_REMOTE_FILEPATH,
200
- key: :dayone_remote_filepath,
201
- section: :sifttter_redux
202
- }
203
- ]
204
-
205
- pref_prompts.each do |prompt|
206
- d = init_from_scratch ? prompt[:default] : Configuration::send(prompt[:section])[prompt[:key]]
207
- pref = CLIMessage::prompt(prompt[:prompt], d)
208
- pref = File.expand_path(pref) if pref.start_with?('~')
209
-
210
- Configuration::send(prompt[:section]).merge!(prompt[:key] => pref)
211
- CLIMessage::debug("Value for #{ prompt[:key] }: #{ pref }")
212
- end
213
- end
214
-
215
- CLIMessage::debug("Configuration values: #{ Configuration::dump }")
216
- Configuration::save
217
- end
218
- end
@@ -1,54 +0,0 @@
1
- require 'readline'
2
- require 'test_helper'
3
- require File.join(File.dirname(__FILE__), '..', 'lib/sifttter_redux/cli_message.rb')
4
-
5
- class CLIMessageTest < Test::Unit::TestCase
6
- def setup
7
- SifttterRedux::CLIMessage::deactivate_logging
8
- end
9
-
10
- def test_error_message
11
- assert_output('# test'.red + "\n") { SifttterRedux::CLIMessage::error('test') }
12
- end
13
-
14
- def test_info_message
15
- assert_output('# test'.blue + "\n") { SifttterRedux::CLIMessage::info('test') }
16
- end
17
-
18
- def test_info_block_single_line
19
- assert_output("# start".blue + "body\n" + 'end'.blue + "\n") do
20
- SifttterRedux::CLIMessage::info_block('start', 'end') { puts 'body' }
21
- end
22
- end
23
-
24
- def test_info_block_multiline
25
- assert_output("# start".blue + "\nbody\n" + '# end'.blue + "\n") do
26
- SifttterRedux::CLIMessage::info_block('start', 'end', true) { puts 'body' }
27
- end
28
- end
29
-
30
- def test_info_block_no_block
31
- assert_raise ArgumentError do
32
- SifttterRedux::CLIMessage::info_block('start', 'end', true)
33
- end
34
- end
35
-
36
- def test_section_message
37
- assert_output('---> test'.purple + "\n") { SifttterRedux::CLIMessage::section('test') }
38
- end
39
-
40
- def test_section_block_single_line
41
- assert_output("---> section".purple + "\nbody\n") do
42
- SifttterRedux::CLIMessage::section_block('section', true) { puts 'body' }
43
- end
44
- end
45
-
46
- def test_success_message
47
- assert_output('# test'.green + "\n") { SifttterRedux::CLIMessage::success('test') }
48
- end
49
-
50
- def test_warning_message
51
- assert_output('# test'.yellow + "\n") { SifttterRedux::CLIMessage::warning('test') }
52
- end
53
-
54
- end
@@ -1,78 +0,0 @@
1
- require 'test_helper'
2
- require File.join(File.dirname(__FILE__), '..', 'lib/sifttter_redux/configuration.rb')
3
-
4
- class ConfigurationTest < Test::Unit::TestCase
5
-
6
- def setup
7
- SifttterRedux::Configuration::load('/tmp/srd_config')
8
- end
9
-
10
- def teardown
11
- File.delete('/tmp/srd_config') if File.exists?('/tmp/srd_config')
12
- end
13
-
14
- def test_add_data
15
- SifttterRedux::Configuration::reset
16
- SifttterRedux::Configuration::add_section(:section1)
17
- SifttterRedux::Configuration::section1.merge!( a: 'test', b: 'test' )
18
- assert_equal(SifttterRedux::Configuration::dump, { section1: { a: 'test', b: 'test' } })
19
-
20
- SifttterRedux::Configuration::section1[:a] = 'bigger test'
21
- SifttterRedux::Configuration::section1[:c] = 'little test'
22
- assert_equal(SifttterRedux::Configuration::dump, { section1: { a: 'bigger test', b: 'test', c: 'little test' } })
23
- end
24
-
25
- def test_add_section
26
- SifttterRedux::Configuration::reset
27
- SifttterRedux::Configuration::add_section(:section1)
28
- SifttterRedux::Configuration::add_section(:section2)
29
- assert_equal(SifttterRedux::Configuration::dump, { section1: {}, section2: {} })
30
- end
31
-
32
- def test_add_section_duplicate
33
- SifttterRedux::Configuration::reset
34
- SifttterRedux::Configuration::add_section(:section1)
35
- SifttterRedux::Configuration::add_section(:section2)
36
- SifttterRedux::Configuration::add_section(:section2)
37
- assert_equal(SifttterRedux::Configuration::dump, { section1: {}, section2: {} })
38
- end
39
-
40
- def test_config_path
41
- assert_equal(SifttterRedux::Configuration::config_path, '/tmp/srd_config')
42
- end
43
-
44
- def test_delete_section
45
- SifttterRedux::Configuration::reset
46
- SifttterRedux::Configuration::add_section(:section1)
47
- SifttterRedux::Configuration::add_section(:section2)
48
- SifttterRedux::Configuration::delete_section(:section2)
49
- assert_equal(SifttterRedux::Configuration::dump, { section1: {} })
50
- end
51
-
52
- def test_delete_section_nonexistant
53
- SifttterRedux::Configuration::reset
54
- SifttterRedux::Configuration::add_section(:section1)
55
- SifttterRedux::Configuration::delete_section('section12723762323')
56
- assert_equal(SifttterRedux::Configuration::dump, { section1: {} })
57
- end
58
-
59
- def test_reset
60
- SifttterRedux::Configuration::reset
61
- SifttterRedux::Configuration::add_section(:section1)
62
- SifttterRedux::Configuration::add_section(:section2)
63
- SifttterRedux::Configuration::add_section(:section3)
64
- SifttterRedux::Configuration::reset
65
- assert_equal(SifttterRedux::Configuration::dump, {})
66
- end
67
-
68
- def test_save
69
- SifttterRedux::Configuration::reset
70
- SifttterRedux::Configuration::add_section(:section1)
71
- SifttterRedux::Configuration.section1.merge!({ a: 'test', b: 'test' })
72
- SifttterRedux::Configuration::save
73
-
74
- File.open('/tmp/srd_config', 'r') do |f|
75
- assert_output("---\n:section1:\n :a: test\n :b: test\n") { puts f.read }
76
- end
77
- end
78
- end