#! /usr/bin/python

# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
# See LICENSE for details.

import sys
import os

# give preference to anything with "opscenter" in the path, but give
# higher preference to anything under the tarball/install directory

exe_path = os.path.abspath(sys.argv[0])
tarball_path = os.path.normpath(os.path.join(exe_path, os.pardir, os.pardir))

to_shift = filter(lambda d: "opscenter" in d, sys.path)
to_shift += filter(lambda d: tarball_path in d, sys.path)

for directory in to_shift:
    sys.path.remove(directory)
    if "lib-fallback" not in directory:
        sys.path.insert(0, directory)
    else:
        sys.path.append(directory)

if hasattr(os, "getuid") and os.getuid() != 0:
    sys.path.insert(0, os.path.abspath(os.getcwd()))

from twisted.scripts.twistd import run
run()
