mirror of
https://git.yoctoproject.org/poky
synced 2026-09-19 09:49:33 +02:00
distrodata: Use Python CSV instead of did by hand
Fix CSV generation in distrodata class using Python CSV module before it some errors happen when read due to incorrect quoting/delimiters. [YOCTO #7777] (From OE-Core rev: de4d9d46bd293da820830f22d9ff08c0f26831c6) Signed-off-by: AnÃbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
56072bb3bd
commit
20a71d63fc
@@ -2,11 +2,16 @@ addhandler distro_eventhandler
|
|||||||
distro_eventhandler[eventmask] = "bb.event.BuildStarted"
|
distro_eventhandler[eventmask] = "bb.event.BuildStarted"
|
||||||
python distro_eventhandler() {
|
python distro_eventhandler() {
|
||||||
import oe.distro_check as dc
|
import oe.distro_check as dc
|
||||||
|
import csv
|
||||||
logfile = dc.create_log_file(e.data, "distrodata.csv")
|
logfile = dc.create_log_file(e.data, "distrodata.csv")
|
||||||
|
|
||||||
lf = bb.utils.lockfile("%s.lock" % logfile)
|
lf = bb.utils.lockfile("%s.lock" % logfile)
|
||||||
f = open(logfile, "a")
|
with open(logfile, "a") as f:
|
||||||
f.write("Package,Description,Owner,License,VerMatch,Version,Upsteam,Reason,Recipe Status,Distro 1,Distro 2,Distro 3\n")
|
writer = csv.writer(f)
|
||||||
f.close()
|
writer.writerow(['Package', 'Description', 'Owner', 'License',
|
||||||
|
'VerMatch', 'Version', 'Upsteam', 'Reason', 'Recipe Status',
|
||||||
|
'Distro 1', 'Distro 2', 'Distro 3'])
|
||||||
|
f.close()
|
||||||
bb.utils.unlockfile(lf)
|
bb.utils.unlockfile(lf)
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -98,6 +103,7 @@ python do_distrodata_np() {
|
|||||||
addtask distrodata
|
addtask distrodata
|
||||||
do_distrodata[nostamp] = "1"
|
do_distrodata[nostamp] = "1"
|
||||||
python do_distrodata() {
|
python do_distrodata() {
|
||||||
|
import csv
|
||||||
logpath = d.getVar('LOG_DIR', True)
|
logpath = d.getVar('LOG_DIR', True)
|
||||||
bb.utils.mkdirhier(logpath)
|
bb.utils.mkdirhier(logpath)
|
||||||
logfile = os.path.join(logpath, "distrodata.csv")
|
logfile = os.path.join(logpath, "distrodata.csv")
|
||||||
@@ -176,14 +182,13 @@ python do_distrodata() {
|
|||||||
result = dist_check.compare_in_distro_packages_list(distro_check_dir, localdata)
|
result = dist_check.compare_in_distro_packages_list(distro_check_dir, localdata)
|
||||||
|
|
||||||
lf = bb.utils.lockfile("%s.lock" % logfile)
|
lf = bb.utils.lockfile("%s.lock" % logfile)
|
||||||
f = open(logfile, "a")
|
with open(logfile, "a") as f:
|
||||||
f.write("%s,%s,%s,%s,%s,%s,%s,%s,%s" % \
|
row = [pname, pdesc, maintainer, plicense, vermatch, pcurver, pupver, noupdate_reason, rstatus]
|
||||||
(pname, pdesc, maintainer, plicense, vermatch, pcurver, pupver, noupdate_reason, rstatus))
|
row.extend(result)
|
||||||
line = ""
|
|
||||||
for i in result:
|
writer = csv.writer(f)
|
||||||
line = line + "," + i
|
writer.writerow(row)
|
||||||
f.write(line + "\n")
|
f.close()
|
||||||
f.close()
|
|
||||||
bb.utils.unlockfile(lf)
|
bb.utils.unlockfile(lf)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,45 +203,33 @@ do_distrodataall() {
|
|||||||
addhandler checkpkg_eventhandler
|
addhandler checkpkg_eventhandler
|
||||||
checkpkg_eventhandler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted"
|
checkpkg_eventhandler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted"
|
||||||
python checkpkg_eventhandler() {
|
python checkpkg_eventhandler() {
|
||||||
|
import csv
|
||||||
|
|
||||||
def parse_csv_file(filename):
|
def parse_csv_file(filename):
|
||||||
package_dict = {}
|
package_dict = {}
|
||||||
fd = open(filename, "r")
|
|
||||||
lines = fd.read().rsplit("\n")
|
|
||||||
fd.close()
|
|
||||||
|
|
||||||
first_line = ''
|
with open(filename, "r") as f:
|
||||||
index = 0
|
reader = csv.reader(f, delimiter='\t')
|
||||||
for line in lines:
|
for row in reader:
|
||||||
#Skip the first line
|
pn = row[0]
|
||||||
if index == 0:
|
|
||||||
first_line = line
|
if reader.line_num == 1:
|
||||||
index += 1
|
header = row
|
||||||
continue
|
|
||||||
elif line == '':
|
|
||||||
continue
|
|
||||||
index += 1
|
|
||||||
package_name = line.rsplit("\t")[0]
|
|
||||||
if '-native' in package_name or 'nativesdk-' in package_name:
|
|
||||||
original_name = package_name.rsplit('-native')[0]
|
|
||||||
if original_name == '':
|
|
||||||
original_name = package_name.rsplit('nativesdk-')[0]
|
|
||||||
if original_name in package_dict:
|
|
||||||
continue
|
continue
|
||||||
else:
|
|
||||||
package_dict[package_name] = line
|
|
||||||
else:
|
|
||||||
new_name = package_name + "-native"
|
|
||||||
if not(new_name in package_dict):
|
|
||||||
new_name = 'nativesdk-' + package_name
|
|
||||||
if new_name in package_dict:
|
|
||||||
del package_dict[new_name]
|
|
||||||
package_dict[package_name] = line
|
|
||||||
|
|
||||||
fd = open(filename, "w")
|
if '-native' in pn or 'nativesdk-' in pn:
|
||||||
fd.write("%s\n"%first_line)
|
continue
|
||||||
for el in package_dict:
|
|
||||||
fd.write(package_dict[el] + "\n")
|
if not pn in package_dict.keys():
|
||||||
fd.close()
|
package_dict[pn] = row
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
with open(filename, "w") as f:
|
||||||
|
writer = csv.writer(f, delimiter='\t')
|
||||||
|
writer.writerow(header)
|
||||||
|
for pn in package_dict.keys():
|
||||||
|
writer.writerow(package_dict[pn])
|
||||||
|
f.close()
|
||||||
|
|
||||||
del package_dict
|
del package_dict
|
||||||
|
|
||||||
@@ -245,9 +238,13 @@ python checkpkg_eventhandler() {
|
|||||||
logfile = dc.create_log_file(e.data, "checkpkg.csv")
|
logfile = dc.create_log_file(e.data, "checkpkg.csv")
|
||||||
|
|
||||||
lf = bb.utils.lockfile("%s.lock" % logfile)
|
lf = bb.utils.lockfile("%s.lock" % logfile)
|
||||||
f = open(logfile, "a")
|
with open(logfile, "a") as f:
|
||||||
f.write("Package\tVersion\tUpver\tLicense\tSection\tHome\tRelease\tDepends\tBugTracker\tPE\tDescription\tStatus\tTracking\tURI\tMAINTAINER\tNoUpReason\n")
|
writer = csv.writer(f, delimiter='\t')
|
||||||
f.close()
|
headers = ['Package', 'Version', 'Upver', 'License', 'Section',
|
||||||
|
'Home', 'Release', 'Depends', 'BugTracker', 'PE', 'Description',
|
||||||
|
'Status', 'Tracking', 'URI', 'MAINTAINER', 'NoUpReason']
|
||||||
|
writer.writerow(headers)
|
||||||
|
f.close()
|
||||||
bb.utils.unlockfile(lf)
|
bb.utils.unlockfile(lf)
|
||||||
elif bb.event.getName(e) == "BuildCompleted":
|
elif bb.event.getName(e) == "BuildCompleted":
|
||||||
import os
|
import os
|
||||||
@@ -263,6 +260,7 @@ addtask checkpkg
|
|||||||
do_checkpkg[nostamp] = "1"
|
do_checkpkg[nostamp] = "1"
|
||||||
python do_checkpkg() {
|
python do_checkpkg() {
|
||||||
localdata = bb.data.createCopy(d)
|
localdata = bb.data.createCopy(d)
|
||||||
|
import csv
|
||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -371,14 +369,17 @@ python do_checkpkg() {
|
|||||||
else:
|
else:
|
||||||
pmstatus = ""
|
pmstatus = ""
|
||||||
|
|
||||||
|
psrcuri = psrcuri.split()[0]
|
||||||
pdepends = "".join(pdepends.split("\t"))
|
pdepends = "".join(pdepends.split("\t"))
|
||||||
pdesc = "".join(pdesc.split("\t"))
|
pdesc = "".join(pdesc.split("\t"))
|
||||||
no_upgr_reason = d.getVar('RECIPE_NO_UPDATE_REASON', True)
|
no_upgr_reason = d.getVar('RECIPE_NO_UPDATE_REASON', True)
|
||||||
lf = bb.utils.lockfile("%s.lock" % logfile)
|
lf = bb.utils.lockfile("%s.lock" % logfile)
|
||||||
f = open(logfile, "a")
|
with open(logfile, "a") as f:
|
||||||
f.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % \
|
writer = csv.writer(f, delimiter='\t')
|
||||||
(pname,pversion,pupver,plicense,psection, phome,prelease, pdepends,pbugtracker,ppe,pdesc,pstatus,pmver,psrcuri,maintainer, no_upgr_reason))
|
writer.writerow([pname, pversion, pupver, plicense, psection, phome,
|
||||||
f.close()
|
prelease, pdepends, pbugtracker, ppe, pdesc, pstatus, pmver,
|
||||||
|
psrcuri, maintainer, no_upgr_reason])
|
||||||
|
f.close()
|
||||||
bb.utils.unlockfile(lf)
|
bb.utils.unlockfile(lf)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,12 +442,14 @@ addhandler checklicense_eventhandler
|
|||||||
checklicense_eventhandler[eventmask] = "bb.event.BuildStarted"
|
checklicense_eventhandler[eventmask] = "bb.event.BuildStarted"
|
||||||
python checklicense_eventhandler() {
|
python checklicense_eventhandler() {
|
||||||
"""initialize log files."""
|
"""initialize log files."""
|
||||||
|
import csv
|
||||||
import oe.distro_check as dc
|
import oe.distro_check as dc
|
||||||
logfile = dc.create_log_file(e.data, "missinglicense.csv")
|
logfile = dc.create_log_file(e.data, "missinglicense.csv")
|
||||||
lf = bb.utils.lockfile("%s.lock" % logfile)
|
lf = bb.utils.lockfile("%s.lock" % logfile)
|
||||||
f = open(logfile, "a")
|
with open(logfile, "a") as f:
|
||||||
f.write("Package\tLicense\tMissingLicense\n")
|
writer = csv.writer(f, delimiter='\t')
|
||||||
f.close()
|
writer.writerow(['Package', 'License', 'MissingLicense'])
|
||||||
|
f.close()
|
||||||
bb.utils.unlockfile(lf)
|
bb.utils.unlockfile(lf)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -454,6 +457,7 @@ python checklicense_eventhandler() {
|
|||||||
addtask checklicense
|
addtask checklicense
|
||||||
do_checklicense[nostamp] = "1"
|
do_checklicense[nostamp] = "1"
|
||||||
python do_checklicense() {
|
python do_checklicense() {
|
||||||
|
import csv
|
||||||
import shutil
|
import shutil
|
||||||
logpath = d.getVar('LOG_DIR', True)
|
logpath = d.getVar('LOG_DIR', True)
|
||||||
bb.utils.mkdirhier(logpath)
|
bb.utils.mkdirhier(logpath)
|
||||||
@@ -466,10 +470,10 @@ python do_checklicense() {
|
|||||||
.replace(',', '').replace(" ", "").split("&"))):
|
.replace(',', '').replace(" ", "").split("&"))):
|
||||||
if not os.path.isfile(os.path.join(generic_directory, license_type)):
|
if not os.path.isfile(os.path.join(generic_directory, license_type)):
|
||||||
lf = bb.utils.lockfile("%s.lock" % logfile)
|
lf = bb.utils.lockfile("%s.lock" % logfile)
|
||||||
f = open(logfile, "a")
|
with open(logfile, "a") as f:
|
||||||
f.write("%s\t%s\t%s\n" % \
|
writer = csv.writer(f, delimiter='\t')
|
||||||
(pn,license_types,license_type))
|
writer.writerow([pn, license_types, license_type])
|
||||||
f.close()
|
f.close()
|
||||||
bb.utils.unlockfile(lf)
|
bb.utils.unlockfile(lf)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user