Module: Sync

Extended by:
Sync
Included in:
Sync
Defined in:
lib/commands/sync.rb

Instance Method Summary collapse

Instance Method Details

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/commands/sync.rb', line 5

def run()
  ARGV.reject { |x| x.start_with?("-") }
  project_name = ARGV.shift || $settings.project_name

  unless project_name
    Enzyme.error("No project name specified. Ensure you're in the project's directory or set it specifically. Run `enzyme help sync` for help.")
    return
  end

  unless $settings.sync.share_name
    Enzyme.error("The `sync.share_name` setting is not set. Set it using `enzyme config sync.share_name \"Share Name\"`.")
    return
  end

  unless $settings.sync.host
    Enzyme.error("The `sync.host` setting is not set. Set it using `enzyme config sync.host \"Host._afpovertcp._tcp.local\"`.")
    return
  end

  unless $settings.sync.projects_directory
    Enzyme.error("The `sync.projects_directory` setting is not set. Set it using `enzyme config sync.projects_directory \"My Projects Directory\"`.")
    return
  end

  unless $settings.sync.protected_directory
    Enzyme.error("The `sync.protected_directory` setting is not set. Set it using `enzyme config sync.protected_directory \"my_directory\"`.")
    return
  end

  unless $settings.sync.shared_directory
    Enzyme.error("The `sync.shared_directory` setting is not set. Set it using `enzyme config sync.shared_directory \"our_shared_directory\"`.")
    return
  end

  # Mount the network volume. Only works on OS X.
  system "mkdir \"/Volumes/#{$settings.sync.share_name}\""
  system "mount -t afp \"afp://#{$settings.sync.host}/#{$settings.sync.share_name}\" \"/Volumes/#{$settings.sync.share_name}\""
  system "mkdir \"/Volumes/#{$settings.sync.share_name}/#{$settings.sync.projects_directory}/#{project_name}\""
  # Pull.
  system "rsync -aH --stats -v -u --progress --exclude '#{$settings.sync.protected_directory}/**' \"/Volumes/#{$settings.sync.share_name}/#{$settings.sync.projects_directory}/#{project_name}/\" '#{$settings.projects_directory}/#{project_name}/resources/'"
  # Push.
  system "rsync -aH --stats -v -u --progress --include '*/' --include '#{$settings.sync.shared_directory}/**' --include '#{$settings.sync.protected_directory}/**' --exclude '*' '#{$settings.projects_directory}/#{project_name}/resources/' \"/Volumes/#{$settings.sync.share_name}/#{$settings.sync.projects_directory}/#{project_name}/\""
end