22
22
import json
23
23
from .types import SwdbItem , convert_reason
24
24
import logging
25
+ from dnf .i18n import _
25
26
26
27
logger = logging .getLogger ('dnf' )
27
28
@@ -104,7 +105,15 @@ def get_yumdb_packages(cursor, yumdb_path, repo_fn):
104
105
105
106
# insert data into rows
106
107
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
107
115
name = '-' .join (row [1 :])
116
+
108
117
if name in pkgs .keys ():
109
118
command = []
110
119
vals = pkgs [name ]
@@ -121,9 +130,6 @@ def get_yumdb_packages(cursor, yumdb_path, repo_fn):
121
130
repo = repo_fn (cursor , temp )
122
131
command .append ("R_ID='{}'" .format (repo ))
123
132
124
- # get PDID of the package
125
- pdid = pid_to_pdid .get (row [0 ])
126
-
127
133
# Update PACKAGE_DATA row
128
134
if command :
129
135
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):
140
146
command_line = vals .get ('command_line' )
141
147
if releasever or command_line :
142
148
tid = pdid_to_tid .get (pdid )
149
+ if not tid :
150
+ continue
143
151
# 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 ))
154
161
155
162
156
163
def run (input_dir = '/var/lib/dnf/' , output_file = '/var/lib/dnf/history/swdb.sqlite' ):
@@ -191,24 +198,24 @@ def bind_repo(cursor, name):
191
198
192
199
# check path to yumdb dir
193
200
if not os .path .isdir (yumdb_path ):
194
- logger .error ('Error: yumdb directory not valid' )
201
+ logger .error (_ ( 'Error: yumdb directory not valid' ) )
195
202
return False
196
203
197
204
# check path to history dir
198
205
if not os .path .isdir (history_path ):
199
- logger .write ('Error: history directory not valid' )
206
+ logger .write (_ ( 'Error: history directory not valid' ) )
200
207
return False
201
208
202
209
# check historyDB file and pick newest one
203
210
historydb_file = glob .glob (os .path .join (history_path , "history*" ))
204
211
if len (historydb_file ) < 1 :
205
- logger .write ('Error: history database file not valid' )
212
+ logger .write (_ ( 'Error: history database file not valid' ) )
206
213
return False
207
214
historydb_file .sort ()
208
215
historydb_file = historydb_file [0 ]
209
216
210
217
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' ) )
212
219
return False
213
220
214
221
tmp_output_file = output_file + '.transform'
@@ -217,7 +224,7 @@ def bind_repo(cursor, name):
217
224
historyDB = sqlite3 .connect (historydb_file )
218
225
h_cursor = historyDB .cursor ()
219
226
except :
220
- logger .error ("ERROR: unable to open database '{}'" .format (historydb_file ))
227
+ logger .error (_ ( "ERROR: unable to open the database '{}'" ) .format (historydb_file ))
221
228
return False
222
229
223
230
try :
@@ -226,7 +233,7 @@ def bind_repo(cursor, name):
226
233
database = sqlite3 .connect (tmp_output_file )
227
234
cursor = database .cursor ()
228
235
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 ))
230
237
return False
231
238
232
239
# value distribution in tables
@@ -239,7 +246,7 @@ def bind_repo(cursor, name):
239
246
240
247
ENVIRONMENTS = ['name_id' , 'name' , 'ui_name' , 'pkg_types' , 'grp_types' ]
241
248
242
- logger .info ("Transforming database. It may take a while..." )
249
+ logger .info (_ ( "Transforming the software database. It may take some time." ) )
243
250
244
251
# contruction of PACKAGE from pkgtups
245
252
h_cursor .execute ('SELECT * FROM pkgtups' )
0 commit comments