Module: GitMedia::Sync

Defined in:
lib/git-media/sync.rb

Class Method Summary collapse

Class Method Details

.expand_referencesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/git-media/sync.rb', line 16

def self.expand_references
  status = GitMedia::Status.find_references
  status[:to_expand].each do |file, sha|
    cache_file = GitMedia.media_path(sha)
    if !File.exist?(cache_file)
      puts "Downloading " + sha[0,8] + " : " + file
      @pull.pull(file, sha) 
    end

    puts "Expanding  " + sha[0,8] + " : " + file
    
    if File.exist?(cache_file)
      FileUtils.cp(cache_file, file)
    else
      puts 'could not get media'
    end
  end
end

.run!Object



8
9
10
11
12
13
14
# File 'lib/git-media/sync.rb', line 8

def self.run!
  @push = GitMedia.get_push_transport
  @pull = GitMedia.get_pull_transport
  
  self.expand_references
  self.upload_local_cache
end

.upload_local_cacheObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/git-media/sync.rb', line 35

def self.upload_local_cache
  # find files in media buffer and upload them
  all_cache = Dir.chdir(GitMedia.get_media_buffer) { Dir.glob('*') }
  unpushed_files = @push.get_unpushed(all_cache)
  unpushed_files.each do |sha|
    puts 'uploading ' + sha[0, 8]
    @push.push(sha)
  end
  # TODO: if --clean, remove them
end