Exemple #1
0
def check():
	if option('mode') == 'init':
		init()
		exit(0)

	if isfile('db'):
		import sqlite3
		conn = sqlite3.connect(dbFilename)
		cur = conn.cursor()
		try:
			row = cur.execute("SELECT value FROM settings WHERE name = 'dbVersion'")
		except sqlite3.DatabaseError, e:
			if 'not a database' in e.message:
				print "There is a file named 'db', but it doesn't appear to be a sprint database"
			else:
				print "There was a problem attempting to open the database: %s" % e.message
			exit(1)
		if option('mode') != 'update':
			print "The database is in an old format. Run %s --update to update it" % sys.argv[0]
			exit(1)
		version = int(row.fetchone()[0])
		if version < LAST_SQLITE_VERSION:
			print "Sprint has changed backend formats, but your database is so old it can't be converted by this version. You need to:"
			print
			print "  * Rollback to revision %s" % LAST_SQLITE_REVISION
			print "  * Run %s --update to update to the latest sqlite database" % sys.argv[0]
			print "  * Switch back to the latest Sprint revision"
			print "  * Run %s --update again to switch from sqlite to stasis" % sys.argv[0]
		else:
			print "Sprint has changed backend formats, so your entire existing database needs to be converted. This is an automated procedure; your old database will be renamed 'db-old.sqlite'. The logs folder will also be converted to a stasis database with a single 'log' table; the existing logs folder will be renamed logs-old."
			print
			print "Run database conversion? [\033[1;32mYes\033[0m/\033[1;31mNo\033[0m] ",
			fd = sys.stdin.fileno()
			reg = termios.tcgetattr(fd)
			try:
				tty.setraw(fd)
				ch = sys.stdin.read(1)
			finally:
				termios.tcsetattr(fd, termios.TCSADRAIN, reg)
			sys.stdout.write("%s\n" % ch)
			print
			if ch not in ('y', 'Y', '\r', '\n'):
				print "Canceled"
				exit(0)
			print "Conversion will start in 3 seconds; depending on the database size you may see quite a lot of text go by"
			sleep(3)
			import sqlite_to_stasis
			print
			if isdir('logs'):
				rename('logs', 'logs-old')
			mkdir('logs')
			print "Database conversion complete. Ready to apply updates"
Exemple #2
0
def isDevMode(handler = None):
	if devMode is None:
		setDevMode(option('dev'))
	return devMode and ((handler is None) or (handler.session['user'] and handler.session['user'].hasPrivilege('Dev')))
Exemple #3
0
os.chdir(dirname(abspath(__file__)))
seed()

from HTTPServer import LoadingServer
preServer = LoadingServer()
preServer.serve_bg()

# We give stasis a single lock for all DiskMaps, but there will only be one DiskMap
from rorn.Lock import getLock, setStackRecording
from stasis.Lock import setMutexProvider
setMutexProvider(lambda: getLock('#stasis'))

from Options import option, parse as parseOptions
parseOptions()
Update.check()
if option('lock-tracking'):
	setStackRecording(True)

from stasis.Singleton import set as setDB
from stasis.DiskMap import DiskMap
from LoadValues import dbFilename
def cacheLog(table):
	sys.__stdout__.write("[%s] [%s] %s\n" % (datetime.now().replace(microsecond = 0), 'stasis', "Backfilling table: %s" % table))
setDB(DiskMap(dbFilename, cache = True, nocache = ['log', 'sessions'], cacheNotifyFn = cacheLog))

from LoadValues import bricked
from Log import console
from Cron import Cron
from HTTPServer import server as getServer, ServerError
from Settings import PORT, settings
from WebSocket import WebSocket
Exemple #4
0
def header(handler, includes):
	print "<!DOCTYPE html>"
	print "<html>"
	print "<head>"
	print "<title>$title$</title>"
	print "<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/syntax-highlighting.css\">"
	print "<link rel=\"shortcut icon\" href=\"/static/images/favicon.ico\">"

	print "<script src=\"/static/jquery.js\" type=\"text/javascript\"></script>"
	print "<script src=\"/static/jquery-migrate-1.1.1.min.js\" type=\"text/javascript\"></script>"
	print "<link rel=\"stylesheet\" href=\"/static/jquery-ui-1.10.1.custom.css\">"
	print "<script src=\"/static/jquery-ui-1.10.1.custom.min.js\" type=\"text/javascript\"></script>"
	print "<link href=\"/static/jquery.contextMenu.css\" rel=\"stylesheet\" type=\"text/css\" />"
	print "<script src=\"/static/jquery.contextMenu.js\"></script>"
	print "<script src=\"/static/jquery.mousewheel-min.js\"></script>"
	print "<script src=\"/static/jquery.terminal-0.4.23.js\"></script>"
	print "<link href=\"/static/jquery.terminal.css\" rel=\"stylesheet\" type=\"text/css\" />"
	print "<script src=\"/static/jquery.ba-bbq.js\"></script>"

	print "<script src=\"/static/bootstrap-dropdown.js\" type=\"text/javascript\"></script>"
	print "<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/bootstrap.css\">"

	print "<link rel=\"stylesheet\" href=\"/static/chosen/chosen.css\" />"
	print "<script src=\"/static/chosen/chosen.jquery.js\" type=\"text/javascript\"></script>"

	print "<script src=\"/static/noty/jquery.noty.js\"></script>"
	print "<script src=\"/static/noty/layouts/bottomCenter.js\"></script>"
	print "<script src=\"/static/noty/themes/default.js\"></script>"
	print "<script src=\"/static/noty/themes/sprint.js\"></script>"

	print "<script src=\"/dyn.js\" type=\"text/javascript\"></script>"
	print "<script src=\"/static/script.js\" type=\"text/javascript\"></script>"
	print "<script src=\"/static/shell.js\" type=\"text/javascript\"></script>"

	print "<style type=\"text/css\">"
	if handler.session['user']:
		print ".username[username~=\"%s\"] {" % handler.session['user'].username
		print "    color: #C00;"
		print "    font-weight: bold;"
		print "}"
	print "</style>"

	for filename in includes['less']:
		print "<link rel=\"stylesheet/less\" type=\"text/css\" href=\"%s\" />" % filename
	# for filename in includes['css']:
		# print "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />" % filename
	for filename in includes['js']:
		print "<script src=\"%s\" type=\"text/javascript\"></script>" % filename

	print "<link rel=\"stylesheet/less\" type=\"text/css\" href=\"/static/style.less\">"
	print "<script type=\"text/javascript\">"
	print "less = {"
	print "    env: '%s'," % ('development' if isDevMode(handler) else 'production')
	print "    async: false,"
	print "    dumpLineNumbers: 'comments'"
	print "};"
	print "</script>"
	print "<script src=\"/static/less.js\" type=\"text/javascript\"></script>"

	changes = list(getChanges(handler, handler.path))
	if changes:
		print "<script src=\"/static/changelog.js\"></script>"
		print "<script type=\"text/javascript\">"
		print "$(document).ready(function() {"
		fmt = "%%(message)s<div style=\"text-align: right; font-size: 6pt\"><a target=\"_blank\" href=\"%s\">%%(hash)s</a></div>" % gitURL
		for change in changes:
			print "    showChangelog(%s);" % toJS(fmt % {'hash': change.hash, 'message': change.message})
		print "});"
		print "</script>"

	print "</head>"
	print "<body>"
	print "<div id=\"shell\"></div>"
	print "<div id=\"frame\">"

	print "<div id=\"main_a\">"
	if handler.session['user']:
		print "<div class=\"avatar\">"
		print "<img class=\"avatar\" src=\"%s\">" % handler.session['user'].getAvatar()
		print "<div class=\"subavatar\">"
		if 'impersonator' in handler.session:
			print "<img class=\"subavatar\" src=\"%s\" onClick=\"unimpersonate();\" title=\"Unimpersonate\">" % handler.session['impersonator'].getAvatar()
		else:
			unreadMessages = Message.loadAll(userid = handler.session['user'].id, read = False)
			if len(unreadMessages) > 0:
				print "<a class=\"inbox\" href=\"/messages/inbox\">%d</a>" % len(unreadMessages)
		print "</div>"
		print "</div>"
	print "<div class=\"navigation\">"
	print "<div class=\"ident\">"
	if handler.session['user']:
		print "Logged in as %s" % handler.session['user']
	else:
		print "<a href=\"/login\">Not logged in</a>"
	print "</div>"

	if (option('dev') or isDevMode(handler)) and handler.session['user'] and handler.session['user'].hasPrivilege('Dev'):
		if isDevMode(handler):
			print "<div class=\"devwarning\" onClick=\"buildmode('production')\">"
			print "Development"
			print "</div>"
		else:
			print "<div class=\"prodwarning\" onClick=\"buildmode('development')\">"
			print "Production"
			print "</div>"

	print "<div class=\"topmenu\">"
	print menu.render(handler, handler.path)
	print "</div>"
	print "</div>"
	print "</div>"

	print "<div id=\"main_b\"></div>"

	print "<div id=\"main_c\">"

	if settings.systemMessage:
		print "<div class=\"sysmessage\">%s</div>" % settings.systemMessage

	print "<div id=\"main_d\">"

	print "<h1>$bodytitle$</h1>"
Exemple #5
0
			import sqlite_to_stasis
			print
			if isdir('logs'):
				rename('logs', 'logs-old')
			mkdir('logs')
			print "Database conversion complete. Ready to apply updates"

	if not isdir('db'):
		print "No database found. If you've never run this tool before, run %s --init to configure it" % sys.argv[0]
		exit(1)

	# There's no DB connection yet, so we set a temporary uncached one
	# The real cached version is set later in main
	setDB(DiskMap(dbFilename))

	if option('mode') == 'update':
		if int(settings.dbVersion) < len(updates):
			runUpdates()
			print "Updated to database version %d. %s" % (len(updates), HOW_TO_RUN)
			exit(0)
		elif int(settings.dbVersion) == len(updates):
			print "Unable to update -- already at database version %d" % len(updates)
			exit(1)
	if int(settings.dbVersion) < len(updates):
		print "The database is %s behind. Run %s --update to update it" % (pluralize(len(updates) - int(settings.dbVersion), 'version', 'versions'), sys.argv[0])
		exit(1)
	elif int(settings.dbVersion) > len(updates):
		print "The database is %s ahead; downgrading is not supported" % pluralize(int(settings.dbVersion) - DB_VERSION, 'version', 'versions')
		exit(1)

def init():