henchman-sync 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/README.md +17 -5
- data/lib/applescript.rb +47 -9
- data/lib/cache.rb +63 -0
- data/lib/clean.rb +59 -0
- data/lib/core.rb +16 -41
- data/lib/henchman/version.rb +1 -1
- data/lib/henchman.rb +12 -0
- data/lib/launchd_handler.rb +23 -12
- data/lib/templates.rb +44 -5
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00b0b426fe2f85ce317502bbfec6dbe6545f757d
|
4
|
+
data.tar.gz: 0d62c14e6b5d9fe87241e4e94e31264f2b6f99a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0141c85238c432b3ed3a6441ecff9d5639626339e8f3ce6137ce600b2a3da28917a3ad176850cee3d3e1a5848aeb0788e71afa4bfcddacd1595f634851624d23
|
7
|
+
data.tar.gz: 5d0d0d6a43f71ad8d0a01c83d42611880820a3f26442074f08b61c166914103076d5cfd7f1a14c903ada9e0b710cc4beacbaaf9f199c4914ea13139743473682
|
data/README.md
CHANGED
@@ -22,11 +22,25 @@ This will guide you through setting up the application, including linking your D
|
|
22
22
|
|
23
23
|
This starts the henchman daemon. You can now select a track in iTunes which is not available locally, and you will be asked if you'd like to fetch the track from your Dropbox. The application will also automatically download the rest of the album that contains the track you selected.
|
24
24
|
|
25
|
+
You can also click on a playlist, and if that playlist has tracks that are not available locally, they will be downloaded for you.
|
26
|
+
|
27
|
+
Starting the henchman daemon will also create a task to cleanse your iTunes tracks twice per day*. The task runs at 12:00 AM and PM (or as soon as possible if the machine was asleep at that time.) Any track that hasn't been played in more than 24 hours AND wasn't downloaded in the last 24 hours will be removed from your machine. You can also run the clean manually by running
|
28
|
+
|
29
|
+
$ henchman clean
|
30
|
+
|
31
|
+
You can also run
|
32
|
+
|
33
|
+
$ henchman clean --played_date 'true'
|
34
|
+
|
35
|
+
To remove tracks that haven't been played in the last 24 hours (ignoring when the track was last downloaded.)
|
36
|
+
|
37
|
+
* = as of version 0.3.0 - if you were running an earlier version simply stop and re-start henchman
|
38
|
+
|
25
39
|
## Troubleshooting
|
26
40
|
|
27
|
-
Running the `configure` command creates a `~/.henchman` direction. This directory contains your configuration file, as well as log files and a shell
|
41
|
+
Running the `configure` command creates a `~/.henchman` direction. This directory contains your configuration file, as well as log files and a shell scripts used for running the application. If nothing appears to be happening in iTunes after running `henchman start` your best bet is to check the log files.
|
28
42
|
|
29
|
-
By default, the application checks if iTunes is open every 10 seconds.
|
43
|
+
By default, the application checks if iTunes is open every 10 seconds. If it is, it continues to poll iTunes every 3 seconds to see if a track is selected. If you'd like to change these, you can edit the `config` YAML file. If you edit the `poll_itunes_open` setting, you'll need to stop and re-start the henchman daemon.
|
30
44
|
|
31
45
|
## Development
|
32
46
|
|
@@ -36,9 +50,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
36
50
|
|
37
51
|
## TODO
|
38
52
|
|
39
|
-
|
40
|
-
- Figure out how to download playlist with a "'" in them
|
41
|
-
- Move off of the 'dropbox-sdk' gem, since it uses their API V1, which will be depreciated June 28th, 2017 (or just buck up and update the gem myself)
|
53
|
+
- Move off of the 'dropbox-sdk' gem, since it uses their API V1, which will be depreciated June 28th, 2017 (or just buck up and update the gem myself)
|
42
54
|
|
43
55
|
## Contributing
|
44
56
|
|
data/lib/applescript.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
1
3
|
module Henchman
|
2
4
|
|
3
5
|
class AppleScript
|
@@ -15,7 +17,7 @@ module Henchman
|
|
15
17
|
|
16
18
|
def prompt_script prompt
|
17
19
|
"tell application \"iTunes\"\n"\
|
18
|
-
" display dialog \"Fetch #{prompt}?\"\n"\
|
20
|
+
" display dialog \"Fetch #{prompt.gsub(/'/){ %q('"'"') }}?\"\n"\
|
19
21
|
"end tell"
|
20
22
|
end
|
21
23
|
|
@@ -62,8 +64,8 @@ module Henchman
|
|
62
64
|
"tell application \"iTunes\"\n"\
|
63
65
|
" try\n"\
|
64
66
|
" set album_tracks to "\
|
65
|
-
" (every track whose artist is \"#{artist}\" "\
|
66
|
-
" and album is \"#{album}\")\n"\
|
67
|
+
" (every track whose artist is \"#{artist.gsub(/'/){ %q('"'"') }}\" "\
|
68
|
+
" and album is \"#{album.gsub(/'/){ %q('"'"') }}\")\n"\
|
67
69
|
" set str to \"\"\n"\
|
68
70
|
" repeat with album_track in album_tracks\n"\
|
69
71
|
" set data_location to location of album_track as string\n"\
|
@@ -133,7 +135,7 @@ module Henchman
|
|
133
135
|
def get_playlist_tracks_script playlist
|
134
136
|
"tell application \"iTunes\"\n"\
|
135
137
|
" try\n"\
|
136
|
-
" set playlist_tracks to every track in playlist \"#{playlist}\"\n"\
|
138
|
+
" set playlist_tracks to every track in playlist \"#{playlist.gsub(/'/){ %q('"'"') }}\"\n"\
|
137
139
|
" set str to \"\"\n"\
|
138
140
|
" repeat with playlist_track in playlist_tracks\n"\
|
139
141
|
" set data_location to location of playlist_track as string\n"\
|
@@ -142,9 +144,9 @@ module Henchman
|
|
142
144
|
" set data_album to album of playlist_track as string\n"\
|
143
145
|
" set data_title to name of playlist_track as string\n"\
|
144
146
|
" set data_id to database ID of playlist_track as string\n"\
|
145
|
-
" set str to str & data_artist & \"#{@delimiter}\"
|
146
|
-
" & data_album & \"#{@delimiter}\"
|
147
|
-
" & data_title & \"#{@delimiter}\"
|
147
|
+
" set str to str & data_artist & \"#{@delimiter}\""\
|
148
|
+
" & data_album & \"#{@delimiter}\""\
|
149
|
+
" & data_title & \"#{@delimiter}\""\
|
148
150
|
" & data_id & \"#{@delimiter*2}\"\n"\
|
149
151
|
" end if\n"\
|
150
152
|
" end repeat\n"\
|
@@ -155,6 +157,28 @@ module Henchman
|
|
155
157
|
"end tell"
|
156
158
|
end
|
157
159
|
|
160
|
+
def get_tracks_with_location_script
|
161
|
+
"tell application \"iTunes\"\n"\
|
162
|
+
" try\n"\
|
163
|
+
" set all_tracks to every track in playlist \"Music\"\n"\
|
164
|
+
" set str to \"\"\n"\
|
165
|
+
" repeat with cur_track in all_tracks\n"\
|
166
|
+
" set data_location to location of cur_track as string\n"\
|
167
|
+
" if data_location is not equal to \"missing value\" then\n"\
|
168
|
+
" set data_id to database ID of cur_track as string\n"\
|
169
|
+
" set data_date to played date of cur_track\n"\
|
170
|
+
" set str to str & data_id & \"#{@delimiter}\""\
|
171
|
+
" & data_date & \"#{@delimiter}\""\
|
172
|
+
" & (POSIX path of data_location as string) & \"#{@delimiter*2}\"\n"\
|
173
|
+
" end if\n"\
|
174
|
+
" end repeat\n"\
|
175
|
+
" return str\n"\
|
176
|
+
" on error\n"\
|
177
|
+
" return 0\n"\
|
178
|
+
" end try\n"\
|
179
|
+
"end tell\n"\
|
180
|
+
end
|
181
|
+
|
158
182
|
def applescript_command(script)
|
159
183
|
"osascript -e '#{script}' 2> /dev/null"
|
160
184
|
end
|
@@ -173,6 +197,20 @@ module Henchman
|
|
173
197
|
track
|
174
198
|
end
|
175
199
|
|
200
|
+
def get_tracks_with_location
|
201
|
+
tracks = Array.new
|
202
|
+
tmp_tracks = %x(#{applescript_command(get_tracks_with_location_script)}).chomp
|
203
|
+
tmp_tracks = tmp_tracks.split @delimiter*2
|
204
|
+
tmp_tracks.each do |track|
|
205
|
+
next if track.empty?
|
206
|
+
tmp_track = track.split @delimiter
|
207
|
+
tracks.push( {:id => tmp_track[0],
|
208
|
+
:date => DateTime.parse(tmp_track[1]),
|
209
|
+
:path => tmp_track[2]} )
|
210
|
+
end
|
211
|
+
tracks
|
212
|
+
end
|
213
|
+
|
176
214
|
def get_playlist
|
177
215
|
playlist = %x(#{applescript_command(get_playlist_script)}).chomp
|
178
216
|
playlist = playlist.split @delimiter
|
@@ -187,7 +225,7 @@ module Henchman
|
|
187
225
|
tracks = Array.new
|
188
226
|
tmp_tracks = %x(#{applescript_command(get_playlist_tracks_script playlist)}).chomp
|
189
227
|
tmp_tracks = tmp_tracks.split @delimiter*2
|
190
|
-
tmp_tracks.
|
228
|
+
tmp_tracks.each do |track|
|
191
229
|
next if track.empty?
|
192
230
|
tmp_track = track.split @delimiter
|
193
231
|
tracks.push( {:artist => tmp_track[0],
|
@@ -204,7 +242,7 @@ module Henchman
|
|
204
242
|
tracks = Array.new
|
205
243
|
tmp_tracks = %x(#{applescript_command(get_album_tracks_script artist, album)}).chomp
|
206
244
|
tmp_tracks = tmp_tracks.split @delimiter*2
|
207
|
-
tmp_tracks.
|
245
|
+
tmp_tracks.each do |track|
|
208
246
|
next if track.empty?
|
209
247
|
tmp_track = track.split @delimiter
|
210
248
|
next if tmp_track[3] == selection[:id]
|
data/lib/cache.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "templates"
|
2
|
+
require "date"
|
3
|
+
|
4
|
+
module Henchman
|
5
|
+
|
6
|
+
class Cache
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
begin
|
10
|
+
@cache_file = File.expand_path("~/.henchman/cache")
|
11
|
+
@cache = YAML.load_file(@cache_file)
|
12
|
+
raise "Incorrectly formatted cache" if !(@cache.include? :ignore)
|
13
|
+
|
14
|
+
@cache[:ignore].each_value { |val| val.default = 0 }
|
15
|
+
rescue StandardError => err
|
16
|
+
puts "Error opening cache file (#{err})"
|
17
|
+
@cache = Henchman::Templates.cache
|
18
|
+
end
|
19
|
+
@cache[:history].default = DateTime.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def config config
|
23
|
+
@config = config
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_ignore type, identifier
|
27
|
+
return false if !(valid_ignore_type? type)
|
28
|
+
@cache[:ignore][type][identifier] = Time.now.to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
def ignore? type, identifier
|
32
|
+
return false if !(valid_ignore_type? type)
|
33
|
+
@cache[:ignore][type][identifier] >= (Time.now.to_i - @config[:reprompt_timeout])
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_time_last_downloaded track
|
37
|
+
@cache[:history][track[:id].to_i]
|
38
|
+
end
|
39
|
+
|
40
|
+
def tag track
|
41
|
+
@cache[:history][track[:id].to_i] = DateTime.now
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete track
|
45
|
+
@cache[:history].delete track[:id].to_i
|
46
|
+
end
|
47
|
+
|
48
|
+
def flush
|
49
|
+
File.open(@cache_file, "w") { |f| f.write( @cache.to_yaml ) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def valid_ignore_type? type
|
53
|
+
if !(Henchman::Templates.cache[:ignore].keys.include? type)
|
54
|
+
puts "Invalid type '#{type}' for ignore cache check"
|
55
|
+
false
|
56
|
+
else
|
57
|
+
true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/lib/clean.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "applescript"
|
2
|
+
require "cache"
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
module Henchman
|
6
|
+
|
7
|
+
class Clean
|
8
|
+
|
9
|
+
def self.run played_date
|
10
|
+
|
11
|
+
puts "Cleanup ran at #{DateTime.now.strftime('%m-%d-%Y %k:%M:%S%p')}"
|
12
|
+
|
13
|
+
played_date = (played_date == 'true') ? true : false
|
14
|
+
|
15
|
+
@appleScript = Henchman::AppleScript.new
|
16
|
+
@cache = Henchman::Cache.new
|
17
|
+
begin
|
18
|
+
@config = YAML.load_file(File.expand_path('~/.henchman/config'))
|
19
|
+
@cache.config @config
|
20
|
+
@appleScript.setup @config
|
21
|
+
rescue StandardError => err
|
22
|
+
puts "Error opening config file. Try rerunning `henchman configure`"
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
cutoff = DateTime.now - 1
|
27
|
+
|
28
|
+
tracks = @appleScript.get_tracks_with_location
|
29
|
+
tracks.each do |track|
|
30
|
+
cache_time = @cache.get_time_last_downloaded track
|
31
|
+
if track[:date] < cutoff && ((cache_time < cutoff) || played_date)
|
32
|
+
cleanup track
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
@cache.flush
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.cleanup track
|
41
|
+
filepath = track[:path]
|
42
|
+
File.delete filepath
|
43
|
+
@cache.delete track
|
44
|
+
puts "Deleted #{filepath}"
|
45
|
+
|
46
|
+
while File.dirname(filepath) != @config[:root]
|
47
|
+
filepath = File.dirname(filepath)
|
48
|
+
begin
|
49
|
+
Dir.rmdir(filepath)
|
50
|
+
puts "Deleted #{filepath}"
|
51
|
+
rescue SystemCallError => msg
|
52
|
+
break
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/lib/core.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require "dropbox
|
2
|
-
require "applescript
|
1
|
+
require "dropbox"
|
2
|
+
require "applescript"
|
3
|
+
require "cache"
|
3
4
|
require "yaml"
|
4
5
|
|
5
6
|
module Henchman
|
@@ -8,24 +9,14 @@ module Henchman
|
|
8
9
|
|
9
10
|
def self.run
|
10
11
|
@appleScript = Henchman::AppleScript.new
|
11
|
-
|
12
|
-
begin
|
13
|
-
cache_file = File.expand_path("~/.henchman/cache")
|
14
|
-
@ignore = YAML.load_file(cache_file)
|
15
|
-
raise "Incorrectly formatted cache" if !(@ignore.include? :artist)
|
16
|
-
|
17
|
-
@ignore.each_value { |val| val.default = 0 }
|
18
|
-
rescue StandardError => err
|
19
|
-
puts "Error opening cache file (#{err})"
|
20
|
-
@ignore = Henchman::Templates.cache
|
21
|
-
end
|
22
|
-
|
12
|
+
@cache = Henchman::Cache.new
|
23
13
|
threads = []
|
24
14
|
update_cache = false
|
25
15
|
|
26
16
|
while itunes_is_active?
|
27
17
|
begin
|
28
18
|
@config = YAML.load_file(File.expand_path('~/.henchman/config'))
|
19
|
+
@cache.config @config
|
29
20
|
rescue StandardError => err
|
30
21
|
puts "Error opening config file. Try rerunning `henchman configure`"
|
31
22
|
return
|
@@ -42,14 +33,15 @@ module Henchman
|
|
42
33
|
track = @appleScript.get_selection
|
43
34
|
|
44
35
|
if track_selected? track
|
45
|
-
if (missing_track_selected? track) && !(ignore? :artist, track[:artist])
|
36
|
+
if (missing_track_selected? track) && !(@cache.ignore? :artist, track[:artist])
|
46
37
|
update_cache = true
|
47
|
-
update_ignore :artist, track[:artist]
|
38
|
+
@cache.update_ignore :artist, track[:artist]
|
48
39
|
if @appleScript.fetch? "#{track[:album]} by #{track[:artist]}"
|
49
40
|
begin
|
50
41
|
# first download the selected track
|
51
42
|
dropbox_path = @dropbox.search_for track
|
52
43
|
file_save_path = @dropbox.download track, dropbox_path
|
44
|
+
@cache.tag track
|
53
45
|
|
54
46
|
# if we downloaded it, update the location of the track in iTunes
|
55
47
|
unless !file_save_path
|
@@ -57,7 +49,7 @@ module Henchman
|
|
57
49
|
# if the update failed, cleanup that directory and don't bother
|
58
50
|
# doing the rest of the album
|
59
51
|
if !updated
|
60
|
-
cleanup file_save_path
|
52
|
+
cleanup file_save_path, track
|
61
53
|
next
|
62
54
|
end
|
63
55
|
|
@@ -76,9 +68,9 @@ module Henchman
|
|
76
68
|
playlist = @appleScript.get_playlist
|
77
69
|
if playlist
|
78
70
|
playlist_tracks = @appleScript.get_playlist_tracks playlist
|
79
|
-
if (!playlist_tracks.empty?) && !(ignore? :playlist, playlist)
|
71
|
+
if (!playlist_tracks.empty?) && !(@cache.ignore? :playlist, playlist)
|
80
72
|
update_cache = true
|
81
|
-
update_ignore :playlist, playlist
|
73
|
+
@cache.update_ignore :playlist, playlist
|
82
74
|
if @appleScript.fetch? playlist
|
83
75
|
threads << Thread.new{ download_tracks playlist_tracks }
|
84
76
|
end
|
@@ -89,26 +81,7 @@ module Henchman
|
|
89
81
|
end
|
90
82
|
|
91
83
|
threads.each { |thr| thr.join }
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
def self.update_ignore type, identifier
|
96
|
-
return false if !(valid_ignore_type? type)
|
97
|
-
@ignore[type][identifier] = Time.now.to_i
|
98
|
-
end
|
99
|
-
|
100
|
-
def self.ignore? type, identifier
|
101
|
-
return false if !(valid_ignore_type? type)
|
102
|
-
@ignore[type][identifier] >= (Time.now.to_i - @config[:reprompt_timeout])
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.valid_ignore_type? type
|
106
|
-
if !(Henchman::Templates.cache.keys.include? type)
|
107
|
-
puts "Invalid type '#{type}' for ignore cache check"
|
108
|
-
false
|
109
|
-
else
|
110
|
-
true
|
111
|
-
end
|
84
|
+
@cache.flush if update_cache
|
112
85
|
end
|
113
86
|
|
114
87
|
def self.track_selected? track
|
@@ -132,21 +105,23 @@ module Henchman
|
|
132
105
|
# first download the selected track
|
133
106
|
dropbox_path = @dropbox.search_for track
|
134
107
|
file_save_path = @dropbox.download track, dropbox_path
|
108
|
+
@cache.tag track
|
135
109
|
|
136
110
|
# if we downloaded it, update the location of the track in iTunes
|
137
111
|
unless !file_save_path
|
138
112
|
updated = @appleScript.set_track_location track, file_save_path
|
139
113
|
|
140
114
|
# if the update failed, remove that file
|
141
|
-
cleanup file_save_path if !updated
|
115
|
+
cleanup file_save_path, track if !updated
|
142
116
|
end
|
143
117
|
rescue StandardError => err
|
144
118
|
puts err
|
145
119
|
end
|
146
120
|
end
|
147
121
|
|
148
|
-
def self.cleanup file_save_path
|
122
|
+
def self.cleanup file_save_path, track
|
149
123
|
File.delete file_save_path
|
124
|
+
@cache.delete track
|
150
125
|
while File.dirname(file_save_path) != @config[:root]
|
151
126
|
file_save_path = File.dirname(file_save_path)
|
152
127
|
begin
|
data/lib/henchman/version.rb
CHANGED
data/lib/henchman.rb
CHANGED
@@ -2,6 +2,7 @@ require "henchman/version"
|
|
2
2
|
require "configure"
|
3
3
|
require "launchd_handler"
|
4
4
|
require "core"
|
5
|
+
require "clean"
|
5
6
|
require "commander/import"
|
6
7
|
require "yaml"
|
7
8
|
|
@@ -43,5 +44,16 @@ module Henchman
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
47
|
+
command :clean do |c|
|
48
|
+
c.syntax = 'henchman clean [options]'
|
49
|
+
c.description = 'Remove tracks from the file system that are old. '\
|
50
|
+
'Should not be ran manually.'
|
51
|
+
c.option '--played_date \'true\'/\'false\'', String, 'Delete tracks based only on last played date'
|
52
|
+
c.action do |args, options|
|
53
|
+
options.default :played_date => 'false'
|
54
|
+
Henchman::Clean.run options.played_date
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
46
58
|
end
|
47
59
|
end
|
data/lib/launchd_handler.rb
CHANGED
@@ -13,28 +13,39 @@ module Henchman
|
|
13
13
|
return if !Henchman.connect
|
14
14
|
end
|
15
15
|
|
16
|
-
puts "Creating
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
puts "Creating agents"
|
17
|
+
plist_main = Henchman::Templates.plist_main
|
18
|
+
plist_path_main = File.expand_path("~/Library/LaunchAgents/com.henchman.plist")
|
19
|
+
plist_clean = Henchman::Templates.plist_clean
|
20
|
+
plist_path_clean = File.expand_path("~/Library/LaunchAgents/com.henchman.clean.plist")
|
21
|
+
shell_script_path_main = File.expand_path("~/.henchman/run.sh")
|
22
|
+
shell_script_path_clean = File.expand_path("~/.henchman/clean.sh")
|
20
23
|
cache_path = File.expand_path("~/.henchman/cache")
|
21
|
-
File.write(
|
22
|
-
File.write(
|
24
|
+
File.write(plist_path_main, plist_main)
|
25
|
+
File.write(shell_script_path_main, Henchman::Templates.shell_script('run'))
|
26
|
+
File.write(plist_path_clean, plist_clean)
|
27
|
+
File.write(shell_script_path_clean, Henchman::Templates.shell_script('clean'))
|
23
28
|
File.open(cache_path, "w") { |f| f.write( Henchman::Templates.cache.to_yaml ) }
|
24
29
|
|
25
30
|
puts "Launching agent"
|
26
|
-
`chmod +x #{
|
27
|
-
`
|
31
|
+
`chmod +x #{shell_script_path_main}`
|
32
|
+
`chmod +x #{shell_script_path_clean}`
|
33
|
+
`launchctl load #{plist_path_main}`
|
34
|
+
`launchctl load #{plist_path_clean}`
|
28
35
|
|
29
|
-
puts "Launched
|
36
|
+
puts "Launched successfully! You are now running henchman."
|
30
37
|
end
|
31
38
|
|
32
39
|
def self.stop
|
33
40
|
puts "Stopping agents"
|
34
|
-
|
35
|
-
|
36
|
-
`
|
41
|
+
plist_path_main = File.expand_path("~/Library/LaunchAgents/com.henchman.plist")
|
42
|
+
plist_path_clean = File.expand_path("~/Library/LaunchAgents/com.henchman.clean.plist")
|
43
|
+
`launchctl unload #{plist_path_main}`
|
44
|
+
`launchctl unload #{plist_path_clean}`
|
45
|
+
`rm #{plist_path_main}`
|
46
|
+
`rm #{plist_path_clean}`
|
37
47
|
`rm #{File.expand_path("~/.henchman/run.sh")}`
|
48
|
+
`rm #{File.expand_path("~/.henchman/clean.sh")}`
|
38
49
|
`rm #{File.expand_path("~/.henchman/cache")}`
|
39
50
|
`rm #{File.expand_path("~/.henchman/stdout.log")}`
|
40
51
|
`rm #{File.expand_path("~/.henchman/stderr.log")}`
|
data/lib/templates.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Henchman
|
2
2
|
class Templates
|
3
|
-
def self.
|
3
|
+
def self.plist_main
|
4
4
|
config = YAML.load_file(File.expand_path('~/.henchman/config'))
|
5
5
|
|
6
6
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\
|
@@ -24,9 +24,45 @@ module Henchman
|
|
24
24
|
"</plist>"
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.
|
27
|
+
def self.plist_clean
|
28
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\
|
29
|
+
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "\
|
30
|
+
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"\
|
31
|
+
"<plist version=\"1.0\">\n"\
|
32
|
+
"<dict>\n"\
|
33
|
+
"\t<key>Label</key>\n"\
|
34
|
+
"\t<string>henchman_clean</string>\n"\
|
35
|
+
"\t<key>ProgramArguments</key>\n"\
|
36
|
+
"\t<array>\n"\
|
37
|
+
"\t\t<string>#{File.expand_path('~/.henchman/clean.sh')}</string>\n"\
|
38
|
+
"\t</array>\n"\
|
39
|
+
"\t<key>StartCalendarInterval</key>\n"\
|
40
|
+
"\t<array>\n"\
|
41
|
+
"\t<!-- Run twice a day. At 12:00 AM and at 12:00 PM -->\n"\
|
42
|
+
"\t\t<dict>\n"\
|
43
|
+
"\t\t\t<key>Hour</key>\n"\
|
44
|
+
"\t\t\t<integer>00</integer>\n"\
|
45
|
+
"\t\t\t<key>Minute</key>\n"\
|
46
|
+
"\t\t\t<integer>00</integer>\n"\
|
47
|
+
"\t\t</dict>\n"\
|
48
|
+
"\t\t<dict>\n"\
|
49
|
+
"\t\t\t<key>Hour</key>\n"\
|
50
|
+
"\t\t\t<integer>12</integer>\n"\
|
51
|
+
"\t\t\t<key>Minute</key>\n"\
|
52
|
+
"\t\t\t<integer>00</integer>\n"\
|
53
|
+
"\t\t</dict>\n"\
|
54
|
+
"\t</array>\n"\
|
55
|
+
"\t<key>StandardOutPath</key>\n"\
|
56
|
+
"\t<string>#{File.expand_path('~/.henchman/stdout.log')}</string>\n"\
|
57
|
+
"\t<key>StandardErrorPath</key>\n"\
|
58
|
+
"\t<string>#{File.expand_path('~/.henchman/stderr.log')}</string>\n"\
|
59
|
+
"</dict>\n"\
|
60
|
+
"</plist>"
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.shell_script command
|
28
64
|
"#!/bin/sh\n"\
|
29
|
-
"#{`which henchman`.chomp}
|
65
|
+
"#{`which henchman`.chomp} #{command}"
|
30
66
|
end
|
31
67
|
|
32
68
|
def self.config
|
@@ -46,8 +82,11 @@ module Henchman
|
|
46
82
|
|
47
83
|
def self.cache
|
48
84
|
{
|
49
|
-
:
|
50
|
-
|
85
|
+
:ignore => {
|
86
|
+
:artist => Hash.new(0),
|
87
|
+
:playlist => Hash.new(0)
|
88
|
+
},
|
89
|
+
:history => Hash.new
|
51
90
|
}
|
52
91
|
end
|
53
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: henchman-sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Merritt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -100,6 +100,8 @@ files:
|
|
100
100
|
- exe/henchman
|
101
101
|
- henchman.gemspec
|
102
102
|
- lib/applescript.rb
|
103
|
+
- lib/cache.rb
|
104
|
+
- lib/clean.rb
|
103
105
|
- lib/configure.rb
|
104
106
|
- lib/core.rb
|
105
107
|
- lib/dropbox.rb
|