Welcome, guest | Sign In | My Account | Store | Cart

Walks through the all the Firefox profiles in current user account and cleans all *.sqlite files with "vacuum". It makes firefox faster then often. Should work on Linux, too, when properly changed constants.

For: python 2.6 (2.5+sqlite3), FF 3.5

Python, 51 lines
 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*- 

import os, sqlite3
"""Walks through the all the Firefox profiles in current user account and cleans all
*.sqlite files with "vacuum". It makes firefox faster then often. Should work on Linux, too,
when properly changed constants."""

# -------------- constants -----------------------------------------

systemEncoding="mbcs"

profileUser= unicode(os.environ["USERPROFILE"], systemEncoding)
profileApp = unicode(os.environ["APPDATA"], systemEncoding) + ur"\Mozilla\Firefox\Profiles"


# -------------- functions -----------------------------------------

def searchProfil(profileApp):
    "all firefox profiles"
    for profile in os.listdir(profileApp):
        profileFull=os.path.join(profileApp, profile)
        searchSqlite(profileFull)
        

def searchSqlite(profile):
    "all sqlite file in each firefox profile"
    sq=[os.path.join(profile,s) for s in os.listdir(profile) if s.endswith(".sqlite")]
    print "\n..."+profile[len(profileUser):]
    for s in  sq:
        dirName, fileName=os.path.split(s)
        conn = sqlite3.connect(s)
        oldSize=os.path.getsize(s)
        print fileName+":",
        try: 
            c=conn.cursor()
            c.execute("VACUUM")  # this is the thing
            c.close()
            print "done.",
            print "%.1f%%" % (os.path.getsize(s)*1.0/oldSize*100)
            
        except:
            print "error."

# ----------------- main -------------------------------------------     

if __name__=="__main__":

    if os.path.isdir(profileApp):
        searchProfil(profileApp)
    else:
        print "Not exists:", profileApp

3 comments

Vince Spicer 14 years, 9 months ago  # | flag

Linux version Recipe 576843

Michal Niklas 14 years, 9 months ago  # | flag

This recipe do not work on non-english version of Windows!

On my Polish version of Windows Firefox profile is saved in Dane aplikacji while this recipe looks at Application Data.

Instead of:

    profilApp = os.path.join(profilUser,profilAppMain)

use:

    profilApp = os.environ['APPDATA'] + ur"\Mozilla\Firefox\Profiles"

I have found info about APPDATA on How to find Windows "Application data" directory??

peekaa (author) 14 years, 9 months ago  # | flag

thanks, updated together with other small things (better output)

Created by peekaa on Wed, 15 Jul 2009 (MIT)
Python recipes (4591)
peekaa's recipes (2)

Required Modules

Other Information and Tasks