Skip to content
Snippets Groups Projects
Commit a74b3515 authored by Vermaat's avatar Vermaat
Browse files

Install/upgrade scripts output colorized messages.

parent 939603f5
No related branches found
No related tags found
No related merge requests found
......@@ -8,27 +8,14 @@ Usage:
"""
import sys
import MySQLdb
def _connect():
try:
connection = MySQLdb.connect(host='localhost',
user='mutalyzer',
passwd='',
db='mutalyzer')
except MySQLdb.Error, e:
print 'Error %d: %s' % (e.args[0], e.args[1])
sys.exit(1)
return connection
import migration
def check():
"""
Check if migration is needed.
"""
connection = _connect()
connection = migration.db_connect('mutalyzer')
cursor = connection.cursor()
cursor.execute('SHOW COLUMNS FROM GBInfo WHERE field = "created";')
has_column = len(cursor.fetchall()) > 0
......@@ -36,8 +23,7 @@ def check():
has_index = len(cursor.fetchall()) > 0
connection.close()
if has_column != has_index:
print 'Installation is not in a recognizable state. Fix manually.'
sys.exit(1)
migration.fatal('Installation is not in a recognizable state. Fix manually.')
return not has_column
......@@ -45,25 +31,17 @@ def migrate():
"""
Perform migration.
"""
connection = _connect()
connection = migration.db_connect('mutalyzer')
cursor = connection.cursor()
cursor.execute("""
ALTER TABLE GBInfo
#ADD COLUMN created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
ALTER TABLE GBInfo
ADD COLUMN created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD INDEX created (created);""")
connection.commit()
connection.close()
print 'Added column mutalyzer.GBInfo.created'
print 'Added index on mutalyzer.GBInfo.created'
migration.info('Added column mutalyzer.GBInfo.created')
migration.info('Added index on mutalyzer.GBInfo.created')
if __name__ == '__main__':
needed = check()
if needed:
print 'This migration is needed.'
if len(sys.argv) > 1 and sys.argv[1] == 'migrate':
print 'Performing migration.'
migrate()
print 'Performed migration.'
else:
print 'This migration is not needed.'
migration.main(check, migrate)
......@@ -20,20 +20,7 @@ The map tables are renamed to map_backup.
"""
import sys
import MySQLdb
def _connect(db):
try:
connection = MySQLdb.connect(host='localhost',
user='mutalyzer',
passwd='',
db=db)
except MySQLdb.Error, e:
print 'Error %d: %s' % (e.args[0], e.args[1])
sys.exit(1)
return connection
import migration
def _exon_starts(starts):
......@@ -50,7 +37,7 @@ def _exon_stops(stops):
def _check(db):
# Todo: Also check if 'map' is gone.
connection = _connect(db)
connection = migration.db_connect(db)
cursor = connection.cursor()
cursor.execute('SHOW TABLES LIKE "Mapping";')
ok = len(cursor.fetchall()) > 0
......@@ -59,7 +46,7 @@ def _check(db):
def _migrate(db):
connection = _connect(db)
connection = migration.db_connect(db)
cursor = connection.cursor()
cursor.execute("""
CREATE TABLE Mapping (
......@@ -114,13 +101,13 @@ def _migrate(db):
r['cds_stop'], _exon_starts(r['exon_starts']), _exon_stops(r['exon_stops']),
r['protein'], r['source']))
print 'Converted table map to table Mapping on %s (%d entries)' % (db, count)
migration.info('Converted table map to table Mapping on %s (%d entries)' % (db, count))
cursor.execute('DROP TABLE IF EXISTS gbStatus, map_cdsBackup, refGene, refLink')
cursor.execute('RENAME TABLE map TO map_backup')
print 'Dropped tables gbStatus, map_cdsBackup, refGene, refLink on %s' % db
print 'Renamed table map to map_backup on %s' % db
migration.info('Dropped tables gbStatus, map_cdsBackup, refGene, refLink on %s' % db)
migration.info('Renamed table map to map_backup on %s' % db)
select_cursor.close()
cursor.close()
......@@ -135,8 +122,7 @@ def check():
hg18_ok = _check('hg18')
hg19_ok = _check('hg19')
if hg18_ok != hg19_ok:
print 'Installation is not in a recognizable state. Fix manually.'
sys.exit(1)
migration.fatal('Installation is not in a recognizable state. Fix manually.')
return not hg18_ok
......@@ -149,12 +135,4 @@ def migrate():
if __name__ == '__main__':
needed = check()
if needed:
print 'This migration is needed.'
if len(sys.argv) > 1 and sys.argv[1] == 'migrate':
print 'Performing migration.'
migrate()
print 'Performed migration.'
else:
print 'This migration is not needed.'
migration.main(check, migrate)
......@@ -5,11 +5,16 @@
# Usage:
# ./003-config-remove-ucsc.migration [migrate]
COLOR_INFO='\033[92m'
COLOR_WARNING='\033[93m'
COLOR_ERROR='\033[91m'
COLOR_END='\033[0m'
if [ -e /etc/mutalyzer/config ] && $(grep -q 'MySQL username for the UCSC database' /etc/mutalyzer/config); then
echo 'This migration is needed.'
echo -e "${COLOR_WARNING}This migration is needed.${COLOR_END}"
if [ "$1" = 'migrate' ]; then
echo 'Performing migration.'
echo 'Copying /etc/mutalyzer/config to /etc/mutalyzer/config.backup'
echo -e "${COLOR_INFO}Copying /etc/mutalyzer/config to /etc/mutalyzer/config.backup${COLOR_END}"
cp /etc/mutalyzer/config /etc/mutalyzer/config.backup
sed -i '/MySQL username for the UCSC database/d' /etc/mutalyzer/config
sed -i '/Host name for the UCSC database/d' /etc/mutalyzer/config
......@@ -17,9 +22,9 @@ if [ -e /etc/mutalyzer/config ] && $(grep -q 'MySQL username for the UCSC databa
sed -i '/RemoteMySQLuser =/d' /etc/mutalyzer/config
sed -i '/^RemoteMySQLhost =/d' /etc/mutalyzer/config
sed -i '/^UpdateInterval =/d' /etc/mutalyzer/config
echo 'Removed all UCSC database configuration values from /etc/mutalyzer/config'
echo -e "${COLOR_INFO}Removed all UCSC database configuration values from /etc/mutalyzer/config${COLOR_END}"
echo 'Performed migration.'
fi
else
echo 'This migration is not needed.'
echo -e "${COLOR_INFO}This migration is not needed.${COLOR_END}"
fi
......@@ -5,20 +5,25 @@
# Usage:
# ./004-cron-ucsc-to-ncbi.migration [migrate]
COLOR_INFO='\033[92m'
COLOR_WARNING='\033[93m'
COLOR_ERROR='\033[91m'
COLOR_END='\033[0m'
if [ -e /etc/cron.d/mutalyzer-ucsc-update ] && $(grep -v -q '^#' /etc/cron.d/mutalyzer-ucsc-update); then
echo 'This migration is needed.'
echo -e "${COLOR_WARNING}This migration is needed.${COLOR_END}"
if [ "$1" = 'migrate' ]; then
echo 'Performing migration.'
sed -i 's/^/#/' /etc/cron.d/mutalyzer-ucsc-update
echo 'Commented all lines in /etc/cron.d/mutalyzer-ucsc-update'
echo -e "${COLOR_INFO}Commented all lines in /etc/cron.d/mutalyzer-ucsc-update${COLOR_END}"
if [ ! -e /etc/cron.d/mutalyzer-mapping-update ]; then
BIN_MAPPING_UPDATE=$(which mutalyzer-mapping-update)
cp extras/cron.d/mutalyzer-mapping-update /etc/cron.d/mutalyzer-mapping-update
sed -i -e "s@<MUTALYZER_BIN_MAPPING_UPDATE>@${BIN_MAPPING_UPDATE}@g" /etc/cron.d/mutalyzer-mapping-update
echo 'Installed /etc/cron.d/mutalyzer-mapping-update'
echo -e "${COLOR_INFO}Installed /etc/cron.d/mutalyzer-mapping-update${COLOR_END}"
fi
echo 'Performed migration.'
fi
else
echo 'This migration is not needed.'
echo -e "${COLOR_INFO}This migration is not needed.${COLOR_END}"
fi
"""
Some utility functions for our simple migrations.
@todo: Perhaps this should be moved to the mutalyzer package.
"""
import sys
import MySQLdb
COLOR_INFO = '\033[92m'
COLOR_WARNING = '\033[93m'
COLOR_ERROR = '\033[91m'
COLOR_END = '\033[0m'
def print_color(message, color=None):
if color is None:
print message
else:
print color + message + COLOR_END
def info(message):
print_color(message, COLOR_INFO)
def warning(message):
print_color(message, COLOR_WARNING)
def error(message):
print_color(message, COLOR_ERROR)
def fatal(message):
error(message)
sys.exit(1)
def db_connect(database):
try:
connection = MySQLdb.connect(host='localhost',
user='mutalyzer',
passwd='',
db=database)
except MySQLdb.Error as e:
fatal('Error %d: %s' % (e.args[0], e.args[1]))
return connection
def main(check, migrate):
needed = check()
if needed:
warning('This migration is needed.')
if len(sys.argv) > 1 and sys.argv[1] == 'migrate':
print 'Performing migration.'
migrate()
print 'Performed migration.'
else:
info('This migration is not needed.')
......@@ -17,6 +17,11 @@
set -e
COLOR_INFO='\033[92m'
COLOR_WARNING='\033[93m'
COLOR_ERROR='\033[91m'
COLOR_END='\033[0m'
# The 'cd /' is a hack to prevent the mutalyzer package under the current
# directory to be used.
PACKAGE_ROOT=$(cd / && python -c 'import mutalyzer; print mutalyzer.package_root()')
......@@ -27,40 +32,40 @@ BIN_WEBSITE=$(which mutalyzer-website.wsgi)
BIN_WEBSERVICE=$(which mutalyzer-webservice.wsgi)
if [ ! -e /etc/mutalyzer/config ]; then
echo "Creating /etc/mutalyzer/config"
echo -e "${COLOR_INFO}Creating /etc/mutalyzer/config${COLOR_END}"
mkdir -p /etc/mutalyzer
cp extras/config.example /etc/mutalyzer/config
chmod -R u=rwX,go=rX /etc/mutalyzer
else
echo "Not touching /etc/mutalyzer/config (it exists)"
echo -e "${COLOR_WARNING}Not touching /etc/mutalyzer/config (it exists)${COLOR_END}"
fi
echo "Touching /var/log/mutalyzer.log"
echo -e "${COLOR_INFO}Touching /var/log/mutalyzer.log${COLOR_END}"
touch /var/log/mutalyzer.log
chown www-data:www-data /var/log/mutalyzer.log
chmod u=rw,go=r /var/log/mutalyzer.log
echo "Touching /var/cache/mutalyzer"
echo -e "${COLOR_INFO}Touching /var/cache/mutalyzer${COLOR_END}"
mkdir -p /var/cache/mutalyzer
chown -R www-data:www-data /var/cache/mutalyzer
chmod -R u=rwX,go=rX /var/cache/mutalyzer
echo "Creating /etc/init.d/mutalyzer-batchd"
echo -e "${COLOR_INFO}Creating /etc/init.d/mutalyzer-batchd${COLOR_INFO}"
cp extras/init.d/mutalyzer-batchd /etc/init.d/mutalyzer-batchd
sed -i -e "s@<MUTALYZER_BIN_BATCHD>@${BIN_BATCHD}@g" /etc/init.d/mutalyzer-batchd
chmod u=rwx,go=rx /etc/init.d/mutalyzer-batchd
echo "Installing init script links"
echo -e "${COLOR_INFO}Installing init scripts${COLOR_END}"
update-rc.d -f mutalyzer-batchd remove
update-rc.d mutalyzer-batchd defaults 98 02
echo "Installing crontab"
echo -e "${COLOR_INFO}Installing crontab${COLOR_END}"
cp extras/cron.d/mutalyzer-cache-sync /etc/cron.d/mutalyzer-cache-sync
sed -i -e "s@<MUTALYZER_BIN_CACHE_SYNC>@${BIN_CACHE_SYNC}@g" /etc/cron.d/mutalyzer-cache-sync
cp extras/cron.d/mutalyzer-mapping-update /etc/cron.d/mutalyzer-mapping-update
sed -i -e "s@<MUTALYZER_BIN_MAPPING_UPDATE>@${BIN_MAPPING_UPDATE}@g" /etc/cron.d/mutalyzer-mapping-update
echo "Creating /etc/apache2/conf.d/mutalyzer.conf"
echo -e "${COLOR_INFO}Creating /etc/apache2/conf.d/mutalyzer.conf${COLOR_END}"
cp extras/apache/mutalyzer.conf /etc/apache2/conf.d/mutalyzer.conf
sed -i -e "s@<MUTALYZER_BIN_WEBSITE>@${BIN_WEBSITE}@g" -e "s@<MUTALYZER_BIN_WEBSERVICE>@${BIN_WEBSERVICE}@g" -e "s@<MUTALYZER_BIN_BATCHD>@${BIN_BATCHD}@g" /etc/apache2/conf.d/mutalyzer.conf
chmod u=rw,go=r /etc/apache2/conf.d/mutalyzer.conf
......@@ -199,7 +204,7 @@ EOF
wget "ftp://ftp.ncbi.nih.gov/genomes/H_sapiens/mapview/seq_gene.md.gz" -O - | zcat > /tmp/seq_gene.md
$(BIN_MAPPING_UPDATE hg19 /tmp/seq_gene.md 'GRCh37.p2-Primary Assembly')
echo "Creating tables in mutalyzer database"
echo -e "${COLOR_INFO}Creating tables in mutalyzer database${COLOR_END}"
# Create mutalyzer tables
cat << EOF | mysql -u mutalyzer -D mutalyzer
......@@ -254,7 +259,7 @@ if [ -e /var/www/mutalyzer/base ]; then
rm /var/www/mutalyzer/base
fi
echo "Symlinking /var/www/mutalyzer/base to $PACKAGE_ROOT/templates/base"
echo -e "${COLOR_INFO}Symlinking /var/www/mutalyzer/base to $PACKAGE_ROOT/templates/base${COLOR_END}"
ln -s $PACKAGE_ROOT/templates/base /var/www/mutalyzer/base
echo "Restarting Apache"
......
......@@ -13,6 +13,11 @@
set -e
COLOR_INFO='\033[92m'
COLOR_WARNING='\033[93m'
COLOR_ERROR='\033[91m'
COLOR_END='\033[0m'
# The 'cd /' is a hack to prevent the mutalyzer package under the current
# directory to be used.
PACKAGE_ROOT=$(cd / && python -c 'import mutalyzer; print mutalyzer.package_root()')
......@@ -26,7 +31,7 @@ if [ -e /var/www/mutalyzer/base ]; then
rm /var/www/mutalyzer/base
fi
echo "Symlinking /var/www/mutalyzer/base to $PACKAGE_ROOT/templates/base"
echo -e "${COLOR_INFO}Symlinking /var/www/mutalyzer/base to $PACKAGE_ROOT/templates/base${COLOR_END}"
ln -s $PACKAGE_ROOT/templates/base /var/www/mutalyzer/base
echo "Running any needed migrations"
......
......@@ -13,7 +13,12 @@
set -e
echo "Installing packages with apt"
COLOR_INFO='\033[92m'
COLOR_WARNING='\033[93m'
COLOR_ERROR='\033[91m'
COLOR_END='\033[0m'
echo -e "${COLOR_INFO}Installing packages with apt${COLOR_END}"
apt-get install -y \
mysql-server \
......@@ -36,7 +41,7 @@ apt-get install -y \
python-setuptools \
git-core
echo "Installing latest soaplib from git master"
echo -e "${COLOR_INFO}Installing latest soaplib from git master${COLOR_END}"
mkdir -p /tmp/mutalyzer-install
pushd /tmp/mutalyzer-install
......@@ -48,8 +53,6 @@ python setup.py install
popd
rm -Rf /tmp/mutalyzer-install
echo "Installing suds using easy_install"
echo -e "${COLOR_INFO}Installing suds using easy_install${COLOR_END}"
easy_install suds
echo "kthxbye"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment