本文整理汇总了Python中bleachbit.FileUtilities.execute_sqlite3方法的典型用法代码示例。如果您正苦于以下问题:Python FileUtilities.execute_sqlite3方法的具体用法?Python FileUtilities.execute_sqlite3怎么用?Python FileUtilities.execute_sqlite3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bleachbit.FileUtilities
的用法示例。
在下文中一共展示了FileUtilities.execute_sqlite3方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_chrome_history
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import execute_sqlite3 [as 别名]
def delete_chrome_history(path):
"""Clean history from History and Favicon files without affecting bookmarks"""
cols = ('url', 'title')
where = ""
ids_int = get_chrome_bookmark_ids(path)
if ids_int:
ids_str = ",".join([str(id0) for id0 in ids_int])
where = "where id not in (%s) " % ids_str
cmds = __shred_sqlite_char_columns('urls', cols, where)
cmds += __shred_sqlite_char_columns('visits')
cols = ('lower_term', 'term')
cmds += __shred_sqlite_char_columns('keyword_search_terms', cols)
ver = __get_chrome_history(path)
if ver >= 20:
# downloads, segments, segment_usage first seen in Chrome 14,
# Google Chrome 15 (database version = 20).
# Google Chrome 30 (database version 28) doesn't have full_path, but it
# does have current_path and target_path
if ver >= 28:
cmds += __shred_sqlite_char_columns(
'downloads', ('current_path', 'target_path'))
cmds += __shred_sqlite_char_columns(
'downloads_url_chains', ('url', ))
else:
cmds += __shred_sqlite_char_columns(
'downloads', ('full_path', 'url'))
cmds += __shred_sqlite_char_columns('segments', ('name',))
cmds += __shred_sqlite_char_columns('segment_usage')
FileUtilities.execute_sqlite3(path, cmds)
示例2: delete_chrome_favicons
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import execute_sqlite3 [as 别名]
def delete_chrome_favicons(path):
"""Delete Google Chrome and Chromium favicons not use in in history for bookmarks"""
path_history = os.path.join(os.path.dirname(path), 'History')
ver = __get_chrome_history(path)
cmds = ""
if ver >= 4:
# Version 4 includes Chromium 12
# Version 20 includes Chromium 14, Google Chrome 15, Google Chrome 19
# Version 22 includes Google Chrome 20
# Version 25 is Google Chrome 26
# Version 26 is Google Chrome 29
# Version 28 is Google Chrome 30
# Version 29 is Google Chrome 37
# Version 32 is Google Chrome 51
# Version 36 is Google Chrome 60
# Version 38 is Google Chrome 64
# icon_mapping
cols = ('page_url',)
where = None
if os.path.exists(path_history):
cmds += "attach database \"%s\" as History;" % path_history
where = "where page_url not in (select distinct url from History.urls)"
cmds += __shred_sqlite_char_columns('icon_mapping', cols, where)
# favicon images
cols = ('image_data', )
where = "where icon_id not in (select distinct icon_id from icon_mapping)"
cmds += __shred_sqlite_char_columns('favicon_bitmaps', cols, where)
# favicons
# Google Chrome 30 (database version 28): image_data moved to table
# favicon_bitmaps
if ver < 28:
cols = ('url', 'image_data')
else:
cols = ('url', )
where = "where id not in (select distinct icon_id from icon_mapping)"
cmds += __shred_sqlite_char_columns('favicons', cols, where)
elif 3 == ver:
# Version 3 includes Google Chrome 11
cols = ('url', 'image_data')
where = None
if os.path.exists(path_history):
cmds += "attach database \"%s\" as History;" % path_history
where = "where id not in(select distinct favicon_id from History.urls)"
cmds += __shred_sqlite_char_columns('favicons', cols, where)
else:
raise RuntimeError('%s is version %d' % (path, ver))
FileUtilities.execute_sqlite3(path, cmds)
示例3: test_get_sqlite_int
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import execute_sqlite3 [as 别名]
def test_get_sqlite_int(self):
"""Unit test for get_sqlite_int()"""
sql = """CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,value LONGVARCHAR);
INSERT INTO "meta" VALUES('version','20');"""
# create test file
filename = self.mkstemp(prefix='bleachbit-test-sqlite')
FileUtilities.execute_sqlite3(filename, sql)
self.assertExists(filename)
# run the test
ver = Special.get_sqlite_int(filename, 'select value from meta where key="version"')
self.assertEqual(ver, [20])
示例4: delete_mozilla_url_history
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import execute_sqlite3 [as 别名]
def delete_mozilla_url_history(path):
"""Delete URL history in Mozilla places.sqlite (Firefox 3 and family)"""
cmds = ""
# delete the URLs in moz_places
places_suffix = "where id in (select " \
"moz_places.id from moz_places " \
"left join moz_bookmarks on moz_bookmarks.fk = moz_places.id " \
"where moz_bookmarks.id is null); "
cols = ('url', 'rev_host', 'title')
cmds += __shred_sqlite_char_columns('moz_places', cols, places_suffix)
# delete any orphaned annotations in moz_annos
annos_suffix = "where id in (select moz_annos.id " \
"from moz_annos " \
"left join moz_places " \
"on moz_annos.place_id = moz_places.id " \
"where moz_places.id is null); "
cmds += __shred_sqlite_char_columns(
'moz_annos', ('content', ), annos_suffix)
# delete any orphaned favicons
fav_suffix = "where id not in (select favicon_id " \
"from moz_places where favicon_id is not null ); "
if __sqlite_table_exists(path, 'moz_favicons'):
cols = ('url', 'data')
cmds += __shred_sqlite_char_columns('moz_favicons', cols, fav_suffix)
# delete any orphaned history visits
cmds += "delete from moz_historyvisits where place_id not " \
"in (select id from moz_places where id is not null); "
# delete any orphaned input history
input_suffix = "where place_id not in (select distinct id from moz_places)"
cols = ('input', )
cmds += __shred_sqlite_char_columns('moz_inputhistory', cols, input_suffix)
# delete the whole moz_hosts table
# Reference: https://bugzilla.mozilla.org/show_bug.cgi?id=932036
# Reference:
# https://support.mozilla.org/en-US/questions/937290#answer-400987
if __sqlite_table_exists(path, 'moz_hosts'):
cmds += __shred_sqlite_char_columns('moz_hosts', ('host',))
cmds += "delete from moz_hosts;"
# execute the commands
FileUtilities.execute_sqlite3(path, cmds)
示例5: delete_chrome_keywords
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import execute_sqlite3 [as 别名]
def delete_chrome_keywords(path):
"""Delete keywords table in Chromium/Google Chrome 'Web Data' database"""
cols = ('short_name', 'keyword', 'favicon_url',
'originating_url', 'suggest_url')
where = "where not date_created = 0"
cmds = __shred_sqlite_char_columns('keywords', cols, where)
cmds += "update keywords set usage_count = 0;"
ver = __get_chrome_history(path, 'Web Data')
if 43 <= ver < 49:
# keywords_backup table first seen in Google Chrome 17 / Chromium 17 which is Web Data version 43
# In Google Chrome 25, the table is gone.
cmds += __shred_sqlite_char_columns('keywords_backup', cols, where)
cmds += "update keywords_backup set usage_count = 0;"
FileUtilities.execute_sqlite3(path, cmds)
示例6: delete_chrome_autofill
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import execute_sqlite3 [as 别名]
def delete_chrome_autofill(path):
"""Delete autofill table in Chromium/Google Chrome 'Web Data' database"""
cols = ('name', 'value', 'value_lower')
cmds = __shred_sqlite_char_columns('autofill', cols)
cols = ('first_name', 'middle_name', 'last_name', 'full_name')
cmds += __shred_sqlite_char_columns('autofill_profile_names', cols)
cmds += __shred_sqlite_char_columns('autofill_profile_emails', ('email',))
cmds += __shred_sqlite_char_columns('autofill_profile_phones', ('number',))
cols = ('company_name', 'street_address', 'dependent_locality',
'city', 'state', 'zipcode', 'country_code')
cmds += __shred_sqlite_char_columns('autofill_profiles', cols)
cols = (
'company_name', 'street_address', 'address_1', 'address_2', 'address_3', 'address_4',
'postal_code', 'country_code', 'language_code', 'recipient_name', 'phone_number')
cmds += __shred_sqlite_char_columns('server_addresses', cols)
FileUtilities.execute_sqlite3(path, cmds)
示例7: sqlite_clean_helper
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import execute_sqlite3 [as 别名]
def sqlite_clean_helper(self, sql, fn, clean_func, check_func=None, setup_func=None):
"""Helper for cleaning special SQLite cleaning"""
self.assertFalse(sql and fn, "sql and fn are mutually exclusive ways to create the data")
if fn:
filename = os.path.normpath(os.path.join(self.dir_base, fn))
self.assertExists(filename)
# create sqlite file
elif sql:
# create test file
filename = self.mkstemp(prefix='bleachbit-test-sqlite')
# additional setup
if setup_func:
setup_func(filename)
# before SQL creation executed, cleaning should fail
self.assertRaises(sqlite3.DatabaseError, clean_func, filename)
# create
FileUtilities.execute_sqlite3(filename, sql)
self.assertExists(filename)
else:
raise RuntimeError('neither fn nor sql supplied')
# clean the file
old_shred = options.get('shred')
options.set('shred', False, commit=False)
self.assertFalse(options.get('shred'))
clean_func(filename)
options.set('shred', True, commit=False)
self.assertTrue(options.get('shred'))
options.set('shred', old_shred, commit=False)
clean_func(filename)
self.assertExists(filename)
# check
if check_func:
check_func(self, filename)
# tear down
FileUtilities.delete(filename)
self.assertNotExists(filename)
示例8: setUp
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import execute_sqlite3 [as 别名]
def setUp(self):
"""Create test browser files."""
super(SpecialTestCase, self).setUp()
self.dir_base = self.mkdtemp(prefix='bleachbit-test-special')
self.dir_google_chrome_default = os.path.join(self.dir_base, 'google-chrome/Default/')
os.makedirs(self.dir_google_chrome_default)
# google-chrome/Default/Bookmarks
bookmark_path = os.path.join(
self.dir_google_chrome_default, 'Bookmarks')
f = open(bookmark_path, 'w')
f.write(chrome_bookmarks)
f.close()
# google-chrome/Default/Web Data
FileUtilities.execute_sqlite3(os.path.join(self.dir_google_chrome_default, 'Web Data'), chrome_webdata)
# google-chrome/Default/History
FileUtilities.execute_sqlite3(os.path.join(self.dir_google_chrome_default, 'History'), chrome_history_sql)
# google-chrome/Default/databases/Databases.db
os.makedirs(os.path.join(self.dir_google_chrome_default, 'databases'))
FileUtilities.execute_sqlite3(
os.path.join(self.dir_google_chrome_default, 'databases/Databases.db'), chrome_databases_db)
示例9: delete_chrome_databases_db
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import execute_sqlite3 [as 别名]
def delete_chrome_databases_db(path):
"""Delete remote HTML5 cookies (avoiding extension data) from the Databases.db file"""
cols = ('origin', 'name', 'description')
where = "where origin not like 'chrome-%'"
cmds = __shred_sqlite_char_columns('Databases', cols, where)
FileUtilities.execute_sqlite3(path, cmds)