Skip to content

Commit

Permalink
Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Feb 12, 2020
1 parent b55cee6 commit 58ec460
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions bin/yupdate
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ module YUpdate
end
end

module Logger
include Yast::Logger
def msg(message)
puts message
msg(message)
end
end

# # A Ruby Logger which logs in usual YaST y2log format,
# # additionally it prints the messages also to STDOUT
# class YastLogger < Logger
Expand Down Expand Up @@ -148,7 +156,7 @@ module YUpdate
# #
# # @example Use YastLogger in an easy way
# # class Foo
# # include Yast::Logger
# # include YUpdate::Logger
# #
# # def foo
# # # this will be logged into y2log using the usual y2log format
Expand Down Expand Up @@ -213,7 +221,7 @@ module YUpdate

# Class for managing the OverlayFS mounts
class OverlayFS
include Yast::Logger
include YUpdate::Logger

OVERLAY_PREFIX = "/var/lib/YaST2/overlayfs".freeze

Expand All @@ -236,7 +244,7 @@ module YUpdate
# create an OverlayFS overlay for this directory if it is not writable
def create
return if File.writable?(dir)
log.warn "Adding overlay for #{dir}..."
msg "Adding overlay for #{dir}..."

FileUtils.mkdir_p(upperdir)
FileUtils.mkdir_p(workdir)
Expand All @@ -254,12 +262,8 @@ module YUpdate

# delete the OverlayFS for this directory, all changes will be reverted back
def delete
log.debug "umount #{dir}"
system "umount #{dir.shellescape}"

log.debug "umount #{origdir}"
system "umount #{origdir.shellescape}"

FileUtils.rm_rf([upperdir, workdir, origdir])
end

Expand Down Expand Up @@ -335,7 +339,7 @@ module YUpdate

# a generic HTTP downloader
class Downloader
include Yast::Logger
include YUpdate::Logger
attr_reader :url

def initialize(url)
Expand All @@ -345,15 +349,15 @@ module YUpdate
# download the file, returns the response body or if a block is
# given it passes the response to it
def download(redirect = 10, &block)
log.info "Downloading #{url}"
msg "Downloading #{url}"
uri = URI(url)

while redirect > 0
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.is_a?(URI::HTTPS)) do |http|
request = Net::HTTP::Get.new uri
http.request(request) do |response|
if response.is_a?(Net::HTTPRedirection)
log.info "Redirected to #{response["location"]}"
msg "Redirected to #{response["location"]}"
uri = URI(response["location"])
redirect -= 1
elsif response.is_a?(Net::HTTPSuccess)
Expand Down Expand Up @@ -453,7 +457,7 @@ module YUpdate

# install the YaST sources using the "rake install" call
class Installer
include Yast::Logger
include YUpdate::Logger

# globs for ignored some files
SKIP_FILES = [
Expand All @@ -471,7 +475,7 @@ module YUpdate

# install the sources to the specified (temporary) directory
def install_sources(src, target)
log.info "Preparing files..."
msg "Preparing files..."

# check for Makefile.cvs, we cannot install packages using autotools
makefile_cvs = Dir["#{src}/**/Makefile.cvs"].first
Expand All @@ -495,7 +499,7 @@ module YUpdate

# copy the changed files to the ins-sys
def copy_to_system(src)
log.info "Copying to system..."
msg "Copying to system..."
src_path = Pathname.new(src)
cnt = 0
Find.find(src) do |path|
Expand All @@ -507,19 +511,17 @@ module YUpdate
system_dir = File.dirname(system_file)

if skip_file?(system_file)
log.debug "Skipping: #{system_file}"
next
end

if File.exist?(system_file)
if FileUtils.identical?(system_file, path)
log.debug "Not modified: #{system_file}"
next
else
add_overlay(system_dir)
FileUtils.rm_f(system_file) if File.symlink?(system_file)
FileUtils.cp(path, system_file)
log.warn "Updated: #{system_file}"
msg "Updated: #{system_file}"
cnt += 1
end
else
Expand All @@ -532,12 +534,12 @@ module YUpdate
end

FileUtils.cp(path, system_file)
log.warn "Added: #{system_file}"
msg "Added: #{system_file}"
cnt += 1
end
end

log.info "Number of modified files: #{cnt}"
msg "Number of modified files: #{cnt}"
end

# ensure that the target directory is writable
Expand Down Expand Up @@ -647,7 +649,7 @@ module YUpdate

# handle the "patch" command line option
class PatchCommand
include Yast::Logger
include YUpdate::Logger

def initialize(argv)
@argv = argv
Expand Down Expand Up @@ -694,7 +696,7 @@ module YUpdate
servers = RemoteServer.find(hostname)

servers.each do |s|
log.info "Installing from #{s.url}..."
msg "Installing from #{s.url}..."
url = "#{s.url}/archive/current.tar.gz"
install_from_tar(url)
end
Expand Down Expand Up @@ -729,15 +731,15 @@ module YUpdate
inf = InstallInf.new
return if inf[SELF_UPDATE_KEY] == "0"

log.warn "Disabling the YaST SelfUpdate feature in install.inf!"
msg "Disabling the YaST SelfUpdate feature in install.inf!"
inf[SELF_UPDATE_KEY] = "0"
inf.write
end
end

# handle invalid command line options
class InvalidCommand
include Yast::Logger
include YUpdate::Logger

def initialize(cmd)
@cmd = cmd
Expand Down

0 comments on commit 58ec460

Please sign in to comment.