forked from arcc/ObsLog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_empty_members_table.py
More file actions
32 lines (26 loc) · 904 Bytes
/
create_empty_members_table.py
File metadata and controls
32 lines (26 loc) · 904 Bytes
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
#! python
if __name__ == "__main__":
import os
import sys
import sqlite3 as sql
import argparse
p = argparse.ArgumentParser()
p.add_argument('-f', '--force', action='store_true', dest='f',
help='overwrite existing files')
p.add_argument('--dbroot', type=str, default='db',
help="db root path")
args = p.parse_args()
dbname = os.path.join(args.dbroot, 'members.db')
if os.path.exists(dbname) and not args.f:
print "database file already exists: {}".format(dbname)
sys.exit()
elif os.path.exists(dbname) and args.f:
os.remove(dbname)
conn = sql.connect(dbname)
c = conn.cursor()
#create table
query = '''CREATE TABLE members
(id INTEGER PRIMARY KEY, firstname text, lastname text, inst text, userdb text)'''
c.execute(query)
conn.commit()
conn.close()