-
Notifications
You must be signed in to change notification settings - Fork 1
/
add-file.py
38 lines (32 loc) · 996 Bytes
/
add-file.py
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
import argparse
import pathlib
import sqlite3
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('package_name')
parser.add_argument('href')
parser.add_argument('hash_name')
parser.add_argument('hash_value')
return parser.parse_args()
def main():
args = parse_args()
packages_sql = pathlib.Path('packages.sql').resolve()
cnx = sqlite3.connect(':memory:')
with packages_sql.open() as f:
cnx.executescript(f.read())
with cnx:
cnx.execute('''
insert into packages (name, hash_name, hash_value, href)
values (:name, :hash_name, :hash_value, :href)
''', {
'name': args.package_name,
'hash_name': args.hash_name,
'hash_value': args.hash_value,
'href': args.href
})
with packages_sql.open('w') as f:
for line in cnx.iterdump():
f.write(f'{line}\n')
cnx.close()
if __name__ == '__main__':
main()