Class: CodeRunner::RepositoryManager
- Defined in:
- lib/coderunner/repository_manager.rb
Overview
A class for managing a coderunner repository, which consists of a managed set of simulation folders and defaults files which are synchronised across systems using git.
Class Method Summary collapse
- .add_folder(folder, copts) ⇒ Object
- .add_remote(name, url, copts) ⇒ Object
- .bare_repo_command(comm, copts) ⇒ Object
- .clone_repo(url, name, copts) ⇒ Object
- .init_repository(name, copts) ⇒ Object
- .list_remotes(copts) ⇒ Object
- .pull_repository(copts) ⇒ Object
- .push_and_create_repository(copts) ⇒ Object
- .push_repository(copts) ⇒ Object
- .remote_synchronize_down(remote, folder, copts) ⇒ Object
- .remote_synchronize_up(remote, folder, copts) ⇒ Object
-
.setup(copts) ⇒ Object
This function gets called before every command and allows arbitrary manipulation of the command options (copts) hash.
- .try_system(str) ⇒ Object
- .verbosity ⇒ Object
Class Method Details
.add_folder(folder, copts) ⇒ Object
201 202 203 204 |
# File 'lib/coderunner/repository_manager.rb', line 201 def add_folder(folder, copts) repo = Repository.open_in_subfolder(folder) repo.add_folder(folder) end |
.add_remote(name, url, copts) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/coderunner/repository_manager.rb', line 131 def add_remote(name, url, copts) url =~ Repository.url_regex = $~[:folder] unless =~ Repository. raise "Remotes must end in .cr.git for coderunnerrepo" end Dir.chdir(copts[:Y]){ repo = Repository.open_in_subfolder(Dir.pwd) repo..add_remote(name, url) } end |
.bare_repo_command(comm, copts) ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/coderunner/repository_manager.rb', line 120 def (comm, copts) Dir.chdir(copts[:Y]) do repo = Repository.open_in_subfolder(Dir.pwd) Dir.chdir(repo..repo.to_s) do system comm end end end |
.clone_repo(url, name, copts) ⇒ Object
214 215 216 217 218 |
# File 'lib/coderunner/repository_manager.rb', line 214 def clone_repo(url, name, copts) Dir.chdir(copts[:Y]){ Repository.clone(url, name) } end |
.init_repository(name, copts) ⇒ Object
128 129 130 |
# File 'lib/coderunner/repository_manager.rb', line 128 def init_repository(name, copts) Repository.init(name) end |
.list_remotes(copts) ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/coderunner/repository_manager.rb', line 168 def list_remotes(copts) Dir.chdir(copts[:Y]){ repo = Repository.open_in_subfolder(Dir.pwd) repo..remotes.each do |r| puts "#{r.name} #{r.url}" end } end |
.pull_repository(copts) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/coderunner/repository_manager.rb', line 190 def pull_repository(copts) Dir.chdir(copts[:Y]){ repo = Repository.open_in_subfolder(Dir.pwd) if copts[:r] rems = copts[:r].split(/,/).map{|rname| repo..remote(rname)} else rems = repo..remotes end rems.each{|r| repo.pull(r)} } end |
.push_and_create_repository(copts) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/coderunner/repository_manager.rb', line 146 def push_and_create_repository(copts) Dir.chdir(copts[:Y]){ repo = Repository.open_in_subfolder(Dir.pwd) = repo. if copts[:r] rems = copts[:r].split(/,/).map{|rname| .remote(rname)} else raise "Must specify remotes using the -r flag when calling push_and_create_repository" end repo.simple_push(repo.remote("origin")) rems.each do |r| namehost, folder, = repo.split_url(r.name) try_system %[ssh #{namehost} "mkdir -p #{} && cd #{} && git init --bare"] .push(r) try_system %[ssh #{namehost} "git clone #{} #{folder}"] .remotes.each do |other_remote| next if other_remote.name == r.name try_system %[ssh #{namehost} "cd #{} && git remote add #{other_remote.name} #{other_remote.url}"] end end } end |
.push_repository(copts) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/coderunner/repository_manager.rb', line 176 def push_repository(copts) Dir.chdir(copts[:Y]){ puts 'opening repo' repo = Repository.open_in_subfolder(Dir.pwd) if copts[:r] puts 'mapping' rems = copts[:r].split(/,/).map{|rname| repo..remote(rname)} else rems = repo..remotes end puts 'pusing' rems.each{|r| repo.push(r)} } end |
.remote_synchronize_down(remote, folder, copts) ⇒ Object
205 206 207 208 |
# File 'lib/coderunner/repository_manager.rb', line 205 def remote_synchronize_down(remote, folder, copts) repo = Repository.open_in_subfolder(folder) repo.rsyncd(remote, folder) end |
.remote_synchronize_up(remote, folder, copts) ⇒ Object
209 210 211 212 |
# File 'lib/coderunner/repository_manager.rb', line 209 def remote_synchronize_up(remote, folder, copts) repo = Repository.open_in_subfolder(folder) repo.rsyncu(remote, folder) end |
.setup(copts) ⇒ Object
This function gets called before every command and allows arbitrary manipulation of the command options (copts) hash
113 114 115 116 |
# File 'lib/coderunner/repository_manager.rb', line 113 def setup(copts) copts[:Y] ||= Dir.pwd copts[:Y] = File.(copts[:Y]) end |
.try_system(str) ⇒ Object
142 143 144 145 |
# File 'lib/coderunner/repository_manager.rb', line 142 def try_system(str) puts str raise "Failed command: #{str}" unless system str end |
.verbosity ⇒ Object
117 118 119 |
# File 'lib/coderunner/repository_manager.rb', line 117 def verbosity 2 end |