Class: Picasaweb::CLI
- Inherits:
-
Object
- Object
- Picasaweb::CLI
- Defined in:
- lib/picasaweb-backup.rb
Constant Summary collapse
- ALBUM_DIR =
"Albums"
Instance Method Summary collapse
- #download_album(client, album) ⇒ Object
- #ensure_exists(dir) ⇒ Object
-
#initialize(opts) ⇒ CLI
constructor
A new instance of CLI.
- #print(msg) ⇒ Object
- #start_backup ⇒ Object
Constructor Details
#initialize(opts) ⇒ CLI
Returns a new instance of CLI.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/picasaweb-backup.rb', line 99 def initialize opts @opts = opts @client = Client.new if opts[:dir] Dir.chdir opts[:dir] self.print "Changing working directory to #{opts[:dir]}" end if @opts[:log] @logger = Logger.new "picasaweb-backup.log", shift_age = "monthly" end end |
Instance Method Details
#download_album(client, album) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/picasaweb-backup.rb', line 129 def download_album(client, album) Dir.chdir album[:title] do self.print "Checking for new photos in '#{album[:title]}'" photos = nil until photos photos = client.get_photos(album) end downloaded_photos = 0 photos.each do |photo| if !File.exists? photo[:title] self.print " ==> #{photo[:title]}" client.download(photo) downloaded_photos += 1 end end if downloaded_photos == 0 self.print "==> no new photos found" end end end |
#ensure_exists(dir) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/picasaweb-backup.rb', line 122 def ensure_exists(dir) if !File.directory? dir Dir.mkdir dir self.print "Creating directory '#{dir}'" end end |
#print(msg) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/picasaweb-backup.rb', line 114 def print msg if @logger @logger.info msg else puts msg end end |
#start_backup ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/picasaweb-backup.rb', line 151 def start_backup albums = @client.get_albums.select do |album| album[:title].downcase != "auto backup" end ensure_exists(ALBUM_DIR) Dir.chdir ALBUM_DIR albums.each do |album| ensure_exists album[:title] download_album(@client, album) end end |