forked from g-sherman/GeoApt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme_database.py
67 lines (56 loc) · 2.3 KB
/
theme_database.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright (C) 2008-2010 Gary Sherman
# Licensed under the terms of GNU GPL 2
from theme import *
# Schema for the theme database
class ThemeDatabase:
def __init__(self, db=None):
self.db = db
@classmethod
def create_schema(cls, db):
print "Creating schema in SQLITE3 database\n"
cursor = db.cursor()
cursor.execute("create table themes (id integer primary key autoincrement, name text, path text, parent_id int)")
cursor.close()
@classmethod
def add_folder(cls, db, folder, parent_id=0):
print "Adding folder to database\n"
cursor = db.cursor()
cursor.execute("insert into themes (name, parent_id) values('%s', %i)" % (folder, parent_id))
db.commit()
return cursor.lastrowid
@classmethod
def add_theme(cls, db, theme_name, theme_path, parent_id):
print "Adding theme to database\n"
cursor = db.cursor()
cursor.execute("insert into themes (name, path, parent_id) values('%s','%s', %i)" % (theme_name, theme_path, parent_id))
db.commit()
return cursor.lastrowid
@classmethod
def folder_list(cls, db):
# create a list containing the theme folders
cursor = db.cursor()
# get the list of theme folders (rows with parent_id = 0)
cursor.execute("select id, name from themes where parent_id = 0 order by name")
folder_list = list()
for row in cursor:
folder_list.append(Theme(row[0], row[1]))
cursor.close()
return folder_list
@classmethod
def theme_list(cls, db):
# create a dict containing the theme folder and its themes
cursor = db.cursor()
# get the list of theme folders (rows with parent_id = 0)
cursor.execute("select id, name from themes where parent_id = 0 order by name")
theme_list = dict()
theme_cursor = db.cursor()
for row in cursor:
print row
theme_cursor.execute("select id, name, path from themes where parent_id = %s" % row[0])
child_themes = list()
for t_row in theme_cursor:
child_themes.append(Theme(t_row[0], t_row[1], t_row[2]))
theme_list[row[0]] = child_themes
theme_cursor.close()
cursor.close()
return theme_list