Class: Smug::StatusCommand

Inherits:
Command
  • Object
show all
Includes:
Utils
Defined in:
lib/smugsync/status.rb

Constant Summary collapse

ALBUM_STATUS_FORMAT =
"%20s\t%s/(%s files)"
IMAGE_STATUS_FORMAT =
"%20s\t%s/%s"

Instance Method Summary collapse

Methods included from Utils

#method_missing, #status_message

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Smug::Utils

Instance Method Details

#album_status(options = { :local => nil, :remote => nil }) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/smugsync/status.rb', line 62

def album_status(options = { :local => nil, :remote => nil })
    local = options[:local]
    remote = options[:remote]

    if !local and !remote
        raise "album_status: requires either local or remote album"
    elsif local and !remote
        {
            :album => local,
            :status => :not_uploaded,
            :images => local_images(local).map { |img| { :image => img, :status => :not_uploaded} }
        }
    elsif !local and remote
        {
            :album => remote["Title"],
            :status => :not_downloaded,
            :images => remote_images(remote).map { |img| { :image => img, :status => :not_downloaded} }
        }
    else
        # TODO: assure that local and remote titles are the same
        # TODO: document case insensitivity
        not_uploaded = local_images(local) - remote_images(remote)
        not_downloaded = remote_images(remote) - local_images(local)

        {
            :album => remote["Title"],
            :status => :not_modified,
            :images => not_uploaded.map { |img| { :image => img, :status => :not_uploaded} } + not_downloaded.map { |img| { :image => img, :status => :not_downloaded} }
        }
    end
end

#albums_statusObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/smugsync/status.rb', line 43

def albums_status
    status = []

    local_albums = Pathname::pwd.children(false).find_all { |a| a.directory? and a.basename.to_s != ".smug" }.map { |a| a.basename.to_s }
    remote_albums = albums.map { |a| a["Title"] }

    status += albums.map do |album|
        album_status(
            :remote => album,
            :local => local_albums.find { |a| a == album["Title"] }
        )
    end
    status += (local_albums - remote_albums).map do |local_album|
        album_status(:remote => nil, :local => local_album)
    end

    status
end

#current_dir_statusObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/smugsync/status.rb', line 28

def current_dir_status
    current_dir = Config::relative_to_root(Dir.pwd).to_s
    if current_dir == '.'
        albums_status
    else
        Dir::chdir('..')
        status = [album_status(
            :local => current_dir,
            :remote => albums.find { |a| a["Title"] == current_dir }
        )]
        Dir::chdir(current_dir)
        status
    end
end

#execObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/smugsync/status.rb', line 11

def exec
    authenticate

    # TODO: support categories and nested categories
    # for now comparison supports only flat list of albums
    status = current_dir_status
    status.each do |album_status|
        if album_status[:status] != :not_modified
            puts sprintf(ALBUM_STATUS_FORMAT, album_status[:status], album_status[:album], album_status[:images].length)
        else
            album_status[:images].each do |image_status|
                puts sprintf(IMAGE_STATUS_FORMAT, image_status[:status], album_status[:album], image_status[:image])
            end
        end
    end
end