Commit 414eebbf69eefc4da86b9e74e00b3064e5e5c463

Thomas de Grivel 2023-02-25T23:11:54

rbpkg_ci

diff --git a/bin/rbpkg b/bin/rbpkg
index a0936a4..978f572 100755
--- a/bin/rbpkg
+++ b/bin/rbpkg
@@ -23,7 +23,7 @@ when "-qq"
   shift
 end
 
-Rbpkg.init("rbpkg", verbose_level, Rbpkg.log_dir)
+Rbpkg.init("rbpkg", verbose_level, Rbpkg.log_dir, Rbpkg.log_dir)
 
 def usage()
   STDERR.puts """Usage: #{File.basename($0)} COMMAND REPO ...
diff --git a/bin/rbpkg_ci b/bin/rbpkg_ci
index 7995771..412efa4 100755
--- a/bin/rbpkg_ci
+++ b/bin/rbpkg_ci
@@ -23,7 +23,7 @@ when "-qq"
   shift
 end
 
-Rbpkg.init("rbpkg_ci", verbose_level, Rbpkg.ci_log_dir)
+Rbpkg.init("rbpkg_ci", verbose_level, Rbpkg.ci_log_dir, Rbpkg.ci_status_dir)
 
 def usage()
   STDERR.puts "Usage: #{File.basename($0)} REPO BRANCH COMMIT"
diff --git a/lib/rbpkg.rb b/lib/rbpkg.rb
index a0868fc..dce21c2 100644
--- a/lib/rbpkg.rb
+++ b/lib/rbpkg.rb
@@ -56,7 +56,7 @@ module Rbpkg
   def self.ci_remote(repo, branch, commit, host)
     verbose(3, "Rbpkg.ci_remote(#{repo.inspect}, #{branch.inspect}, #{commit.inspect}, #{host.inspect})")
     sh_host = sh_quote(host)
-    cmd! "ssh #{sh_host} rbpkg/bin/rbpkg_ci #{sh_quote(repo)} #{sh_quote(branch)} #{sh_quote(commit)}"
+    cmd "ssh #{sh_host} rbpkg/bin/rbpkg_ci #{sh_quote(repo)} #{sh_quote(branch)} #{sh_quote(commit)}"
     sh_ci_dir = sh_quote(ci_dir)
     cmd! "rsync -a #{sh_host}:#{sh_ci_dir}/. #{sh_ci_dir}"
   end
@@ -107,9 +107,8 @@ module Rbpkg
     end
   end
 
-  @@date = nil
   def self.date
-    @@date || @@date = Time.now.utc.iso8601
+    $date || $date = Time.now.utc.iso8601
   end
 
   @@dir = nil
@@ -156,7 +155,7 @@ module Rbpkg
     end
   end
 
-  def self.init(name, verbose_level, log_dir)
+  def self.init(name, verbose_level, log_dir, status_dir)
     @@verbose_level = verbose_level
     [dir,
      lock_dir,
@@ -165,7 +164,7 @@ module Rbpkg
       FileUtils.mkdir_p(d)
     end
     $log = Rbpkg::Log
-    Rbpkg::Log.init(log_dir, name)
+    Rbpkg::Log.init(log_dir, name, status_dir)
     Rbpkg.lock(name)
   end
 
@@ -244,7 +243,7 @@ module Rbpkg
     uname = `uname`.strip
     raise "uname failed" unless $?.success?
     if uname == "Linux"
-      distrib = `uname -a | grep -io -e Debian -e gentoo -e Ubuntu | sed -e 's|gentoo|Gentoo|'`
+      distrib = `uname -a | grep -io -e Debian -e gentoo -e Ubuntu | sed -e 's|gentoo|Gentoo|'`.strip
       @@os_dir = "#{uname}/#{distrib}"
       @@os = "#{uname}_#{distrib}"
     else
diff --git a/lib/rbpkg/log.rb b/lib/rbpkg/log.rb
index f0b8d9d..cf108e3 100644
--- a/lib/rbpkg/log.rb
+++ b/lib/rbpkg/log.rb
@@ -2,16 +2,16 @@ require 'base64'
 
 module Rbpkg
   class Log
-    attr_reader :name, :path, :path_html
-    attr_accessor :status
+    attr_reader :name, :path, :path_html, :status, :status_path
 
     def initialize(name)
       @name = name
       @path = "#{Rbpkg::Log.log_dir}/#{name}.log"
       @path_html = "#{path}.html"
-      @status = :running
+      @status_path = "#{Rbpkg::Log.status_dir}/#{name}.status"
       raise "log file exists: #{@path.inspect}" if File.exist?(@path)
       raise "log file exists: #{@path_html.inspect}" if File.exist?(@path_html)
+      status = :running
     end
 
     def img
@@ -59,6 +59,13 @@ EOF
       end
     end
 
+    def status=(sym)
+      status_dir = File.dirname(status_path)
+      cmd! "mkdir -p #{sh_quote(status_dir)}" unless File.directory?(status_dir)
+      File.write(status_path, sym.to_s)
+      @status = sym
+    end
+
     def self.add(name)
       raise "already logging to #{name.inspect}" if @@log[name]
       log = new(name)
@@ -66,9 +73,10 @@ EOF
       verbose(3, "Logging to #{log.path}")
     end
 
-    def self.init(log_dir, name)
+    def self.init(log_dir, name, status_dir)
       @@log_dir = log_dir
       @@name = name
+      @@status_dir = status_dir
       @@log = {}
       add(name)
       at_exit { ko_all }
@@ -135,6 +143,10 @@ EOF
       logs
     end
 
+    def self.status_dir
+      @@status_dir
+    end
+
     def self.status_message(status)
       "Status: #{@@name} -> #{status}"
     end