Skip to content

Commit 268a623

Browse files
Eduard Čubaj-mracek
authored andcommitted
[transformer]: yumdb - don't crash with no package data for a package
Update logs
1 parent 73a1a78 commit 268a623

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

dnf/db/swdb_transformer.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import json
2323
from .types import SwdbItem, convert_reason
2424
import logging
25+
from dnf.i18n import _
2526

2627
logger = logging.getLogger('dnf')
2728

@@ -104,7 +105,15 @@ def get_yumdb_packages(cursor, yumdb_path, repo_fn):
104105

105106
# insert data into rows
106107
for row in allrows:
108+
109+
# get PDID of the package
110+
pdid = pid_to_pdid.get(row[0])
111+
if not pdid:
112+
continue
113+
114+
# get package key
107115
name = '-'.join(row[1:])
116+
108117
if name in pkgs.keys():
109118
command = []
110119
vals = pkgs[name]
@@ -121,9 +130,6 @@ def get_yumdb_packages(cursor, yumdb_path, repo_fn):
121130
repo = repo_fn(cursor, temp)
122131
command.append("R_ID='{}'".format(repo))
123132

124-
# get PDID of the package
125-
pdid = pid_to_pdid.get(row[0])
126-
127133
# Update PACKAGE_DATA row
128134
if command:
129135
cmd = "UPDATE PACKAGE_DATA SET {} WHERE PD_ID={}".format(','.join(command), pdid)
@@ -140,17 +146,18 @@ def get_yumdb_packages(cursor, yumdb_path, repo_fn):
140146
command_line = vals.get('command_line')
141147
if releasever or command_line:
142148
tid = pdid_to_tid.get(pdid)
149+
if not tid:
150+
continue
143151
# deciding in Python is faster than running both sqlite statements
144-
if tid:
145-
if releasever and command_line:
146-
cursor.execute('UPDATE TRANS SET cmdline=?, releasever=? WHERE T_ID=?',
147-
(command_line, releasever, tid))
148-
elif releasever:
149-
cursor.execute('UPDATE TRANS SET releasever=? WHERE T_ID=?',
150-
(releasever, tid))
151-
else:
152-
cursor.execute('UPDATE TRANS SET cmdline=? WHERE T_ID=?',
153-
(command_line, tid))
152+
if releasever and command_line:
153+
cursor.execute('UPDATE TRANS SET cmdline=?, releasever=? WHERE T_ID=?',
154+
(command_line, releasever, tid))
155+
elif releasever:
156+
cursor.execute('UPDATE TRANS SET releasever=? WHERE T_ID=?',
157+
(releasever, tid))
158+
else:
159+
cursor.execute('UPDATE TRANS SET cmdline=? WHERE T_ID=?',
160+
(command_line, tid))
154161

155162

156163
def run(input_dir='/var/lib/dnf/', output_file='/var/lib/dnf/history/swdb.sqlite'):
@@ -191,24 +198,24 @@ def bind_repo(cursor, name):
191198

192199
# check path to yumdb dir
193200
if not os.path.isdir(yumdb_path):
194-
logger.error('Error: yumdb directory not valid')
201+
logger.error(_('Error: yumdb directory not valid'))
195202
return False
196203

197204
# check path to history dir
198205
if not os.path.isdir(history_path):
199-
logger.write('Error: history directory not valid')
206+
logger.write(_('Error: history directory not valid'))
200207
return False
201208

202209
# check historyDB file and pick newest one
203210
historydb_file = glob.glob(os.path.join(history_path, "history*"))
204211
if len(historydb_file) < 1:
205-
logger.write('Error: history database file not valid')
212+
logger.write(_('Error: history database file not valid'))
206213
return False
207214
historydb_file.sort()
208215
historydb_file = historydb_file[0]
209216

210217
if not os.path.isfile(historydb_file):
211-
logger.error('Error: history database file not valid')
218+
logger.error(_('Error: history database file not valid'))
212219
return False
213220

214221
tmp_output_file = output_file + '.transform'
@@ -217,7 +224,7 @@ def bind_repo(cursor, name):
217224
historyDB = sqlite3.connect(historydb_file)
218225
h_cursor = historyDB.cursor()
219226
except:
220-
logger.error("ERROR: unable to open database '{}'".format(historydb_file))
227+
logger.error(_("ERROR: unable to open the database '{}'").format(historydb_file))
221228
return False
222229

223230
try:
@@ -226,7 +233,7 @@ def bind_repo(cursor, name):
226233
database = sqlite3.connect(tmp_output_file)
227234
cursor = database.cursor()
228235
except:
229-
logger.error("ERROR: unable to create database '{}'".format(tmp_output_file))
236+
logger.error(_("ERROR: unable to create the database '{}'").format(tmp_output_file))
230237
return False
231238

232239
# value distribution in tables
@@ -239,7 +246,7 @@ def bind_repo(cursor, name):
239246

240247
ENVIRONMENTS = ['name_id', 'name', 'ui_name', 'pkg_types', 'grp_types']
241248

242-
logger.info("Transforming database. It may take a while...")
249+
logger.info(_("Transforming the software database. It may take some time."))
243250

244251
# contruction of PACKAGE from pkgtups
245252
h_cursor.execute('SELECT * FROM pkgtups')

0 commit comments

Comments
 (0)