Skip to content

Commit

Permalink
convert finish client to new base class
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 7, 2015
1 parent 3b63f35 commit 015db2a
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 143 deletions.
4 changes: 2 additions & 2 deletions package/yast2-installation.spec
Expand Up @@ -37,8 +37,8 @@ BuildRequires: docbook-xsl-stylesheets libxslt update-desktop-files yast2-core-
BuildRequires: yast2-devtools >= 3.1.10
BuildRequires: rubygem(rspec)

# Linuxrc.keys
BuildRequires: yast2 >= 3.1.41
# Base clients for inst clients
BuildRequires: yast2 >= 3.1.112

# Yast::Remote
BuildRequires: yast2-network
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Expand Up @@ -107,6 +107,7 @@ ylibdir = "${yast2dir}/lib/installation"
ylib_DATA = \
lib/installation/cio_ignore.rb \
lib/installation/clone_settings.rb \
lib/installation/copy_logs_finish.rb \
lib/installation/minimal_installation.rb \
lib/installation/prep_shrink.rb \
lib/installation/remote_finish_client.rb
Expand Down
143 changes: 2 additions & 141 deletions src/clients/copy_logs_finish.rb
@@ -1,142 +1,3 @@
# encoding: utf-8
require "installation/copy_logs_finish"

# ------------------------------------------------------------------------------
# Copyright (c) 2006-2012 Novell, Inc. All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------

# File:
# copy_logs_finish.ycp
#
# Module:
# Step of base installation finish
#
# Authors:
# Jiri Srain <jsrain@suse.cz>
#
# $Id$
#
module Yast
class CopyLogsFinishClient < Client
include Yast::Logger

def main
Yast.import "UI"

textdomain "installation"

Yast.import "Directory"
Yast.include self, "installation/misc.rb"

@ret = nil
@func = ""
@param = {}

# Check arguments
if Ops.greater_than(Builtins.size(WFM.Args), 0) &&
Ops.is_string?(WFM.Args(0))
@func = Convert.to_string(WFM.Args(0))
if Ops.greater_than(Builtins.size(WFM.Args), 1) &&
Ops.is_map?(WFM.Args(1))
@param = Convert.to_map(WFM.Args(1))
end
end

log.info "starting copy_logs_finish"
log.debug "func=#{@func}"
log.debug "param=#{@param}"

if @func == "Info"
return {
"steps" => 1,
# progress step title
"title" => _(
"Copying log files to installed system..."
),
"when" => [:installation, :live_installation, :update, :autoinst]
}
elsif @func == "Write"
@log_files = Convert.convert(
WFM.Read(path(".local.dir"), Directory.logdir),
:from => "any",
:to => "list <string>"
)

Builtins.foreach(@log_files) do |file|
log.debug "Processing file #{file}"

if file == "y2log" || Builtins.regexpmatch(file, "^y2log-[0-9]+$")
# Prepare y2log, y2log-* for log rotation

target_no = 1

if Ops.greater_than(Builtins.size(file), Builtins.size("y2log-"))
target_no = Ops.add(
1,
Builtins.tointeger(
Builtins.substring(file, Builtins.size("y2log-"), 5)
)
)
end

target_basename = Builtins.sformat("y2log-%1", target_no)
InjectRenamedFile(Directory.logdir, file, target_basename)

compress_cmd = Builtins.sformat(
"gzip %1/%2/%3",
Installation.destdir,
Directory.logdir,
target_basename
)
log.debug "Compress command: #{compress_cmd}"
WFM.Execute(path(".local.bash"), compress_cmd)
elsif Builtins.regexpmatch(file, "^y2log-[0-9]+\\.gz$")
target_no = Ops.add(
1,
Builtins.tointeger(
Builtins.regexpsub(file, "y2log-([0-9]+)\\.gz", "\\1")
)
)
InjectRenamedFile(
Directory.logdir,
file,
Builtins.sformat("y2log-%1.gz", target_no)
)
elsif file == "zypp.log"
# Save zypp.log from the inst-sys
InjectRenamedFile(Directory.logdir, file, "zypp.log-1") # not y2log, y2log-*
else
InjectFile(Ops.add(Ops.add(Directory.logdir, "/"), file))
end
end

copy_cmd = "/bin/cp /var/log/pbl.log '#{Installation.destdir}/#{Directory.logdir}/pbl-instsys.log'"
log.debug "Copy command: #{copy_cmd}"
WFM.Execute(path(".local.bash"), copy_cmd)
else
log.error "unknown function: #{@func}"
@ret = nil
end

log.debug "ret=#{@ret}"
log.info "copy_logs_finish finished"
deep_copy(@ret)
end
end
end

Yast::CopyLogsFinishClient.new.main
::Installation::CopyLogsFinish.run
109 changes: 109 additions & 0 deletions src/lib/installation/copy_logs_finish.rb
@@ -0,0 +1,109 @@
# ------------------------------------------------------------------------------
# Copyright (c) 2006-2015 Novell, Inc. All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------

require "installation/finish_client"

module Installation
class CopyLogsFinish < ::Installation::FinishClient
include Yast::I18n

def initialize
Yast.import "UI"

textdomain "installation"

Yast.import "Directory"
Yast.include self, "installation/misc.rb"
end

def steps
1
end

def title
_("Copying log files to installed system...")
end

def modes
[:installation, :live_installation, :update, :autoinst]
end

def write
@log_files = Yast::Convert.convert(
Yast::WFM.Read(path(".local.dir"), Yast::Directory.logdir),
:from => "any",
:to => "list <string>"
)

Yast::Builtins.foreach(@log_files) do |file|
log.debug "Processing file #{file}"

if file == "y2log" || Yast::Builtins.regexpmatch(file, "^y2log-[0-9]+$")
# Prepare y2log, y2log-* for log rotation

target_no = 1

if Yast::Ops.greater_than(Yast::Builtins.size(file), Yast::Builtins.size("y2log-"))
target_no = Yast::Ops.add(
1,
Yast::Builtins.tointeger(
Yast::Builtins.substring(file, Builtins.size("y2log-"), 5)
)
)
end

target_basename = Yast::Builtins.sformat("y2log-%1", target_no)
InjectRenamedFile(Yast::Directory.logdir, file, target_basename)

compress_cmd = Yast::Builtins.sformat(
"gzip %1/%2/%3",
Yast::Installation.destdir,
Yast::Directory.logdir,
target_basename
)
log.debug "Compress command: #{compress_cmd}"
Yast::WFM.Execute(path(".local.bash"), compress_cmd)
elsif Yast::Builtins.regexpmatch(file, "^y2log-[0-9]+\\.gz$")
target_no = Yast::Ops.add(
1,
Yast::Builtins.tointeger(
Yast::Builtins.regexpsub(file, "y2log-([0-9]+)\\.gz", "\\1")
)
)
InjectRenamedFile(
Yast::Directory.logdir,
file,
Yast::Builtins.sformat("y2log-%1.gz", target_no)
)
elsif file == "zypp.log"
# Save zypp.log from the inst-sys
InjectRenamedFile(Yast::Directory.logdir, file, "zypp.log-1") # not y2log, y2log-*
else
InjectFile(Yast::Ops.add(Yast::Ops.add(Yast::Directory.logdir, "/"), file))
end
end

copy_cmd = "/bin/cp /var/log/pbl.log '#{Yast::Installation.destdir}/#{Yast::Directory.logdir}/pbl-instsys.log'"
log.debug "Copy command: #{copy_cmd}"
Yast::WFM.Execute(path(".local.bash"), copy_cmd)

nil
end
end
end

0 comments on commit 015db2a

Please sign in to comment.