1 #!/usr/bin/env python2.5
15 AUTO_FILE = DIR + "/launcher.db"
16 INDEX_FILE = DIR + "/index.html"
19 print "usage: print_db.py launcher.db -- prints a launcher.db"
20 print "usage: print_db.py -- adb pulls a launcher.db from a device"
21 print " and prints it"
23 print "The dump will be created in a directory called db_files in cwd."
24 print "This script will delete any db_files directory you have now"
28 shutil.rmtree(DIR, True)
32 print "pull_file: " + fn
33 rv = os.system("adb pull"
34 + " /data/data/com.android.launcher/databases/launcher.db"
37 print "adb pull failed"
40 def get_favorites(conn):
42 c.execute("SELECT * FROM favorites")
43 columns = [d[0] for d in c.description]
49 def print_intent(out, id, i, cell):
51 out.write("""<span class="intent" title="%s">shortcut</span>""" % (
52 cgi.escape(cell, True)
56 def print_icon(out, id, i, cell):
58 icon_fn = "icon_%d.png" % id
59 out.write("""<img src="%s">""" % ( icon_fn ))
60 f = file(DIR + "/" + icon_fn, "w")
64 def print_cell(out, id, i, cell):
66 out.write(cgi.escape(str(cell)))
69 "intent": print_intent,
74 print "process_file: " + fn
75 conn = sqlite3.connect(fn)
76 columns,rows = get_favorites(conn)
77 data = [dict(zip(columns,row)) for row in rows]
79 out = file(INDEX_FILE, "w")
82 <style type="text/css">
92 out.write("<b>Favorites table</b><br/>\n")
94 <table border=1 cellspacing=0 cellpadding=4>
99 print_functions.append(FUNCTIONS.get(col, print_cell))
100 for i in range(0,len(columns)):
102 out.write(""" <th>%s</th>
110 for i in range(0,len(row)):
112 # row[0] is always _id
113 out.write(""" <td>""")
114 print_functions[i](out, row[0], row, cell)
119 out.write("""</table>
124 for i in range(0,SCREENS):
126 for j in range(0,ROWS):
128 for k in range(0,COLUMNS):
131 screens.append(screen)
132 occupied = "occupied"
134 screen = screens[row["screen"]]
136 if row["container"] != -100:
142 for j in range(cellY, cellY+spanY):
143 for k in range(cellX, cellX+spanX):
144 screen[j][k] = occupied
145 screen[cellY][cellX] = row
147 for screen in screens:
148 out.write("<br/><b>Screen %d</b><br/>\n" % i)
149 out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
154 out.write(" <td width=%d height=%d></td>\n" %
155 (CELL_SIZE, CELL_SIZE))
156 elif cell == occupied:
159 cellX = cell["cellX"]
160 cellY = cell["cellY"]
161 spanX = cell["spanX"]
162 spanY = cell["spanY"]
163 intent = cell["intent"]
165 title = "title=\"%s\"" % cgi.escape(cell["intent"], True)
168 out.write((" <td colspan=%d rowspan=%d width=%d height=%d"
169 + " bgcolor=#dddddd align=center valign=middle %s>") % (
171 (CELL_SIZE*spanX), (CELL_SIZE*spanY),
173 itemType = cell["itemType"]
175 out.write("""<img src="icon_%d.png">\n""" % ( cell["_id"] ))
177 out.write(cgi.escape(cell["title"]) + " <br/><i>(app)</i>")
179 out.write("""<img src="icon_%d.png">\n""" % ( cell["_id"] ))
181 out.write(cgi.escape(cell["title"]) + " <br/><i>(shortcut)</i>")
183 out.write("""<i>folder</i>""")
185 out.write("""<i>live folder</i>""")
187 out.write("<i>widget %d</i><br/>\n" % cell["appWidgetId"])
188 elif itemType == 1000:
189 out.write("""<i>clock</i>""")
190 elif itemType == 1001:
191 out.write("""<i>search</i>""")
192 elif itemType == 1002:
193 out.write("""<i>photo frame</i>""")
195 out.write("<b>unknown type: %d</b>" % itemType)
198 out.write("</table>\n")
212 process_file(AUTO_FILE)
215 process_file(argv[1])
219 if __name__=="__main__":