[cvs-annodex] commit (/annodex):
cmmlwiki/branches/diddl3/cgi/cmmlwiki.py
cmmlwiki/branches/diddl3/www/cmmlwiki/admin.html
alexander
nobody at lists.annodex.net
Fri Sep 23 16:41:52 EST 2005
Update of /annodex (new revision 1450)
Modified files:
cmmlwiki/branches/diddl3/cgi/cmmlwiki.py
cmmlwiki/branches/diddl3/www/cmmlwiki/admin.html
Log Message:
DB Init improved.
Modified: cmmlwiki/branches/diddl3/cgi/cmmlwiki.py
===================================================================
--- cmmlwiki/branches/diddl3/cgi/cmmlwiki.py 2005-09-23 02:38:53 UTC (rev 1449)
+++ cmmlwiki/branches/diddl3/cgi/cmmlwiki.py 2005-09-23 06:41:52 UTC (rev 1450)
@@ -21,7 +21,7 @@
"""
db = "/var/local/lib/cmmlwiki/cmmlwiki.db"
-db_tables = ["mediafiles","projects","clips"]
+db_tables = ["maxix","mediafiles","projects","clips"]
db_tables_rev=[]
for i in db_tables:
db_tables_rev.append(i)
@@ -40,7 +40,7 @@
tracelog = True
-upload_dir = "/var/www/cmmlwiki-projects/media"
+media_dir = "/var/www/cmmlwiki-projects/media"
#=========================================================================
#===
@@ -244,8 +244,43 @@
#=== ADMIN
#===
#=========================================================================
+def setup():
+ def status(dir):
+ print "( %s ) " % dir
+ ok = "False"
+ if os.path.exists (dir):
+ print "exists"
+ ok = "True"
+ if os.access(dir,os.W_OK):
+ print "and is writeable.<br>"
+ else:
+ print "but is not writeable!. Please change permissions on <b> %s </b><br>" % dir
+ else:
+ print "doesn't exist! Please create the writable directory <b> %s </b><br>" % dir
+ return ok
+
+ all_ok = "True"
+ html_head("System setup")
+ print "Checking if defined directories exist and are writeable...<br><br>"
+
+ print "The database directory "
+ db_dir = os.path.dirname(db)
+ all_ok = all_ok and status(db_dir)
+
+ print "The media directory "
+ all_ok = all_ok and status(media_dir)
+
+ if all_ok:
+ print "<br>You're all set. Initialize the data repository now!<br>"
+
+ html_foot()
+#=========================================================================
def init_db():
db_tables_create={}
+ db_tables_create["maxix"]="""
+ CREATE TABLE maxix (
+ ix INTEGER NOT NULL
+ )"""
db_tables_create["mediafiles"]="""
CREATE TABLE mediafiles (
ixm INTEGER PRIMARY KEY,
@@ -259,12 +294,6 @@
name VARCHAR(80) UNIQUE,
ixm INTEGER
)"""
-# db_tables_create["sources"]="""
-# CREATE TABLE sources (
-# ixs INTEGER PRIMARY KEY,
-# ixp INTEGER,
-# path VARCHAR(256)
-# )"""
db_tables_create["heads"]="""
CREATE TABLE heads (
ixh INTEGER PRIMARY KEY,
@@ -284,20 +313,30 @@
img_src VARCHAR(80),
desc VARCHAR(256)
)"""
- if (not os.path.exists (db)):
- error("DB file '"+db+"' doesn't existi yet.")
+# if (not os.path.exists (db)):
+# error("DB file '"+db+"' doesn't existi yet.")
html_head ("DB initialisation")
+ print "Dropping the database..."
+# print "Dropping existing database tables..."
+# for tab in db_tables_rev:
+# print "<p>"+tab+"..."
+# try:
+# cur.execute('DROP TABLE %s' % tab)
+# except:
+# pass
+# print "dropped.</p>"
+ try:
+ if os.path.exists(db):
+ os.remove(db)
+ print "done.<br>"
+ except:
+ error("Error removing the db file ( %s )!")
+
+ print "Recreating database tables..."
+ #Opening the db should create it
con = sqlite.connect(db,autocommit=1)
cur = con.cursor()
- print "Dropping existing database tables..."
- for tab in db_tables_rev:
- print "<p>"+tab+"..."
- try:
- cur.execute('DROP TABLE %s' % tab)
- except:
- pass
- print "dropped.</p>"
- print "Recreating database tables..."
+
for tab in db_tables:
try:
print "<p>"+tab+"..."
@@ -306,40 +345,19 @@
print "created.</p>"
except KeyError:
print "Create statement not found"
-# # sources
-# sql = """CREATE TABLE sources (
-# ixs INTEGER PRIMARY KEY,
-# ixp INTEGER,
-# path VARCHAR(256)
-# )"""
-# cur.execute(sql)
-# # heads
-# sql = """CREATE TABLE heads (
-# ixh INTEGER PRIMARY KEY,
-# ixp INTEGER,
-# id VARCHAR(20),
-# title VARCHAR(80)
-# )"""
-# cur.execute(sql)
-# # clips
-# sql = """CREATE TABLE clips (
-# ixc INTEGER PRIMARY KEY,
-# ixp INTEGER,
-# start_time VARCHAR(20),
-# end_time VARCHAR(20),
-# id VARCHAR(20),
-# a_href VARCHAR(80),
-# a_text VARCHAR(256),
-# img_src VARCHAR(80),
-# desc VARCHAR(256)
-# )"""
-# cur.execute(sql)
+
+ print "Initialising database..."
+ sql = "INSERT into maxix VALUES (0);"
+ cur.execute(sql)
+ print "done."
+
html_foot()
#=========================================================================
def check_db():
html_head("DB check")
con = sqlite.connect(db)
cur = con.cursor()
+
sql = 'SELECT count(*) AS rec_count FROM maxix'
cur.execute(sql)
sqlcount=-1
@@ -353,6 +371,7 @@
print "OK"
else:
print "broken"
+
sql = 'SELECT count(*) AS rec_count FROM maxix'
cur.execute(sql)
sqlcount=-1
@@ -366,10 +385,11 @@
print "OK"
else:
print "broken"
+
# more to test:
# is every key <= then the maxix value?
# referencial integrity: doe sthe forain key exist in other table?
- # whatever the db used isnot able to enforce
+ # whatever the db used isnot able to enforce...
html_foot()
#=========================================================================
def dump_db():
@@ -441,17 +461,17 @@
# tracelog("NOTempty: filename:",len(fileitem))
if not fileitem.file: return
ixm = new_ix_s()
- media_dir = os.path.join(upload_dir, ixm)
+ media_upload_dir = os.path.join(media_dir, ixm)
con = sqlite.connect(db,autocommit=1)
cur = con.cursor()
try:
- os.makedirs(media_dir, mode=0777)
+ os.makedirs(media_upload_dir, mode=0777)
except:
- error("Media upload directory "+upload_dir+" couldn't be created.\
+ error("Media upload directory "+media_dir+" couldn't be created.\
Please check manually.")
try:
- file_name = os.path.join(media_dir, fileitem.filename)
+ file_name = os.path.join(media_upload_dir, fileitem.filename)
file_name_temp = file_name+".uploading"
sql = 'INSERT INTO mediafiles values ("%s","%s","%s","%s")'\
% (ixm, fileitem.filename, file_name, time.asctime())
Modified: cmmlwiki/branches/diddl3/www/cmmlwiki/admin.html
===================================================================
--- cmmlwiki/branches/diddl3/www/cmmlwiki/admin.html 2005-09-23 02:38:53 UTC (rev 1449)
+++ cmmlwiki/branches/diddl3/www/cmmlwiki/admin.html 2005-09-23 06:41:52 UTC (rev 1450)
@@ -10,6 +10,7 @@
</div>
<h2>Database</h2>
<ul>
+ <li><a href="/cmmlwiki/adm?action=setup">Check Setup</a></li>
<li><a href="/cmmlwiki/adm?action=init_db">Initialize DB</a></li>
<li><a href="/cmmlwiki/adm?action=dump_db">Dump DB</a></li>
<li><a href="/cmmlwiki/adm?action=delete_db_records">Delete all DB records</a></li>
--
alexander
More information about the cvs-annodex
mailing list