|
3 | 3 |
|
4 | 4 | require 'pp' |
5 | 5 | require 'yaml' |
| 6 | +# require 'open3' |
6 | 7 |
|
7 | 8 | # Add new books to this array, as necessary |
8 | 9 | @books = ['docs-book-cloudfoundry', 'docs-book-pcfservices', 'docs-book-pivotalcf', 'docs-book-runpivotal'] |
9 | 10 | @modified_repos = [] |
10 | 11 | @repo_list = ["docs-layout-repo", "docs-utility-scripts"] |
11 | 12 |
|
12 | | -# Create a list of the book repositories to be cloned_or_updated, and send them to cloner/updater. |
| 13 | +# Create a list of the book repositories to be cloned_or_updated, send them to cloner/updater, and display the ignored modified repos. |
13 | 14 | def gather_repos(books) |
14 | 15 | books.map do |book| |
15 | 16 | YAML.load(File.open(Dir.home + '/workspace/' + book + '/config.yml'))['sections'].each do |section| |
16 | 17 | @repo_list.push(section['repository']['name']) |
17 | 18 | end |
18 | 19 | end |
19 | 20 | reduced_list = reduce_list_for_current_work @repo_list |
20 | | - clone_or_update reduced_list.uniq |
| 21 | + multithread_pipe reduced_list.uniq |
| 22 | + # clone_or_update reduced_list.uniq |
21 | 23 | display_modified_repos @modified_repos |
22 | 24 | end |
23 | 25 |
|
24 | 26 | # Removes repos with changes from @repo_list |
25 | 27 | def reduce_list_for_current_work(working_repos_array) |
26 | 28 | working_repos_array.reject! do |repo| |
27 | | - repo && @modified_repos.push(repo) if `cd ~/workspace/#{repo.gsub(/\w*-?\w*\//,'')}; git status`.include?('modified') |
| 29 | + repo && @modified_repos.push(repo) if File.directory?(Dir.home + '/workspace/' + repo.gsub(/\w*-?\w*\//,'')) && `cd ~/workspace/#{repo.gsub(/\w*-?\w*\//,'')}; git status`.include?('modified') |
28 | 30 | end |
29 | 31 | working_repos_array.compact.uniq |
30 | 32 | end |
31 | 33 |
|
| 34 | +def multithread_pipe(list_of_repos) |
| 35 | + threads = [] |
| 36 | + list_of_repos.each do |repo| |
| 37 | + threads << Thread.new { clone_or_update repo} |
| 38 | + end |
| 39 | + threads.each{|t|t.join} |
| 40 | +end |
| 41 | + |
32 | 42 | # Ternary operation that checks for directory existence, if none, clones; otherwise updates repo |
33 | | -def clone_or_update(repo_list) |
34 | | - repo_list.each do |repo| |
| 43 | +def clone_or_update(repo) |
35 | 44 | File.directory?(Dir.home + '/workspace/' + repo.gsub(/\w*-?\w*\//,'')) ? update_repo(repo) : clone_repo(repo) |
36 | | - end |
37 | 45 | end |
38 | 46 |
|
39 | 47 | # Displays repos with modifications |
|
0 commit comments