]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - www/webapp/uriel.py
6 allowed_items
= [ "cpu_mhz", "cpu_model", "formfactor", "lang", "model",
7 "ram_mb", "storage_mb", "system", "vendor", ]
9 class Database(object):
14 self
.connection
= sql
.connect(user
="uriel", db
=self
._name
)
19 return self
.connection
.cursor()
21 def table(self
, item
, sort
=0, consolidate
=0):
23 c
.execute("SELECT value FROM %s WHERE item = '%s'" % (self
._table
, item
,))
33 result
= "%s" % result
35 if results
.has_key(result
):
42 for i
in results
.items():
46 ret
= sorted(ret
, key
=operator
.itemgetter(1))
52 ret
.append(int("%s" % result
))
66 c
.execute("SELECT COUNT(DISTINCT(id)) FROM %s" % self
._table
)
67 self
._count
= int("%s" % c
.fetchone())
71 def get(self
, id, item
):
73 c
.execute("SELECT value FROM %s WHERE id = '%s' AND item = '%s'" % \
74 (self
._table
, id, item
,))
75 ret
= c
.fetchall() or None
79 def set(self
, id, item
, value
):
81 if self
.get(id, item
):
82 c
.execute("UPDATE %s SET value = '%s' WHERE id = '%s' AND item = '%s'" % \
83 (self
._table
, value
, id, item
,))
85 c
.execute("INSERT INTO %s(id, item, value) VALUES('%s', '%s', '%s')" % \
86 (self
._table
, id, item
, value
))