Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import platform, os, sqlite3

"""
Note: Compatible with Python 2.5+, on Darwin 9.7 (OSX 10.5+), Windows XP, Windows Vista, Server 2008, and 7.
"""

def sqliteClean(sqliteFile):
    print("Optimizing " + os.path.basename(sqliteFile) + "...")
    conn = sqlite3.connect(sqliteFile)
    cursor = conn.cursor()
    cursor.execute("vacuum")
    cursor.close()

def cleanFolder(profilesPath):
    for profileFolder in os.listdir(profilesPath):
        if os.path.isdir(os.path.join(profilesPath, profileFolder)):
            for dirItem in os.listdir(os.path.join(profilesPath, profileFolder)):
                if os.path.isfile(os.path.join(profilesPath, profileFolder, dirItem)) and os.path.splitext(dirItem)[1] == ".sqlite":
                    sqliteClean(os.path.join(profilesPath, profileFolder, dirItem))

if platform.system() == "Windows":
    ffProfile = "Mozilla\Firefox\Profiles"
    if platform.release() == "XP":
        cleanFolder(os.path.join(os.environ['APPDATA'], ffProfile))
        cleanFolder(os.path.join(os.environ['USERPROFILE'], "Local Settings\Application Data", ffProfile))
    if platform.release() == "Vista" or platform.release() == "post2008server":
        cleanFolder(os.path.join(os.environ['APPDATA'], ffProfile))
        cleanFolder(os.path.join(os.environ['LOCALAPPDATA'], ffProfile))
elif platform.system() == "Darwin":
  ffProfile = "Library/Application Support/Firefox/Profiles"
  cleanFolder(os.path.join(os.environ['HOME'], ffProfile))