Hash :
226df393
Author :
Thomas de Grivel
Date :
2023-02-20T19:38:11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
require 'time'
require __FILE__ + '/../rbpkg/repos'
module Rbpkg
def self.checkout(branch, repos)
repos.each do |name|
Repos.repo(name).checkout(branch)
end
end
def self.clean_sources(repos)
repos.each do |name|
Repos.repo(name).clean_sources()
end
end
@@date = nil
def self.date
@@date || @@date = Time.now.utc.iso8601
end
def self.dir
ENV["RBPKG_DIR"] || "#{ENV["HOME"]}/rbpkg"
end
def self.ensure_dir(path)
if ! File.directory?(path)
cmd "mkdir -p #{sh_quote(path)}"
end
end
def self.fetch(repos)
repos.each do |name|
Repos.repo(name).fetch()
end
end
def self.git_clone(repos)
repos.each do |name|
Repos.repo(name).git_clone()
end
end
def self.info(repos)
repos.each do |name|
repo_info = Repos.repo(name).inspect()
$log.puts repo_info
puts repo_info
end
end
def self.init
[dir,
lock_dir,
log_dir
].each do |d|
ensure_dir(d)
end
end
def self.lock(name)
path = lock_path(name)
#verbose(2, "Locking #{path}")
while File.file?(path)
sleep 1000.ms
end
File.write(path, "")
at_exit { FileUtils.rm(path) }
end
def self.lock_dir
"#{dir}/var/lock"
end
def self.lock_path(name)
"#{lock_dir}/#{name}.lock"
end
def self.log_dir
"#{dir}/var/log/shpkg"
end
def self.log_path(name)
"#{log_dir}/#{name}_#{date}_#{$$}.log"
end
def self.pull(repos)
repos.each do |name|
Repos.repo(name).pull()
end
end
def self.src_dir
"#{dir}/src"
end
end
def cmd(string)
verbose(1, string)
IO.popen("#{string} 2>&1", "r") do |pipe|
while line = pipe.gets()
$log.puts line
puts line
end
end
end
def sh_quote (str)
if str.scan("\n") == []
if str.match?(/^[-+\/=.,:^_0-9A-Za-z]*$/)
str
else
"\"" + str.gsub(/([$`\\\"])/, "\\\1") + "\""
end
end
end
def verbose(level, msg)
colored = case level
when 1
"\33[0;34m#{msg}\33[0m\n"
when 2
"\33[0;35m#{msg}\33[0m\n"
else
raise "unknown verbose level: #{level}"
end
$log.puts colored
puts colored
end