diff --git a/lib/entropy/db/sql.py b/lib/entropy/db/sql.py index 1e6c82074..0aef6fbc1 100644 --- a/lib/entropy/db/sql.py +++ b/lib/entropy/db/sql.py @@ -35,6 +35,12 @@ from entropy.db.exceptions import Warning, Error, InterfaceError, \ DatabaseError, DataError, OperationalError, IntegrityError, \ InternalError, ProgrammingError, NotSupportedError +def _get_main_thread(): + for _thread in threading.enumerate(): + if _thread.name == "MainThread": + return _thread + raise AssertionError("Where the fuck is the MainThread?") + class SQLConnectionWrapper(object): @@ -591,12 +597,6 @@ class EntropySQLRepository(EntropyRepositoryBase): # "UPDATE OR REPLACE" dialect _UPDATE_OR_REPLACE = None - def _get_main_thread(): - for _thread in threading.enumerate(): - if _thread.name == "MainThread": - return _thread - raise AssertionError("Where the fuck is the MainThread?") - _MAIN_THREAD = _get_main_thread() def __init__(self, db, read_only, skip_checks, indexing, @@ -1017,6 +1017,131 @@ class EntropySQLRepository(EntropyRepositoryBase): """ raise NotImplementedError() + def _addCompileFlags(self, chost, cflags, cxxflags): + """ + NOTE: only working with _baseinfo_extrainfo_2010 disabled + + Add package Compiler flags used to repository. + Return its identifier (idflags). + + @param chost: CHOST string + @type chost: string + @param cflags: CFLAGS string + @type cflags: string + @param cxxflags: CXXFLAGS string + @type cxxflags: string + @return: Compiler flags triple identifier (idflags) + @rtype: int + """ + cur = self._cursor().execute(""" + INSERT INTO flags VALUES (NULL,?,?,?) + """, (chost, cflags, cxxflags,)) + return cur.lastrowid + + def _areCompileFlagsAvailable(self, chost, cflags, cxxflags): + """ + NOTE: only working with _baseinfo_extrainfo_2010 disabled + Return whether given Compiler FLAGS are available in repository. + + @param chost: CHOST flag + @type chost: string + @param cflags: CFLAGS flag + @type cflags: string + @param cxxflags: CXXFLAGS flag + @type cxxflags: string + @return: availability (True if available) + @rtype: bool + """ + cur = self._cursor().execute(""" + SELECT idflags FROM flags WHERE chost = (?) + AND cflags = (?) AND cxxflags = (?) LIMIT 1 + """, + (chost, cflags, cxxflags,) + ) + result = cur.fetchone() + if result: + return result[0] + return -1 + + def _isLicenseAvailable(self, pkglicense): + """ + NOTE: only working with _baseinfo_extrainfo_2010 disabled + + Return whether license metdatatum (NOT license name) is available + in repository. + + @param pkglicense: "license" package metadatum (returned by + retrieveLicense) + @type pkglicense: string + @return: "license" metadatum identifier (idlicense) + @rtype: int + """ + if not entropy.tools.is_valid_string(pkglicense): + pkglicense = ' ' + + cur = self._cursor().execute(""" + SELECT idlicense FROM licenses WHERE license = (?) LIMIT 1 + """, (pkglicense,)) + result = cur.fetchone() + + if result: + return result[0] + return -1 + + def _addLicense(self, pkglicense): + """ + NOTE: only working with _baseinfo_extrainfo_2010 disabled + + Add package license name string to repository. + Return its identifier (idlicense). + + @param pkglicense: license name string + @type pkglicense: string + @return: license name identifier (idlicense) + @rtype: int + """ + if not entropy.tools.is_valid_string(pkglicense): + pkglicense = ' ' # workaround for broken license entries + cur = self._cursor().execute(""" + INSERT INTO licenses VALUES (NULL,?) + """, (pkglicense,)) + return cur.lastrowid + + def _isCategoryAvailable(self, category): + """ + NOTE: only working with _baseinfo_extrainfo_2010 disabled + Return whether given category is available in repository. + + @param category: category name + @type category: string + @return: availability (True if available) + @rtype: bool + """ + cur = self._cursor().execute(""" + SELECT idcategory FROM categories WHERE category = (?) LIMIT 1 + """, (category,)) + result = cur.fetchone() + if result: + return result[0] + return -1 + + def _addCategory(self, category): + """ + NOTE: only working with _baseinfo_extrainfo_2010 disabled + + Add package category string to repository. Return its identifier + (idcategory). + + @param category: name of the category to add + @type category: string + @return: category identifier (idcategory) + @rtype: int + """ + cur = self._cursor().execute(""" + INSERT INTO categories VALUES (NULL,?) + """, (category,)) + return cur.lastrowid + def _addPackage(self, pkg_data, revision = -1, package_id = None, formatted_content = False): """ @@ -1037,19 +1162,19 @@ class EntropySQLRepository(EntropyRepositoryBase): idflags = None if not _baseinfo_extrainfo_2010: # create new category if it doesn't exist - catid = self.__isCategoryAvailable(pkg_data['category']) + catid = self._isCategoryAvailable(pkg_data['category']) if catid == -1: - catid = self.__addCategory(pkg_data['category']) + catid = self._addCategory(pkg_data['category']) # create new license if it doesn't exist - licid = self.__isLicenseAvailable(pkg_data['license']) + licid = self._isLicenseAvailable(pkg_data['license']) if licid == -1: - licid = self.__addLicense(pkg_data['license']) + licid = self._addLicense(pkg_data['license']) - idflags = self.__areCompileFlagsAvailable(pkg_data['chost'], + idflags = self._areCompileFlagsAvailable(pkg_data['chost'], pkg_data['cflags'], pkg_data['cxxflags']) if idflags == -1: - idflags = self.__addCompileFlags(pkg_data['chost'], + idflags = self._addCompileFlags(pkg_data['chost'], pkg_data['cflags'], pkg_data['cxxflags']) idprotect = self._isProtectAvailable(pkg_data['config_protect']) @@ -3866,14 +3991,6 @@ class EntropySQLRepository(EntropyRepositoryBase): return False return True - def acceptLicense(self, license_name): - """ - Reimplemented from EntropyRepositoryBase. - Needs to call superclass method. This is a stub, - please implement the SQL logic. - """ - super(EntropySQLRepository, self).acceptLicense(license_name) - def isSystemPackage(self, package_id): """ Reimplemented from EntropyRepositoryBase. diff --git a/lib/entropy/db/sqlite.py b/lib/entropy/db/sqlite.py index 788800fc0..c2d734755 100644 --- a/lib/entropy/db/sqlite.py +++ b/lib/entropy/db/sqlite.py @@ -559,21 +559,10 @@ class EntropySQLiteRepository(EntropySQLRepository): DELETE FROM packagedownloads WHERE idpackage = (?)""", (package_id,)) - def __addCategory(self, category): + def _addCategory(self, category): """ - NOTE: only working with _baseinfo_extrainfo_2010 disabled - - Add package category string to repository. Return its identifier - (idcategory). - - @param category: name of the category to add - @type category: string - @return: category identifier (idcategory) - @rtype: int + Reimplemented from EntropySQLRepository. """ - cur = self._cursor().execute(""" - INSERT INTO categories VALUES (NULL,?) - """, (category,)) self._clearLiveCache("retrieveCategory") self._clearLiveCache("searchNameCategory") self._clearLiveCache("retrieveKeySlot") @@ -582,47 +571,7 @@ class EntropySQLiteRepository(EntropySQLRepository): self._clearLiveCache("searchKeySlotTag") self._clearLiveCache("retrieveKeySlotAggregated") self._clearLiveCache("getStrictData") - return cur.lastrowid - - def __addLicense(self, pkglicense): - """ - NOTE: only working with _baseinfo_extrainfo_2010 disabled - - Add package license name string to repository. - Return its identifier (idlicense). - - @param pkglicense: license name string - @type pkglicense: string - @return: license name identifier (idlicense) - @rtype: int - """ - if not entropy.tools.is_valid_string(pkglicense): - pkglicense = ' ' # workaround for broken license entries - cur = self._cursor().execute(""" - INSERT INTO licenses VALUES (NULL,?) - """, (pkglicense,)) - return cur.lastrowid - - def __addCompileFlags(self, chost, cflags, cxxflags): - """ - NOTE: only working with _baseinfo_extrainfo_2010 disabled - - Add package Compiler flags used to repository. - Return its identifier (idflags). - - @param chost: CHOST string - @type chost: string - @param cflags: CFLAGS string - @type cflags: string - @param cxxflags: CXXFLAGS string - @type cxxflags: string - @return: Compiler flags triple identifier (idflags) - @rtype: int - """ - cur = self._cursor().execute(""" - INSERT INTO flags VALUES (NULL,?,?,?) - """, (chost, cflags, cxxflags,)) - return cur.lastrowid + return super(EntropySQLiteRepository, self)._addCategory(category) def setCategory(self, package_id, category): """ @@ -635,10 +584,10 @@ class EntropySQLiteRepository(EntropySQLRepository): """, (category, package_id,)) else: # create new category if it doesn't exist - catid = self.__isCategoryAvailable(category) + catid = self._isCategoryAvailable(category) if catid == -1: # create category - catid = self.__addCategory(category) + catid = self._addCategory(category) self._cursor().execute(""" UPDATE baseinfo SET idcategory = (?) WHERE idpackage = (?) """, (catid, package_id,)) @@ -1306,74 +1255,6 @@ class EntropySQLiteRepository(EntropySQLRepository): flags = ("N/A", "N/A", "N/A") return flags - def __isCategoryAvailable(self, category): - """ - NOTE: only working with _baseinfo_extrainfo_2010 disabled - Return whether given category is available in repository. - - @param category: category name - @type category: string - @return: availability (True if available) - @rtype: bool - """ - cur = self._cursor().execute(""" - SELECT idcategory FROM categories WHERE category = (?) LIMIT 1 - """, (category,)) - result = cur.fetchone() - if result: - return result[0] - return -1 - - def __isLicenseAvailable(self, pkglicense): - """ - NOTE: only working with _baseinfo_extrainfo_2010 disabled - - Return whether license metdatatum (NOT license name) is available - in repository. - - @param pkglicense: "license" package metadatum (returned by - retrieveLicense) - @type pkglicense: string - @return: "license" metadatum identifier (idlicense) - @rtype: int - """ - if not entropy.tools.is_valid_string(pkglicense): - pkglicense = ' ' - - cur = self._cursor().execute(""" - SELECT idlicense FROM licenses WHERE license = (?) LIMIT 1 - """, (pkglicense,)) - result = cur.fetchone() - - if result: - return result[0] - return -1 - - def __areCompileFlagsAvailable(self, chost, cflags, cxxflags): - """ - NOTE: only working with _baseinfo_extrainfo_2010 disabled - Return whether given Compiler FLAGS are available in repository. - - @param chost: CHOST flag - @type chost: string - @param cflags: CFLAGS flag - @type cflags: string - @param cxxflags: CXXFLAGS flag - @type cxxflags: string - @return: availability (True if available) - @rtype: bool - """ - cur = self._cursor().execute(""" - SELECT idflags FROM flags WHERE chost = (?) - AND cflags = (?) AND cxxflags = (?) LIMIT 1 - """, - (chost, cflags, cxxflags,) - ) - result = cur.fetchone() - if result: - return result[0] - return -1 - def searchLicense(self, keyword, just_id = False): """ Reimplemented from EntropySQLRepository.