Class: RightPublish::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/right_publish/repo.rb

Direct Known Subclasses

AptRepo, GemRepo, MsiRepo, YumRepo

Constant Summary collapse

LOCK_FILE_NAME =
'lock.txt'
LOCK_PERIOD =

30 minutes

30 * 60
LOCK_RETRY_INTERVAL =

1 minute

1 * 60

Instance Method Summary collapse

Constructor Details

#initialize(option_key) ⇒ Repo

Returns a new instance of Repo.



41
42
43
# File 'lib/right_publish/repo.rb', line 41

def initialize(option_key)
  @repository_type ||= option_key
end

Instance Method Details

#add(file_or_dir, targe) ⇒ Object

Add a new package to local storage and reindex if necessary

Raises:

  • (NotImplementedError)


107
108
109
# File 'lib/right_publish/repo.rb', line 107

def add(file_or_dir, targe)
  raise NotImplementedError, "Subclass responsibility"
end

#annotate(options = {}) ⇒ Object

Create an index.html file to enable browsing of this repo’s subdir.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :subdir (String)

    a subdirectory (common prefix); only files matching this prefix will be included

  • :filter (Array)

    a whitelist of String glob patterns to filter files, i.e. [“*.rpm”, “*.deb”]



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/right_publish/repo.rb', line 72

def annotate(options={})
  Profile.log("Creating HTML directory listing for #{repo_human_name} files...")

  options[:subdir] ||= repo_config[:subdir]

  files = []
  RightPublish::Storage.ls(local_storage, :subdir => options[:subdir]) do |file|
    files << file
  end

  # Build merged options hash for annotation, based on profile config plus some options
  # passed into our class.
  html_options     = Profile.config[:annotation] ? Profile.config[:annotation].dup : {}
  html_options[:filter] = options[:filter] if options.key?(:filter)

  strip            = options[:subdir].split('/').size
  html             = RightPublish::Annotation.generate_html(files, strip, html_options)

  output    = File.join(repo_config[:subdir], 'index.html')
  local_dir = local_storage.get_directories
  local_dir.files.create(:key => output, :body => html)
end

#publish(file_or_dir, target) ⇒ Object

Perform one-shot publish of one or more packages. “One-shot” means: pull, add, annotate and push.



97
98
99
100
101
102
103
104
# File 'lib/right_publish/repo.rb', line 97

def publish(file_or_dir, target)
  lock do
    pull
    add(file_or_dir, target)
    annotate
    push
  end
end

#pullObject

Sync files from remote to local storage



46
47
48
49
50
51
52
53
54
55
# File 'lib/right_publish/repo.rb', line 46

def pull()
  Profile.log("Fetching #{repo_human_name} files from remote...")

  begin
    sync_dirs(remote_storage, local_storage, repo_config[:subdir])
  rescue Exception => e
    RightPublish::Profile.log("Could not synchronize storage:\n\t#{e}", :error)
    raise RuntimeError, "pull from remote failed."
  end
end

#pushObject

Sync files from local to remote storage



58
59
60
61
62
63
64
65
66
67
# File 'lib/right_publish/repo.rb', line 58

def push()
  Profile.log("Committing local #{repo_human_name} files to remote...")

  begin
    sync_dirs(local_storage, remote_storage, repo_config[:subdir])
  rescue Exception => e
    RightPublish::Profile.log("Could not sychronize storage:\n\t#{e}", :error)
    raise RuntimeError, "push to remote failed."
  end
end