Fix JSON issue (rhbz#1543320)

This commit is contained in:
Terje Røsten 2018-02-08 19:04:36 +01:00
parent 787bed3054
commit 1eb4ce686d
2 changed files with 81 additions and 5 deletions

View File

@ -0,0 +1,66 @@
commit 135a853c60582b14c5b67e5cd988a8062d9896f4
Author: Lyonel Vincent <lyonel@ezix.org>
Date: Fri Apr 28 16:54:42 2017 +0200
Fix JSON output format
cf. https://github.com/lyonel/lshw/pull/28
diff --git a/src/core/hw.cc b/src/core/hw.cc
index 68e5912..9defd26 100644
--- a/src/core/hw.cc
+++ b/src/core/hw.cc
@@ -1368,9 +1368,14 @@ string hwNode::asJSON(unsigned level)
config = getConfigKeys();
resources = getResources("\" value=\"");
+ if (level == 0)
+ {
+ out << "[" << endl;
+ }
+
if(visible(getClassName()))
{
- out << "{" << endl;
+ out << spaces(2*level) << "{" << endl;
out << spaces(2*level+2) << "\"id\" : \"" << getId() << "\"," << endl;
out << spaces(2*level+2) << "\"class\" : \"" << getClassName() << "\"";
@@ -1613,20 +1618,13 @@ string hwNode::asJSON(unsigned level)
resources.clear();
}
-
- if(countChildren()>0)
+ for (unsigned int i = 0; i < countChildren(); i++)
{
- if(visible(getClassName()))
- out << "," << endl << spaces(2*level+2) << "\"children\" : [" << endl;
-
- for (unsigned int i = 0; i < countChildren(); i++)
+ out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
+ if (visible(getChild(i)->getClassName()))
{
- out << spaces(2*level+4) << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
- if(visible(getChild(i)->getClassName()) && (i < countChildren()-1)) out << "," << endl;
+ out << "," << endl;
}
-
- if(visible(getClassName()))
- out << endl << spaces(2*level+2) << "]";
}
if(visible(getClassName()))
@@ -1635,6 +1633,12 @@ string hwNode::asJSON(unsigned level)
out << "}";
}
+ if (level == 0)
+ {
+ out.seekp(-2, std::ios_base::end);
+ out << endl << "]" << endl;
+ }
+
return out.str();
}

View File

@ -1,7 +1,7 @@
Summary: Hardware lister
Name: lshw
Version: B.02.18
Release: 14%{?dist}
Release: 15%{?dist}
License: GPLv2
Group: Applications/System
URL: http://ezix.org/project/wiki/HardwareLiSter
@ -12,10 +12,12 @@ Source3: lshw-gui
Source4: lshw-gui.appdata.xml
Patch1: lshw-B.02.18-scandir.patch
Patch2: lshw-B.02.18-d05baa7.patch
Patch3: lshw-B.02.18-revert-json.patch
BuildRequires: desktop-file-utils
BuildRequires: gettext
BuildRequires: gtk2-devel >= 2.4
BuildRequires: desktop-file-utils
BuildRequires: libappstream-glib
BuildRequires: python3-devel
Requires: hwdata
%description
lshw is a small tool to provide detailed informaton on the hardware
@ -40,6 +42,7 @@ format.
%setup -q
%patch01 -p1
%patch02 -p1
%patch03 -R -p1
%build
make %{?_smp_mflags} SBINDIR="%{_sbindir}" RPM_OPT_FLAGS="%{optflags}" gui
@ -100,6 +103,12 @@ rm -rf %{buildroot}%{_datadir}/locale/fr/
%check
appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/appdata/*.appdata.xml
# check json output is valid
src/lshw -json \
-disable usb -disable pcmcia -disable isapnp \
-disable ide -disable scsi -disable dmi -disable memory \
-disable cpuinfo 2>/dev/null | %{__python3} -m json.tool
#files -f %{name}.lang
%files
%license COPYING
@ -120,14 +129,15 @@ appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/appdata/*.appdata
%{_datadir}/polkit-1/actions/org.ezix.lshw.gui.policy
%changelog
* Thu Feb 08 2018 Terje Rosten <terje.rosten@ntnu.no> - B.02.18-15
- Fix JSON issue (rhbz#1543320)
* Thu Feb 08 2018 Fedora Release Engineering <releng@fedoraproject.org> - B.02.18-14
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild
* Fri Jan 26 2018 Terje Rosten <terje.rosten@ntnu.no> - B.02.18-14
- Need gettext
* Fri Jan 26 2018 Terje Rosten <terje.rosten@ntnu.no> - B.02.18-13
- Fix date
- Need gettext
* Fri Jan 26 2018 Terje Rosten <terje.rosten@ntnu.no> - B.02.18-12
- Update to commit d05baa7