Commit 1bc157d2 authored by Jim Tittsler's avatar Jim Tittsler

Watch.py: initial filesystem (fs) snapshot support.

Improve error reporting (including treating navigation menu creation
errors as warnings).
parent f2d60979
......@@ -7,6 +7,8 @@ from email.mime.text import MIMEText
import subprocess
import MySQLdb
node = '/home/ubuntu/.nvm/versions/node/v4.2.1/bin/node'
def send_mail(name, email, subject, message):
if email == '' or subject == '' or message == '':
return
......@@ -28,6 +30,7 @@ db = MySQLdb.connect(host=options['mwdbhost'],
db=options['mwdb'])
c = db.cursor(MySQLdb.cursors.DictCursor)
# find the most recent request that hasn't been started
c.execute("""SELECT * from mw_snapshot
WHERE status=0
ORDER BY id
......@@ -36,22 +39,22 @@ row = c.fetchone()
if row is None:
sys.exit(0)
#print row
opt = json.loads(row['opt'])
inoutline = opt['outline'].strip()
if not inoutline.lower().startswith('http://wikieducator.org'):
if inoutline[0] <> '/':
inoutline = '/' + inoutline
opt['outline'] = 'http://wikieducator.org' + inoutline
#print '======== opt ========='
#print opt
# mark in progress
c.execute("""UPDATE mw_snapshot
SET status=1, started=NOW()
WHERE id=%s""",
(row['id'],))
db.commit()
result = 0
errmsg = ''
# build a title out of the outline page name
title_parts = opt['outline'].split('/')
if len(title_parts) >= 2:
......@@ -63,16 +66,34 @@ title = title.replace('Practice:', '')
title = '/' + title
os.chdir('/home/ubuntu/Projects/course')
args = [
'/usr/local/bin/node', 'courseWP.js',
'--prevnext',
'--brand', 'DS4OER Challenge',
'--wpurl', opt['url'],
'--wpuser', opt['user'],
'--wppass', opt['password'],
'--wpmenu', '--wpdelete',
'--theme', 'newSplashWP',
]
if not 'type' in opt:
result = 101
errmsg = 'Request type missing'
elif opt['type'] == 'wp':
args = [
node, 'courseWP.js',
'--prevnext',
'--brand', 'DS4OER Challenge',
'--wpurl', opt['url'],
'--wpuser', opt['user'],
'--wppass', opt['password'],
'--wpmenu', '--wpdelete',
'--theme', 'newSplashWP',
]
elif opt['type'] == 'fs':
title = '/' + opt['course']
args = [
'/usr/local/bin/node', 'course.js',
'--prevnext',
'--urlprefix', title,
'--brand', title[1:],
'--theme', 'newSplash',
]
else:
result = 102
errmsg = 'Unknown snapshot type requested'
if 'logo' in opt and opt['logo']:
args.extend(['--logo', opt['logo'],
'--link', opt['link']])
......@@ -107,6 +128,12 @@ if result == 0:
"""A snapshot of %s\n
has been created at %s\n""" % (opt['outline'].encode('utf-8'), opt['url'].encode('utf-8'))
)
elif result == 11:
send_mail(name, email,
'WikiEducator->WordPress course snapshot created',
"""A snapshot of %s\n
has been created at %s\nbut there may have been a problem creating the navigation menu.\n""" % (opt['outline'].encode('utf-8'), opt['url'].encode('utf-8'))
)
else:
send_mail(name, email,
'WikiEducator->WordPress course snapshot FAILED',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment