Skip to content

Commit

Permalink
Merge pull request #948 from yast/fix/desktop-modules-reading
Browse files Browse the repository at this point in the history
Fix desktop modules reading
  • Loading branch information
imobachgs committed Jul 4, 2019
2 parents 04dfea4 + 338f6bd commit 2486faa
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 2 deletions.
27 changes: 26 additions & 1 deletion library/desktop/src/modules/Desktop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def Read(values_to_parse)
ret = ReadLocalizedKey(filename, filepath, value)
Ops.set(filemap, value, ret) if !ret.nil? && ret != ""
end
name2 = Builtins.regexpsub(file, "^.*/(.*).desktop", "\\1")
name2 = desktop_file_to_module(file)
if name2 != "" && !name2.nil?
Ops.set(@Modules, name2, filemap)
group = Ops.get_string(filemap, "X-SuSE-YaST-Group", "")
Expand Down Expand Up @@ -400,6 +400,31 @@ def ParseSingleDesktopFile(file)
publish function: :ModuleList, type: "list <term> (string)"
publish function: :RunViaDesktop, type: "void (string, list <string>)"
publish function: :ParseSingleDesktopFile, type: "map <string, string> (string)"

private

# @return [Regexp] Regular expression which matches the module name of a desktop file
FILE_REGEXP = /([^\.]+).desktop\Z/.freeze

# Converts the file name to the expected module name
#
# In 2019, desktop files were renamed to org.opensuse.yast.MODULE.desktop. This method extracts
# and normalizes the *MODULE* part of the filename.
#
# @param [String] filename
# @return [String,nil] Module name or nil if it cannot be inferred.
# @see https://github.com/yast/yast-yast2/issues/934
def desktop_file_to_module(filename)
basename = File.basename(filename)
name = basename[FILE_REGEXP, 1]
if name.nil?
log.info "Could not infer the module name from #{filename}"
return
end

# E.g. 'AddOn' to 'add-on'
name.gsub(/([[:lower:]])([[:upper:]]+)/, '\1-\2').downcase
end
end

Desktop = DesktopClass.new
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Desktop Entry]
Type=Application
Categories=Settings;System;Qt;X-SuSE-YaST;X-SuSE-YaST-Software;

X-KDE-ModuleType=Library
X-KDE-HasReadOnlyMode=true
X-SuSE-YaST-Call=add-on

X-SuSE-YaST-Group=Software
X-SuSE-YaST-Argument=
X-SuSE-YaST-RootOnly=true
X-SuSE-YaST-AutoInst=configure
X-SuSE-YaST-Geometry=
X-SuSE-YaST-SortKey=
X-SuSE-YaST-AutoInstResource=
X-SuSE-YaST-AutoInstPath=install
X-SuSE-YaST-AutoInstSchema=add-on.rnc
X-SuSE-YaST-AutoInstClonable=true
X-SuSE-YaST-Keywords=update,packages,repositories,software

Icon=yast-addon
Exec=xdg-su -c "/sbin/yast2 add-on"

Name=YaST Add-On Products
GenericName=Add-On Products
Comment=Install or remove add-on products
StartupNotify=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Desktop Entry]
Type=Application
Categories=Settings;System;Qt;X-SuSE-YaST;X-SuSE-YaST-System;

X-KDE-ModuleType=Library
X-KDE-HasReadOnlyMode=true
X-SuSE-YaST-Call=lan

X-SuSE-YaST-Group=System
X-SuSE-YaST-Argument=
X-SuSE-YaST-RootOnly=true
X-SuSE-YaST-AutoInst=all
X-SuSE-YaST-Geometry=
X-SuSE-YaST-SortKey=
X-SuSE-YaST-AutoInstResource=networking
X-SuSE-YaST-AutoInstClonable=true
X-SuSE-YaST-AutoInstSchema=networking.rnc
X-SuSE-YaST-AutoInstRequires=host

Icon=yast-lan
Exec=xdg-su -c "/sbin/yast2 lan"

Name=YaST Network
GenericName=Network Settings
Comment=Configure network cards, hostname and routing
StartupNotify=true
X-SuSE-YaST-Keywords=network,lan,dns,routing
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[Desktop Entry]
Type=Application
Categories=Settings;System;Qt;X-SuSE-YaST;X-SuSE-YaST-System;

X-KDE-ModuleType=Library
X-KDE-HasReadOnlyMode=true
X-SuSE-YaST-Call=services-manager

X-SuSE-YaST-Group=System
X-SuSE-YaST-Argument=
X-SuSE-YaST-RootOnly=true
X-SuSE-YaST-AutoInst=all
X-SuSE-YaST-Geometry=
X-SuSE-YaST-SortKey=
X-SuSE-YaST-AutoInstClonable=true
X-SuSE-YaST-AutoInstSchema=services-manager.rnc
X-SuSE-YaST-AutoInstResourceAliases=runlevel
X-SuSE-YaST-Keywords=systemd,system,background

Icon=yast-services-manager
Exec=xdg-su -c "/sbin/yast2 services-manager"

Name=YaST Services Manager
GenericName=Configure running services and the default target
StartupNotify=true

40 changes: 40 additions & 0 deletions library/desktop/test/desktop_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) [2019] SUSE LLC
#
# 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 SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require_relative "test_helper"

Yast.import "Desktop"

describe Yast::Desktop do
describe "#Modules" do
around { |e| change_scr_root(DESKTOP_DATA_PATH, &e) }

before do
Yast::Desktop.Read(["Name"])
end

it "returns modules information using the short name as key" do
expect(Yast::Desktop.Modules).to eq(
"add-on" => { "Name" => "YaST Add-On Products" },
"lan" => { "Name" => "YaST Network" },
"services-manager" => { "Name" => "YaST Services Manager" }
)
end
end
end
21 changes: 21 additions & 0 deletions library/desktop/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) [2019] SUSE LLC
#
# 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 SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require_relative "../../../test/test_helper.rb"

DESKTOP_DATA_PATH = File.join(__dir__, "data")
6 changes: 6 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Jul 3 14:59:48 UTC 2019 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Infer the right module name from desktop files (bsc#1140233).
- 4.2.12

-------------------------------------------------------------------
Mon Jul 1 13:41:45 UTC 2019 - Knut Anderssen <kanderssen@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 4.2.11
Version: 4.2.12
Release: 0
Summary: YaST2 Main Package
License: GPL-2.0-only
Expand Down

0 comments on commit 2486faa

Please sign in to comment.