📄 sqlitecache.c
字号:
}static voidupdate_other_info_clean (UpdateInfo *update_info){ UpdateOtherInfo *info = (UpdateOtherInfo *) update_info; if (info->pkg_handle) sqlite3_finalize (info->pkg_handle); if (info->changelog_handle) sqlite3_finalize (info->changelog_handle);}static voidwrite_other_package_to_db (UpdateInfo *update_info, Package *package){ UpdateOtherInfo *info = (UpdateOtherInfo *) update_info; yum_db_package_ids_write (update_info->db, info->pkg_handle, package); yum_db_changelog_write (update_info->db, info->changelog_handle, package);}/*****************************************************************************/static voidprogress_cb (UpdateInfo *update_info){ PyObject *progress = (PyObject *) update_info->python_callback; PyObject *repoid = (PyObject *) update_info->user_data; PyObject *args; PyObject *result; Py_INCREF(repoid); args = PyTuple_New (3); PyTuple_SET_ITEM (args, 0, PyInt_FromLong (update_info->packages_seen)); PyTuple_SET_ITEM (args, 1, PyInt_FromLong (update_info->count_from_md)); PyTuple_SET_ITEM (args, 2, repoid); result = PyEval_CallObject (progress, args); Py_DECREF (args); Py_XDECREF (result);}static voidupdate_package_cb (Package *p, gpointer user_data){ UpdateInfo *update_info = (UpdateInfo *) user_data; g_hash_table_insert (update_info->all_packages, g_string_chunk_insert (update_info->package_ids_chunk, p->pkgId), GINT_TO_POINTER (1)); if (g_hash_table_lookup (update_info->current_packages, p->pkgId) == NULL) { update_info->write_package (update_info, p); update_info->add_count++; } if (update_info->count_from_md > 0 && update_info->python_callback) { update_info->packages_seen++; progress_cb (update_info); }}static char *update_packages (UpdateInfo *update_info, const char *md_filename, const char *checksum, gpointer python_callback, gpointer user_data, GError **err){ char *db_filename; db_filename = yum_db_filename (md_filename); update_info->db = yum_db_open (db_filename, checksum, update_info->create_tables, err); if (*err) goto cleanup; if (!update_info->db) return db_filename; update_info_init (update_info, err); if (*err) goto cleanup; update_info->python_callback = python_callback; update_info->user_data = user_data; update_info->info_init (update_info, update_info->db, err); if (*err) goto cleanup; sqlite3_exec (update_info->db, "BEGIN", NULL, NULL, NULL); update_info->xml_parse (md_filename, count_cb, update_package_cb, update_info, err); if (*err) goto cleanup; sqlite3_exec (update_info->db, "COMMIT", NULL, NULL, NULL); update_info_remove_old_entries (update_info); yum_db_dbinfo_update (update_info->db, checksum, err); cleanup: update_info->info_clean (update_info); update_info_done (update_info, err); if (update_info->db) sqlite3_close (update_info->db); if (*err) { g_free (db_filename); db_filename = NULL; } return db_filename;}/*********************************************************************/static gbooleanpy_parse_args (PyObject *args, const char **md_filename, const char **checksum, PyObject **log, PyObject **progress, PyObject **repoid){ PyObject *callback; if (!PyArg_ParseTuple (args, "ssOO", md_filename, checksum, &callback, repoid)) return FALSE; if (PyObject_HasAttrString (callback, "log")) { *log = PyObject_GetAttrString (callback, "log"); if (!PyCallable_Check (*log)) { PyErr_SetString (PyExc_TypeError, "parameter must be callable"); return FALSE; } } if (PyObject_HasAttrString (callback, "progressbar")) { *progress = PyObject_GetAttrString (callback, "progressbar"); if (!PyCallable_Check (*progress)) { PyErr_SetString (PyExc_TypeError, "parameter must be callable"); return FALSE; } } return TRUE;}static voidlog_cb (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data){ PyObject *callback = (PyObject *) user_data; int level; PyObject *args; PyObject *result; if (!callback) return; args = PyTuple_New (2); switch (log_level) { case G_LOG_LEVEL_DEBUG: level = 2; break; case G_LOG_LEVEL_MESSAGE: level = 1; break; case G_LOG_LEVEL_WARNING: level = 0; break; case G_LOG_LEVEL_CRITICAL: default: level = -1; break; } PyTuple_SET_ITEM (args, 0, PyInt_FromLong (level)); PyTuple_SET_ITEM (args, 1, PyString_FromString (message)); result = PyEval_CallObject (callback, args); Py_DECREF (args); Py_XDECREF (result);}static PyObject *py_update (PyObject *self, PyObject *args, UpdateInfo *update_info){ const char *md_filename = NULL; const char *checksum = NULL; PyObject *log = NULL; PyObject *progress = NULL; PyObject *repoid = NULL; guint log_id = 0; char *db_filename; PyObject *ret = NULL; GError *err = NULL; if (!py_parse_args (args, &md_filename, &checksum, &log, &progress, &repoid)) return NULL; GLogLevelFlags level = G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_DEBUG; log_id = g_log_set_handler (NULL, level, log_cb, log); db_filename = update_packages (update_info, md_filename, checksum, progress, repoid, &err); g_log_remove_handler (NULL, log_id); if (db_filename) { ret = PyString_FromString (db_filename); g_free (db_filename); } else { PyErr_SetString (PyExc_TypeError, err->message); g_error_free (err); } return ret;}static PyObject *py_update_primary (PyObject *self, PyObject *args){ PackageWriterInfo info; memset (&info, 0, sizeof (PackageWriterInfo)); info.update_info.info_init = package_writer_info_init; info.update_info.info_clean = package_writer_info_clean; info.update_info.create_tables = yum_db_create_primary_tables; info.update_info.write_package = write_package_to_db; info.update_info.xml_parse = yum_xml_parse_primary; return py_update (self, args, (UpdateInfo *) &info);}static PyObject *py_update_filelist (PyObject *self, PyObject *args){ FileListInfo info; memset (&info, 0, sizeof (FileListInfo)); info.update_info.info_init = update_filelist_info_init; info.update_info.info_clean = update_filelist_info_clean; info.update_info.create_tables = yum_db_create_filelist_tables; info.update_info.write_package = write_filelist_package_to_db; info.update_info.xml_parse = yum_xml_parse_filelists; return py_update (self, args, (UpdateInfo *) &info);}static PyObject *py_update_other (PyObject *self, PyObject *args){ UpdateOtherInfo info; memset (&info, 0, sizeof (UpdateOtherInfo)); info.update_info.info_init = update_other_info_init; info.update_info.info_clean = update_other_info_clean; info.update_info.create_tables = yum_db_create_other_tables; info.update_info.write_package = write_other_package_to_db; info.update_info.xml_parse = yum_xml_parse_other; return py_update (self, args, (UpdateInfo *) &info);}static PyMethodDef SqliteMethods[] = { {"update_primary", py_update_primary, METH_VARARGS, "Parse YUM primary.xml metadata."}, {"update_filelist", py_update_filelist, METH_VARARGS, "Parse YUM filelists.xml metadata."}, {"update_other", py_update_other, METH_VARARGS, "Parse YUM other.xml metadata."}, {NULL, NULL, 0, NULL}};PyMODINIT_FUNCinit_sqlitecache (void){ PyObject * m, * d; m = Py_InitModule ("_sqlitecache", SqliteMethods); d = PyModule_GetDict(m); PyDict_SetItemString(d, "DBVERSION", PyInt_FromLong(YUM_SQLITE_CACHE_DBVERSION));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -