Scripts to update metadata to the latest model.

Be sure to backup databases before executing.
This commit is contained in:
Daniel Blankenberg
2007-08-22 20:04:40 +00:00
parent 3f0579c7a4
commit b873d64859
2 changed files with 94 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env python2.4
#Dan Blankenberg
"""
Updates metadata in the database to match rev 1891.
Remember to backup your database before running.
"""
import sys, os, ConfigParser
import galaxy.app
from galaxy.util.bunch import Bunch
import galaxy.datatypes.tabular
def main():
ini_file = sys.argv.pop(1)
conf_parser = ConfigParser.ConfigParser({'here':os.getcwd()})
conf_parser.read(ini_file)
configuration = {}
for key, value in conf_parser.items("app:main"): configuration[key] = value
app = galaxy.app.UniverseApplication( global_conf = ini_file, **configuration )
# Step through Database, turning metadata bunches into dictionaries.
print "Changing metadata bunches to dictionaries."
for row in app.model.Dataset.table.select().execute():
if isinstance (row.metadata, Bunch):
print row.id
app.model.Dataset.table.update(app.model.Dataset.table.c.id == row.id).execute( _metadata = row.metadata.__dict__ )
print "Rewriting all metadata to database, setting metadata dbkey, to ensure JSONified storage."
#Make sure all metadata is jsonified
for row in app.model.Dataset.table.select().execute():
print row.id
data = app.model.Dataset.get(row.id)
dbkey = data.old_dbkey
if not dbkey or data.metadata.dbkey not in ["?", ["?"], None, []]:
dbkey = data.metadata.dbkey
if not dbkey: dbkey = "?"
#change dbkey then flush, then change to real value and flush, ensures that metadata is rewritten to database
data.dbkey="~"
data.flush()
data.dbkey=dbkey
data.flush()
print "Seeking out tabular based files and setting number of columns."
#Search out tabular datatypes and make sure that number of columns is set.
for row in app.model.Dataset.table.select().execute():
data = app.model.Dataset.get(row.id)
if issubclass(type(data.datatype), type(app.datatypes_registry.get_datatype_by_extension('tabular'))):
print row.id
galaxy.datatypes.tabular.Tabular().set_meta( data ) #Call tabular set metadata method for all Classes, this will set number of columns.
data.flush()
app.shutdown()
sys.exit(0)
if __name__ == "__main__":
main()
+36
View File
@@ -0,0 +1,36 @@
#!/bin/sh
## Set MACHTYPE to something,
MACHTYPE=`uname -m`
[ "$MACHTYPE" = "Power Macintosh" ] && MACHTYPE="powerpc"
LC_ALL=POSIX
export MACHTYPE LC_ALL
KERNEL=`uname -s | tr "A-Z" "a-z"`
ARCH="$KERNEL-$MACHTYPE"
echo "Architecture appears to be $ARCH"
UNIVERSE_HOME=`pwd`
PYTHONPATH=$UNIVERSE_HOME/lib:$UNIVERSE_HOME/eggs
export UNIVERSE_HOME PYTHONPATH
## For PBS - if you need to force node paths (i.e. the arch the frontend
## runs on is not the same arch as the compute nodes or Galaxy is
## installed in a different path on the node).
#NODEMACH="i686"
#NODEARCH="linux-i686"
#NODEPATH=$PATH
## Certain tools (EMBOSS, PAML...) are not distributed with Galaxy.
## If you have them installed, add their bin directories to the PATH.
PATH=$PATH:/depot/apps/$MACHTYPE/bin:/home/universe/$ARCH/EMBOSS/bin:/home/universe/$ARCH/ImageMagick/bin:/home/universe/$ARCH/PAML/paml3.15/bin
## NODEPATH defaults to $PATH
: ${NODEPATH:=$PATH}
export PATH NODEPATH
echo "python path: $PYTHONPATH"
python2.4 ./scripts/update_metadata.py universe_wsgi.ini $@