Signed-off-by: Li Ping 1477412247@qq.com --- container/rpm-repo/rpm-repo.rb | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 container/rpm-repo/rpm-repo.rb
diff --git a/container/rpm-repo/rpm-repo.rb b/container/rpm-repo/rpm-repo.rb new file mode 100755 index 0000000..18f0507 --- /dev/null +++ b/container/rpm-repo/rpm-repo.rb @@ -0,0 +1,73 @@ +#!/usr/bin/ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require "bunny" +require "fileutils" +require "json" + + +MQ_HOST = ENV['MQ_HOST'] || ENV['LKP_SERVER'] || '172.17.0.1' +MQ_PORT = ENV['MQ_PORT'] || 5672 + +class MQClient + def initialize(hostname = "172.17.0.1", port = "5672") + @conn = Bunny.new(hostname: hostname, port: port) + @conn.start + @channel = @conn.create_channel + end + + def queue(queue_name, opts = {}) + @channel.queue(queue_name, opts) + end + + def ack(delivery_info) + @channel.ack(delivery_info.delivery_tag) + end +end + +class HandleRepo + def initialize + @mq = MQClient.new(MQ_HOST, MQ_PORT) + @update = [] + end + + def handle_new_rpm + queue = @mq.queue("update_repo") + queue.subscribe({:block => true, :manual_ack => true}) do |info, _pro, msg| + rpm_info = JSON.parse(msg) + puts rpm_info + rpm_info["upload_rpms"].each do |rpm| + rpm_path = File.dirname(rpm).sub("upload", "testing") + FileUtils.mkdir_p(rpm_path) unless File.directory?(rpm_path) + + dest = File.join(rpm_path.to_s, File.basename(rpm)) + @update << dest + FileUtils.mv(rpm, dest) + system("createrepo --update $(dirname #{rpm_path})") + end + update_pub_dir + @mq.ack(info) + end + end + + def update_pub_dir + @update.each do |rpm| + pub_path = File.dirname(rpm).sub("testing", "pub") + FileUtils.mkdir_p(pub_path) unless File.directory?(pub_path) + + dest = File.join(pub_path, File.basename(rpm)) + FileUtils.cp(rpm, dest) + + repodata_dest = File.join(File.dirname(pub_path), "repodata") + repodata_src = File.dirname(rpm).sub("Packages", "repodata") + + FileUtils.rm_r(repodata_dest) if Dir.exist?(repodata_dest) + FileUtils.cp_r(repodata_src, File.dirname(repodata_dest)) + end + end +end + +hr = HandleRepo.new +hr.handle_new_rpm
On Mon, Mar 29, 2021 at 10:11:34PM +0800, Li Ping wrote:
Signed-off-by: Li Ping 1477412247@qq.com
container/rpm-repo/rpm-repo.rb | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 container/rpm-repo/rpm-repo.rb
diff --git a/container/rpm-repo/rpm-repo.rb b/container/rpm-repo/rpm-repo.rb new file mode 100755 index 0000000..18f0507 --- /dev/null +++ b/container/rpm-repo/rpm-repo.rb @@ -0,0 +1,73 @@ +#!/usr/bin/ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require "bunny" +require "fileutils" +require "json"
+MQ_HOST = ENV['MQ_HOST'] || ENV['LKP_SERVER'] || '172.17.0.1' +MQ_PORT = ENV['MQ_PORT'] || 5672
+class MQClient
move the client to the $CCI_SRC/lib, others can use it too.
Thanks, Xueliang
- def initialize(hostname = "172.17.0.1", port = "5672")
- @conn = Bunny.new(hostname: hostname, port: port)
- @conn.start
- @channel = @conn.create_channel
- end
- def queue(queue_name, opts = {})
- @channel.queue(queue_name, opts)
- end
- def ack(delivery_info)
- @channel.ack(delivery_info.delivery_tag)
- end
+end
+class HandleRepo
- def initialize
- @mq = MQClient.new(MQ_HOST, MQ_PORT)
- @update = []
- end
- def handle_new_rpm
- queue = @mq.queue("update_repo")
- queue.subscribe({:block => true, :manual_ack => true}) do |info, _pro, msg|
rpm_info = JSON.parse(msg)
puts rpm_info
rpm_info["upload_rpms"].each do |rpm|
rpm_path = File.dirname(rpm).sub("upload", "testing")
FileUtils.mkdir_p(rpm_path) unless File.directory?(rpm_path)
dest = File.join(rpm_path.to_s, File.basename(rpm))
@update << dest
FileUtils.mv(rpm, dest)
system("createrepo --update $(dirname #{rpm_path})")
end
update_pub_dir
@mq.ack(info)
- end
- end
- def update_pub_dir
- @update.each do |rpm|
pub_path = File.dirname(rpm).sub("testing", "pub")
FileUtils.mkdir_p(pub_path) unless File.directory?(pub_path)
dest = File.join(pub_path, File.basename(rpm))
FileUtils.cp(rpm, dest)
repodata_dest = File.join(File.dirname(pub_path), "repodata")
repodata_src = File.dirname(rpm).sub("Packages", "repodata")
FileUtils.rm_r(repodata_dest) if Dir.exist?(repodata_dest)
FileUtils.cp_r(repodata_src, File.dirname(repodata_dest))
- end
- end
+end
+hr = HandleRepo.new
+hr.handle_new_rpm
2.23.0
On Mon, Mar 29, 2021 at 10:11:34PM +0800, Li Ping wrote:
Signed-off-by: Li Ping 1477412247@qq.com
container/rpm-repo/rpm-repo.rb | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 container/rpm-repo/rpm-repo.rb
diff --git a/container/rpm-repo/rpm-repo.rb b/container/rpm-repo/rpm-repo.rb new file mode 100755 index 0000000..18f0507 --- /dev/null +++ b/container/rpm-repo/rpm-repo.rb @@ -0,0 +1,73 @@ +#!/usr/bin/ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require "bunny" +require "fileutils" +require "json"
delete extra line
+MQ_HOST = ENV['MQ_HOST'] || ENV['LKP_SERVER'] || '172.17.0.1' +MQ_PORT = ENV['MQ_PORT'] || 5672
+class MQClient
- def initialize(hostname = "172.17.0.1", port = "5672")
- @conn = Bunny.new(hostname: hostname, port: port)
- @conn.start
- @channel = @conn.create_channel
- end
for you have added the MQ_HOST/MQ_PORT constants, just use it.
- def queue(queue_name, opts = {})
- @channel.queue(queue_name, opts)
- end
- def ack(delivery_info)
- @channel.ack(delivery_info.delivery_tag)
- end
+end
+class HandleRepo
- def initialize
- @mq = MQClient.new(MQ_HOST, MQ_PORT)
- @update = []
- end
- def handle_new_rpm
- queue = @mq.queue("update_repo")
- queue.subscribe({:block => true, :manual_ack => true}) do |info, _pro, msg|
rpm_info = JSON.parse(msg)
puts rpm_info
debug line?
rpm_info["upload_rpms"].each do |rpm|
rpm_path = File.dirname(rpm).sub("upload", "testing")
FileUtils.mkdir_p(rpm_path) unless File.directory?(rpm_path)
dest = File.join(rpm_path.to_s, File.basename(rpm))
@update << dest
FileUtils.mv(rpm, dest)
system("createrepo --update $(dirname #{rpm_path})")
end
update_pub_dir
@mq.ack(info)
- end
- end
- def update_pub_dir
- @update.each do |rpm|
pub_path = File.dirname(rpm).sub("testing", "pub")
FileUtils.mkdir_p(pub_path) unless File.directory?(pub_path)
dest = File.join(pub_path, File.basename(rpm))
FileUtils.cp(rpm, dest)
repodata_dest = File.join(File.dirname(pub_path), "repodata")
repodata_src = File.dirname(rpm).sub("Packages", "repodata")
FileUtils.rm_r(repodata_dest) if Dir.exist?(repodata_dest)
FileUtils.cp_r(repodata_src, File.dirname(repodata_dest))
is there any need to keep the repodata_src? if not you can use FileUtils.mv is better
Thanks, Luan Shengde
- end
- end
+end
+hr = HandleRepo.new
+hr.handle_new_rpm
2.23.0
On Tue, Mar 30, 2021 at 11:55:54AM +0800, Luan Shengde wrote:
On Mon, Mar 29, 2021 at 10:11:34PM +0800, Li Ping wrote:
Signed-off-by: Li Ping 1477412247@qq.com
container/rpm-repo/rpm-repo.rb | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 container/rpm-repo/rpm-repo.rb
diff --git a/container/rpm-repo/rpm-repo.rb b/container/rpm-repo/rpm-repo.rb new file mode 100755 index 0000000..18f0507 --- /dev/null +++ b/container/rpm-repo/rpm-repo.rb @@ -0,0 +1,73 @@ +#!/usr/bin/ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require "bunny" +require "fileutils" +require "json"
delete extra line
ok, i got it.
+MQ_HOST = ENV['MQ_HOST'] || ENV['LKP_SERVER'] || '172.17.0.1' +MQ_PORT = ENV['MQ_PORT'] || 5672
+class MQClient
- def initialize(hostname = "172.17.0.1", port = "5672")
- @conn = Bunny.new(hostname: hostname, port: port)
- @conn.start
- @channel = @conn.create_channel
- end
for you have added the MQ_HOST/MQ_PORT constants, just use it.
- def queue(queue_name, opts = {})
- @channel.queue(queue_name, opts)
- end
- def ack(delivery_info)
- @channel.ack(delivery_info.delivery_tag)
- end
+end
+class HandleRepo
- def initialize
- @mq = MQClient.new(MQ_HOST, MQ_PORT)
- @update = []
- end
- def handle_new_rpm
- queue = @mq.queue("update_repo")
- queue.subscribe({:block => true, :manual_ack => true}) do |info, _pro, msg|
rpm_info = JSON.parse(msg)
puts rpm_info
debug line?
yes, i will give more information.
Thanks, Ping
rpm_info["upload_rpms"].each do |rpm|
rpm_path = File.dirname(rpm).sub("upload", "testing")
FileUtils.mkdir_p(rpm_path) unless File.directory?(rpm_path)
dest = File.join(rpm_path.to_s, File.basename(rpm))
@update << dest
FileUtils.mv(rpm, dest)
system("createrepo --update $(dirname #{rpm_path})")
end
update_pub_dir
@mq.ack(info)
- end
- end
- def update_pub_dir
- @update.each do |rpm|
pub_path = File.dirname(rpm).sub("testing", "pub")
FileUtils.mkdir_p(pub_path) unless File.directory?(pub_path)
dest = File.join(pub_path, File.basename(rpm))
FileUtils.cp(rpm, dest)
repodata_dest = File.join(File.dirname(pub_path), "repodata")
repodata_src = File.dirname(rpm).sub("Packages", "repodata")
FileUtils.rm_r(repodata_dest) if Dir.exist?(repodata_dest)
FileUtils.cp_r(repodata_src, File.dirname(repodata_dest))
is there any need to keep the repodata_src? if not you can use FileUtils.mv is better
i can not use mv, i have to keep the repodata_src same as repodata_dest
Thanks, Ping
Thanks, Luan Shengde
- end
- end
+end
+hr = HandleRepo.new
+hr.handle_new_rpm
2.23.0
This is tricky logic, should describe the full context/workflow/design as comments in the beginning of class definition.
Thanks, Fengguang
On Mon, Mar 29, 2021 at 10:11:34PM +0800, Li Ping wrote:
Signed-off-by: Li Ping 1477412247@qq.com
container/rpm-repo/rpm-repo.rb | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 container/rpm-repo/rpm-repo.rb
diff --git a/container/rpm-repo/rpm-repo.rb b/container/rpm-repo/rpm-repo.rb new file mode 100755 index 0000000..18f0507 --- /dev/null +++ b/container/rpm-repo/rpm-repo.rb @@ -0,0 +1,73 @@ +#!/usr/bin/ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require "bunny" +require "fileutils" +require "json"
+MQ_HOST = ENV['MQ_HOST'] || ENV['LKP_SERVER'] || '172.17.0.1' +MQ_PORT = ENV['MQ_PORT'] || 5672
+class MQClient
- def initialize(hostname = "172.17.0.1", port = "5672")
- @conn = Bunny.new(hostname: hostname, port: port)
- @conn.start
- @channel = @conn.create_channel
- end
- def queue(queue_name, opts = {})
- @channel.queue(queue_name, opts)
- end
- def ack(delivery_info)
- @channel.ack(delivery_info.delivery_tag)
- end
+end
+class HandleRepo
- def initialize
- @mq = MQClient.new(MQ_HOST, MQ_PORT)
- @update = []
- end
- def handle_new_rpm
- queue = @mq.queue("update_repo")
- queue.subscribe({:block => true, :manual_ack => true}) do |info, _pro, msg|
rpm_info = JSON.parse(msg)
puts rpm_info
rpm_info["upload_rpms"].each do |rpm|
rpm_path = File.dirname(rpm).sub("upload", "testing")
FileUtils.mkdir_p(rpm_path) unless File.directory?(rpm_path)
dest = File.join(rpm_path.to_s, File.basename(rpm))
@update << dest
FileUtils.mv(rpm, dest)
system("createrepo --update $(dirname #{rpm_path})")
end
update_pub_dir
@mq.ack(info)
- end
- end
- def update_pub_dir
- @update.each do |rpm|
pub_path = File.dirname(rpm).sub("testing", "pub")
FileUtils.mkdir_p(pub_path) unless File.directory?(pub_path)
dest = File.join(pub_path, File.basename(rpm))
FileUtils.cp(rpm, dest)
repodata_dest = File.join(File.dirname(pub_path), "repodata")
repodata_src = File.dirname(rpm).sub("Packages", "repodata")
FileUtils.rm_r(repodata_dest) if Dir.exist?(repodata_dest)
FileUtils.cp_r(repodata_src, File.dirname(repodata_dest))
- end
- end
+end
+hr = HandleRepo.new
+hr.handle_new_rpm
2.23.0
On Tue, Mar 30, 2021 at 02:54:09PM +0800, Wu Fengguang wrote:
This is tricky logic, should describe the full context/workflow/design as comments in the beginning of class definition.
ok, i got it.
Thanks, Ping
Thanks, Fengguang
On Mon, Mar 29, 2021 at 10:11:34PM +0800, Li Ping wrote:
Signed-off-by: Li Ping 1477412247@qq.com
container/rpm-repo/rpm-repo.rb | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 container/rpm-repo/rpm-repo.rb
diff --git a/container/rpm-repo/rpm-repo.rb b/container/rpm-repo/rpm-repo.rb new file mode 100755 index 0000000..18f0507 --- /dev/null +++ b/container/rpm-repo/rpm-repo.rb @@ -0,0 +1,73 @@ +#!/usr/bin/ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require "bunny" +require "fileutils" +require "json"
+MQ_HOST = ENV['MQ_HOST'] || ENV['LKP_SERVER'] || '172.17.0.1' +MQ_PORT = ENV['MQ_PORT'] || 5672
+class MQClient
- def initialize(hostname = "172.17.0.1", port = "5672")
- @conn = Bunny.new(hostname: hostname, port: port)
- @conn.start
- @channel = @conn.create_channel
- end
- def queue(queue_name, opts = {})
- @channel.queue(queue_name, opts)
- end
- def ack(delivery_info)
- @channel.ack(delivery_info.delivery_tag)
- end
+end
+class HandleRepo
- def initialize
- @mq = MQClient.new(MQ_HOST, MQ_PORT)
- @update = []
- end
- def handle_new_rpm
- queue = @mq.queue("update_repo")
- queue.subscribe({:block => true, :manual_ack => true}) do |info, _pro, msg|
rpm_info = JSON.parse(msg)
puts rpm_info
rpm_info["upload_rpms"].each do |rpm|
rpm_path = File.dirname(rpm).sub("upload", "testing")
FileUtils.mkdir_p(rpm_path) unless File.directory?(rpm_path)
dest = File.join(rpm_path.to_s, File.basename(rpm))
@update << dest
FileUtils.mv(rpm, dest)
system("createrepo --update $(dirname #{rpm_path})")
end
update_pub_dir
@mq.ack(info)
- end
- end
- def update_pub_dir
- @update.each do |rpm|
pub_path = File.dirname(rpm).sub("testing", "pub")
FileUtils.mkdir_p(pub_path) unless File.directory?(pub_path)
dest = File.join(pub_path, File.basename(rpm))
FileUtils.cp(rpm, dest)
repodata_dest = File.join(File.dirname(pub_path), "repodata")
repodata_src = File.dirname(rpm).sub("Packages", "repodata")
FileUtils.rm_r(repodata_dest) if Dir.exist?(repodata_dest)
FileUtils.cp_r(repodata_src, File.dirname(repodata_dest))
- end
- end
+end
+hr = HandleRepo.new
+hr.handle_new_rpm
2.23.0