]> git.saurik.com Git - cycript.git/blob - libcycript.py
Temporarily remove Number.toCYON: way too verbose.
[cycript.git] / libcycript.py
1 #!/usr/bin/python
2
3 import os
4 import sqlite3
5 import sys
6
7 system = sys.argv[1]
8 dbfile = sys.argv[2]
9 nodejs = sys.argv[3]
10 merges = sys.argv[4:]
11
12 system = int(system)
13 nodejs += '/node/lib'
14
15 keys = {}
16
17 while True:
18 line = sys.stdin.readline()
19 if line == "":
20 break
21 elif line == "\n":
22 continue
23 assert line[-1] == '\n'
24 line = line[0:-1]
25
26 pipe = line.index('|')
27 name = line[0:pipe]
28 line = line[pipe+1:]
29
30 quote = line.index('"')
31 flags = int(line[0:quote])
32 code = line[quote+1:-1]
33
34 key = (name, flags, code)
35 keys[key] = system
36
37 for db in merges:
38 with sqlite3.connect(db) as sql:
39 c = sql.cursor()
40 for name, system, flags, code in c.execute('select name, system, flags, code from cache'):
41 key = (name, flags, code)
42 keys[key] = keys.get(key, 0) | system
43
44 if os.path.exists(dbfile):
45 os.unlink(dbfile)
46
47 with sqlite3.connect(dbfile) as sql:
48 c = sql.cursor()
49
50 c.execute("create table cache (name text not null, system int not null, flags int not null, code text not null, primary key (name, system))")
51 c.execute("create table module (name text not null, flags int not null, code blob not null, primary key (name))")
52
53 for name in [js[0:-3] for js in os.listdir(nodejs) if js.endswith('.js')]:
54 with open(nodejs + '/' + name + '.js', 'r') as file:
55 code = file.read()
56 c.execute("insert into module (name, flags, code) values (?, ?, ?)", [name, 0, buffer(code)])
57
58 many = []
59 for key, system in keys.items():
60 name, flags, code = key
61 many.append((name, system, flags, code))
62 c.executemany("insert into cache (name, system, flags, code) values (?, ?, ?, ?)", many)