1 #!/usr/bin/env python2.5
16 AUTO_FILE = DIR + "/launcher.db"
17 INDEX_FILE = DIR + "/index.html"
20 print "usage: print_db.py launcher.db -- prints a launcher.db"
21 print "usage: print_db.py -- adb pulls a launcher.db from a device"
22 print " and prints it"
24 print "The dump will be created in a directory called db_files in cwd."
25 print "This script will delete any db_files directory you have now"
29 shutil.rmtree(DIR, True)
33 print "pull_file: " + fn
34 rv = os.system("adb pull"
35 + " /data/data/com.android.launcher/databases/launcher.db"
38 print "adb pull failed"
41 def get_favorites(conn):
43 c.execute("SELECT * FROM favorites")
44 columns = [d[0] for d in c.description]
50 def print_intent(out, id, i, cell):
52 out.write("""<span class="intent" title="%s">shortcut</span>""" % (
53 cgi.escape(cell, True)
57 def print_icon(out, id, i, cell):
59 icon_fn = "icon_%d.png" % id
60 out.write("""<img src="%s">""" % ( icon_fn ))
61 f = file(DIR + "/" + icon_fn, "w")
65 def print_cell(out, id, i, cell):
67 out.write(cgi.escape(str(cell)))
70 "intent": print_intent,
74 def render_cell_info(out, cell, occupied):
76 out.write(" <td width=%d height=%d></td>\n" %
77 (CELL_SIZE, CELL_SIZE))
78 elif cell == occupied:
85 intent = cell["intent"]
87 title = "title=\"%s\"" % cgi.escape(cell["intent"], True)
90 out.write((" <td colspan=%d rowspan=%d width=%d height=%d"
91 + " bgcolor=#dddddd align=center valign=middle %s>") % (
93 (CELL_SIZE*spanX), (CELL_SIZE*spanY),
95 itemType = cell["itemType"]
97 out.write("""<img src="icon_%d.png">\n""" % ( cell["_id"] ))
99 out.write(cgi.escape(cell["title"]) + " <br/><i>(app)</i>")
101 out.write("""<img src="icon_%d.png">\n""" % ( cell["_id"] ))
103 out.write(cgi.escape(cell["title"]) + " <br/><i>(shortcut)</i>")
105 out.write("""<i>folder</i>""")
107 out.write("""<i>live folder</i>""")
109 out.write("<i>widget %d</i><br/>\n" % cell["appWidgetId"])
110 elif itemType == 1000:
111 out.write("""<i>clock</i>""")
112 elif itemType == 1001:
113 out.write("""<i>search</i>""")
114 elif itemType == 1002:
115 out.write("""<i>photo frame</i>""")
117 out.write("<b>unknown type: %d</b>" % itemType)
120 def process_file(fn):
121 print "process_file: " + fn
122 conn = sqlite3.connect(fn)
123 columns,rows = get_favorites(conn)
124 data = [dict(zip(columns,row)) for row in rows]
126 out = file(INDEX_FILE, "w")
129 <style type="text/css">
139 out.write("<b>Favorites table</b><br/>\n")
141 <table border=1 cellspacing=0 cellpadding=4>
146 print_functions.append(FUNCTIONS.get(col, print_cell))
147 for i in range(0,len(columns)):
149 out.write(""" <th>%s</th>
157 for i in range(0,len(row)):
159 # row[0] is always _id
160 out.write(""" <td>""")
161 print_functions[i](out, row[0], row, cell)
166 out.write("""</table>
171 for i in range(0, HOTSEAT_SIZE):
174 if row["container"] != -101:
176 screen = row["screen"]
177 hotseat[screen] = row
178 out.write("<br/><b>Hotseat</b><br/>\n")
179 out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
181 render_cell_info(out, cell, None)
182 out.write("</table>\n")
186 for i in range(0,SCREENS):
188 for j in range(0,ROWS):
190 for k in range(0,COLUMNS):
193 screens.append(screen)
194 occupied = "occupied"
196 screen = screens[row["screen"]]
198 if row["container"] != -100:
204 for j in range(cellY, cellY+spanY):
205 for k in range(cellX, cellX+spanX):
206 screen[j][k] = occupied
207 screen[cellY][cellX] = row
209 for screen in screens:
210 out.write("<br/><b>Screen %d</b><br/>\n" % i)
211 out.write("<table class=layout border=1 cellspacing=0 cellpadding=4>\n")
215 render_cell_info(out, cell, occupied)
217 out.write("</table>\n")
231 process_file(AUTO_FILE)
234 process_file(argv[1])
238 if __name__=="__main__":