| |   |
| 89 | 89 | end |
| 90 | 90 | |
| 91 | 91 | def commit_graph_tag(repository, ref = "master") |
| 92 | | filename = "#{repository.project.slug}_#{repository.name}_#{h(ref)}_commit_count.png" |
| 92 | filename = Gitorious::Graphs::CommitsBuilder.filename(repository, ref) |
| 93 | 93 | if File.exist?(File.join(Gitorious::Graphs::Builder.graph_dir, filename)) |
| 94 | 94 | image_tag("graphs/#{filename}") |
| 95 | 95 | end |
| 96 | 96 | end |
| 97 | 97 | |
| 98 | 98 | def commit_graph_by_author_tag(repository, ref = "master") |
| 99 | | filename = "#{repository.project.slug}_#{repository.name}_#{h(ref)}_commit_count_by_author.png" |
| 99 | filename = Gitorious::Graphs::CommitsByAuthorBuilder.filename(repository, ref) |
| 100 | 100 | if File.exist?(File.join(Gitorious::Graphs::Builder.graph_dir, filename)) |
| 101 | 101 | image_tag("graphs/#{filename}") |
| 102 | 102 | end |
| toggle raw diff |
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -89,14 +89,14 @@ module ApplicationHelper
end
def commit_graph_tag(repository, ref = "master")
- filename = "#{repository.project.slug}_#{repository.name}_#{h(ref)}_commit_count.png"
+ filename = Gitorious::Graphs::CommitsBuilder.filename(repository, ref)
if File.exist?(File.join(Gitorious::Graphs::Builder.graph_dir, filename))
image_tag("graphs/#{filename}")
end
end
def commit_graph_by_author_tag(repository, ref = "master")
- filename = "#{repository.project.slug}_#{repository.name}_#{h(ref)}_commit_count_by_author.png"
+ filename = Gitorious::Graphs::CommitsByAuthorBuilder.filename(repository, ref)
if File.exist?(File.join(Gitorious::Graphs::Builder.graph_dir, filename))
image_tag("graphs/#{filename}")
end |
| |   |
| 6 | 6 | |
| 7 | 7 | module Gitorious |
| 8 | 8 | module Graphs |
| 9 | | class Builder |
| 9 | class Builder |
| 10 | GENERATORS = [CommitsBuilder, CommitsByAuthorBuilder] |
| 10 | 11 | def self.generate_all_for(repository) |
| 11 | | CommitsBuilder.generate_for(repository) |
| 12 | | CommitsByAuthorBuilder.generate_for(repository) |
| 12 | GENERATORS.each do |generator| |
| 13 | generator.generate_for(repository) |
| 14 | end |
| 13 | 15 | end |
| 14 | 16 | |
| 15 | 17 | def self.graph_dir |
| 16 | 18 | File.join(RAILS_ROOT, "public/images/graphs/") |
| 17 | 19 | end |
| 20 | |
| 21 | def self.construct_filename(repository, branch, name) |
| 22 | "#{repository.project.slug}_#{repository.name}_#{branch}_#{name}.png" |
| 23 | end |
| 24 | |
| 25 | def self.status_file(repository, branch = "master") |
| 26 | File.join(RAILS_ROOT, "tmp", "graph_generator", |
| 27 | "#{repository.project.slug}_#{repository.name}_#{repository.git.commit_count(branch)}_#{self.name}.status") |
| 28 | end |
| 18 | 29 | |
| 19 | 30 | def self.default_theme |
| 20 | 31 | { |
| toggle raw diff |
--- a/lib/gitorious/graphs/builder.rb
+++ b/lib/gitorious/graphs/builder.rb
@@ -6,15 +6,26 @@ end
module Gitorious
module Graphs
- class Builder
+ class Builder
+ GENERATORS = [CommitsBuilder, CommitsByAuthorBuilder]
def self.generate_all_for(repository)
- CommitsBuilder.generate_for(repository)
- CommitsByAuthorBuilder.generate_for(repository)
+ GENERATORS.each do |generator|
+ generator.generate_for(repository)
+ end
end
def self.graph_dir
File.join(RAILS_ROOT, "public/images/graphs/")
end
+
+ def self.construct_filename(repository, branch, name)
+ "#{repository.project.slug}_#{repository.name}_#{branch}_#{name}.png"
+ end
+
+ def self.status_file(repository, branch = "master")
+ File.join(RAILS_ROOT, "tmp", "graph_generator",
+ "#{repository.project.slug}_#{repository.name}_#{repository.git.commit_count(branch)}_#{self.name}.status")
+ end
def self.default_theme
{ |
| |   |
| 3 | 3 | |
| 4 | 4 | class CommitsBuilder < Gitorious::Graphs::Builder |
| 5 | 5 | def self.generate_for(repository) |
| 6 | | if repository.has_commits? |
| 7 | | builder = new(repository, repository.head_candidate.name) |
| 6 | head = repository.head_candidate |
| 7 | return if head.nil? |
| 8 | |
| 9 | branch = head.name |
| 10 | if !File.exist?(self.status_file(repository, branch)) && repository.has_commits? |
| 11 | builder = new(repository, branch) |
| 8 | 12 | builder.build |
| 9 | 13 | builder.write |
| 14 | FileUtils.touch(self.status_file(repository, branch)) |
| 10 | 15 | end |
| 11 | 16 | end |
| 12 | 17 | |
| … | … | |
| 38 | 38 | @graph.labels = build_labels(week_numbers) |
| 39 | 39 | end |
| 40 | 40 | |
| 41 | def self.filename(repository, branch) |
| 42 | Builder.construct_filename(repository, branch, "commit_count") |
| 43 | end |
| 44 | |
| 41 | 45 | def construct_filename |
| 42 | | "#{@repository.project.slug}_#{@repository.name}_#{@branch}_commit_count.png" |
| 46 | CommitsBuilder.filename(@repository, @branch) |
| 43 | 47 | end |
| 44 | 48 | |
| 45 | 49 | private |
| toggle raw diff |
--- a/lib/gitorious/graphs/commits_builder.rb
+++ b/lib/gitorious/graphs/commits_builder.rb
@@ -3,10 +3,15 @@ module Gitorious
class CommitsBuilder < Gitorious::Graphs::Builder
def self.generate_for(repository)
- if repository.has_commits?
- builder = new(repository, repository.head_candidate.name)
+ head = repository.head_candidate
+ return if head.nil?
+
+ branch = head.name
+ if !File.exist?(self.status_file(repository, branch)) && repository.has_commits?
+ builder = new(repository, branch)
builder.build
builder.write
+ FileUtils.touch(self.status_file(repository, branch))
end
end
@@ -33,8 +38,12 @@ module Gitorious
@graph.labels = build_labels(week_numbers)
end
+ def self.filename(repository, branch)
+ Builder.construct_filename(repository, branch, "commit_count")
+ end
+
def construct_filename
- "#{@repository.project.slug}_#{@repository.name}_#{@branch}_commit_count.png"
+ CommitsBuilder.filename(@repository, @branch)
end
private |
| |   |
| 5 | 5 | def self.generate_for(repository) |
| 6 | 6 | if repository.has_commits? |
| 7 | 7 | repository.git.heads.each do |head| |
| 8 | | builder = new(repository, head.name) |
| 9 | | builder.build |
| 10 | | builder.write |
| 8 | branch = head.name |
| 9 | if !File.exist?(self.status_file(repository, branch)) |
| 10 | builder = new(repository, branch) |
| 11 | builder.build |
| 12 | builder.write |
| 13 | FileUtils.touch(self.status_file(repository, branch)) |
| 14 | end |
| 11 | 15 | end |
| 12 | 16 | end |
| 13 | 17 | end |
| … | … | |
| 35 | 35 | end |
| 36 | 36 | end |
| 37 | 37 | |
| 38 | def self.filename(repository, branch) |
| 39 | Builder.construct_filename(repository, branch, "commit_count_by_author") |
| 40 | end |
| 41 | |
| 38 | 42 | def construct_filename |
| 39 | | "#{@repository.project.slug}_#{@repository.name}_#{@branch}_commit_count_by_author.png" |
| 43 | CommitsByAuthorBuilder.filename(@repository, @branch) |
| 40 | 44 | end |
| 41 | 45 | end |
| 42 | 46 | |
| toggle raw diff |
--- a/lib/gitorious/graphs/commits_by_author_builder.rb
+++ b/lib/gitorious/graphs/commits_by_author_builder.rb
@@ -5,9 +5,13 @@ module Gitorious
def self.generate_for(repository)
if repository.has_commits?
repository.git.heads.each do |head|
- builder = new(repository, head.name)
- builder.build
- builder.write
+ branch = head.name
+ if !File.exist?(self.status_file(repository, branch))
+ builder = new(repository, branch)
+ builder.build
+ builder.write
+ FileUtils.touch(self.status_file(repository, branch))
+ end
end
end
end
@@ -31,8 +35,12 @@ module Gitorious
end
end
+ def self.filename(repository, branch)
+ Builder.construct_filename(repository, branch, "commit_count_by_author")
+ end
+
def construct_filename
- "#{@repository.project.slug}_#{@repository.name}_#{@branch}_commit_count_by_author.png"
+ CommitsByAuthorBuilder.filename(@repository, @branch)
end
end
|
| |   |
| 1 | 1 | #!/usr/bin/env ruby |
| 2 | 2 | |
| 3 | require 'tmpdir' |
| 4 | require "fileutils" |
| 5 | |
| 6 | LOCK_FILE_PATH = File.join(Dir.tmpdir, "gitorious_graphgenerator_lockfile") |
| 7 | if File.exist?(LOCK_FILE_PATH) |
| 8 | $stderr.puts "Lockfile '#{LOCK_FILE_PATH}' exists!" |
| 9 | exit(1) |
| 10 | end |
| 11 | |
| 12 | FileUtils.touch(LOCK_FILE_PATH) |
| 13 | |
| 3 | 14 | ENV["RAILS_ENV"] ||= "production" |
| 4 | 15 | require File.dirname(__FILE__) + "/../config/environment" |
| 5 | 16 | |
| … | … | |
| 19 | 19 | log.level = Logger::INFO |
| 20 | 20 | log.formatter.datetime_format = "%Y-%m-%d %H:%M:%S" |
| 21 | 21 | |
| 22 | STATUS_FILE = File.join(RAILS_ROOT, "tmp", "graph_generator.status") |
| 23 | update_status = !File.exist?(STATUS_FILE) |
| 24 | tmpdir = File.join(RAILS_ROOT, "tmp", "graph_generator") |
| 25 | if !File.directory?(tmpdir) |
| 26 | FileUtils.mkdir_p(tmpdir) |
| 27 | elsif !update_status |
| 28 | mtime = File.mtime(STATUS_FILE).utc |
| 29 | |
| 30 | days = (Time.now.utc - mtime) / (3600*24) |
| 31 | if days >= 5 |
| 32 | log.info "Cleaning '#{tmpdir}'..." |
| 33 | Dir.glob(File.join(tmpdir, "*.status")) do |file| |
| 34 | FileUtils.rm(file) |
| 35 | end |
| 36 | |
| 37 | update_status = true |
| 38 | end |
| 39 | end |
| 40 | |
| 41 | if update_status |
| 42 | FileUtils.touch(STATUS_FILE) |
| 43 | end |
| 44 | |
| 22 | 45 | log.info "Starting graph generation run..." |
| 23 | 46 | Repository.find(:all).each_with_index do |repository, index| |
| 24 | 47 | begin |
| … | … | |
| 59 | 59 | # exit(1) |
| 60 | 60 | end |
| 61 | 61 | end |
| 62 | | log.info "Done with graph generation run" |
| 62 | log.info "Done with graph generation run" |
| 63 | |
| 64 | FileUtils.rm(LOCK_FILE_PATH) |
| toggle raw diff |
--- a/script/graph_generator
+++ b/script/graph_generator
@@ -1,5 +1,16 @@
#!/usr/bin/env ruby
+require 'tmpdir'
+require "fileutils"
+
+LOCK_FILE_PATH = File.join(Dir.tmpdir, "gitorious_graphgenerator_lockfile")
+if File.exist?(LOCK_FILE_PATH)
+ $stderr.puts "Lockfile '#{LOCK_FILE_PATH}' exists!"
+ exit(1)
+end
+
+FileUtils.touch(LOCK_FILE_PATH)
+
ENV["RAILS_ENV"] ||= "production"
require File.dirname(__FILE__) + "/../config/environment"
@@ -8,6 +19,29 @@ log.formatter = Logger::Formatter.new
log.level = Logger::INFO
log.formatter.datetime_format = "%Y-%m-%d %H:%M:%S"
+STATUS_FILE = File.join(RAILS_ROOT, "tmp", "graph_generator.status")
+update_status = !File.exist?(STATUS_FILE)
+tmpdir = File.join(RAILS_ROOT, "tmp", "graph_generator")
+if !File.directory?(tmpdir)
+ FileUtils.mkdir_p(tmpdir)
+elsif !update_status
+ mtime = File.mtime(STATUS_FILE).utc
+
+ days = (Time.now.utc - mtime) / (3600*24)
+ if days >= 5
+ log.info "Cleaning '#{tmpdir}'..."
+ Dir.glob(File.join(tmpdir, "*.status")) do |file|
+ FileUtils.rm(file)
+ end
+
+ update_status = true
+ end
+end
+
+if update_status
+ FileUtils.touch(STATUS_FILE)
+end
+
log.info "Starting graph generation run..."
Repository.find(:all).each_with_index do |repository, index|
begin
@@ -25,4 +59,6 @@ Repository.find(:all).each_with_index do |repository, index|
# exit(1)
end
end
-log.info "Done with graph generation run"
\ No newline at end of file
+log.info "Done with graph generation run"
+
+FileUtils.rm(LOCK_FILE_PATH) |