Exemple #1
0
 def preLaunch(self):
     """
     Sets ourself up for running 
     Needed for unit tests
     """
     log.debug("preLaunch")
     self.packageStore = PackageStore()
     self.ideviceStore = IdeviceStore(self.config)
     self.ideviceStore.load()
     # Make it so jelly can load objects from ~/.exe/idevices
     sys.path.append(self.config.configDir / 'idevices')
     self.webServer = WebServer(self)
     # and determine the web server's port before launching the client, so it can use the same port#:
     self.webServer.find_port()
Exemple #2
0
 def setUp(self):
     packageStore = PackageStore()
     package      = packageStore.createPackage()
     n0 = package.root       # 00
     n1 = n0.createChild()   #  |_01                               
     n2 = n1.createChild()   #  |  |_02                            
     n3 = n2.createChild()   #  |  |  |_03                         
     n4 = n3.createChild()   #  |  |  |  |_04                      
     n5 = n2.createChild()   #  |  |  |_05                         
     n6 = n2.createChild()   #  |  |  |_06
     n7 = n1.createChild()   #  |  |_07                            
     n8 = n1.createChild()   #  |  |_08                            
     n9 = n0.createChild()   #  |_09
     n10 = n0.createChild()  #  |_10
     globals().update(locals()) # Make all local vars global for easy access
Exemple #3
0
 def setUp(self):
     packageStore = PackageStore()
     package = packageStore.createPackage()
     n0 = package.root  # 00
     n1 = n0.createChild()  #  |_01
     n2 = n1.createChild()  #  |  |_02
     n3 = n2.createChild()  #  |  |  |_03
     n4 = n3.createChild()  #  |  |  |  |_04
     n5 = n2.createChild()  #  |  |  |_05
     n6 = n2.createChild()  #  |  |  |_06
     n7 = n1.createChild()  #  |  |_07
     n8 = n1.createChild()  #  |  |_08
     n9 = n0.createChild()  #  |_09
     n10 = n0.createChild()  #  |_10
     globals().update(
         locals())  # Make all local vars global for easy access
Exemple #4
0
 def setUp(self):
     G.application = Application()
     
     G.application.loadConfiguration()
     G.application.preLaunch()
     
     self.packageStore = PackageStore()
     self.package      = self.packageStore.createPackage()
Exemple #5
0
    def testSaveAndLoad(self):
        packageStore = PackageStore()
        package = packageStore.createPackage()
        # Check that it has been given a default name
        self.assertEquals(package.name, "newPackage")
        package.author = "UoA"
        package.description = "Nice test package"
        Config._getConfigPathOptions = lambda s: ['exe.conf']
        config = Config()
        filePath = config.dataDir / 'package1.elp'
        package.save(filePath)

        package1 = Package.load(filePath)
        self.assert_(package1)
        self.assertEquals(package1.author, "UoA")
        self.assertEquals(package1.description, "Nice test package")
        # Package name should have been set when it was saved
        self.assertEquals(package.name, "package1")
        self.assertEquals(package1.name, "package1")
    def _testSaveAndLoad(self):
        packageStore = PackageStore()
        package = packageStore.createPackage()
        # Check that it has been given a default name
        self.assertEquals(package.name, "newPackage")
        package.author = "UoA"
        package.description = "Nice test package"
        Config._getConfigPathOptions = lambda s: ["exe.conf"]
        config = Config()
        filePath = config.dataDir / "package1.elp"
        package.save(filePath)

        package1 = Package.load(filePath)
        self.assert_(package1)
        self.assertEquals(package1.author, "UoA")
        self.assertEquals(package1.description, "Nice test package")
        # Package name should have been set when it was saved
        self.assertEquals(package.name, "package1")
        self.assertEquals(package1.name, "package1")
Exemple #7
0
 def preLaunch(self):
     """
     Sets ourself up for running 
     Needed for unit tests
     """
     log.debug("preLaunch")
     self.packageStore = PackageStore()
     self.ideviceStore = IdeviceStore(self.config)
     self.ideviceStore.load()
     self.webServer = WebServer(self)
Exemple #8
0
 def preLaunch(self):
     """
     Sets ourself up for running 
     Needed for unit tests
     """
     log.debug("preLaunch")
     self.packageStore = PackageStore()
     self.ideviceStore = IdeviceStore(self.config)
     self.ideviceStore.load()
     sys.path.append(self.config.configDir / "idevices")
     self.webServer = WebServer(self)
     self.webServer.find_port()
 def testSaveAndLoad(self):
     packageStore = PackageStore()
     package = packageStore.createPackage()
     # Check that it has been given a default name
     self.assertEquals(package.name, "newPackage")
     package.author = "UoA"
     package.description = "Nice test package"
     Config._getConfigPathOptions = lambda s: ['exe.conf']
     config  = Config()
     SuperTestCase.update_config_parser(config.configParser)
     config.loadSettings()
             
     filePath = config.dataDir/'package1.elp'
     package.save(filePath)
     
     package1 = Package.load(filePath)
     self.assert_(package1)
     self.assertEquals(package1.author, "UoA")
     self.assertEquals(package1.description, "Nice test package")
     # Package name should have been set when it was saved
     self.assertEquals(package.name, "package1")
     self.assertEquals(package1.name, "package1")
Exemple #10
0
class TestResource(unittest.TestCase):
    def setUp(self):
        self.packageStore = PackageStore()
        self.package      = self.packageStore.createPackage()
    def testCreateAndDelete(self):
        """
        Test we have a resource directory and resource files can be stored in
        """
        oliver = Resource(self.package, Path("oliver.jpg"))
        self.assert_((self.package.resourceDir/"oliver.jpg").exists())
        oliver.delete()
        self.assert_(not (self.package.resourceDir/"oliver.jpg").exists())
    def testSaveAndLoad(self):
        pass
Exemple #11
0
 def preLaunch(self):
     """
     Sets ourself up for running 
     Needed for unit tests
     """
     log.debug("preLaunch")
     self.packageStore = PackageStore()
     self.ideviceStore = IdeviceStore(self.config)
     self.ideviceStore.load()
     # Make it so jelly can load objects from ~/.exe/idevices
     sys.path.append(self.config.configDir/'idevices')
     self.webServer = WebServer(self)
     # and determine the web server's port before launching the client, so it can use the same port#:
     self.webServer.find_port()
Exemple #12
0
class TestResource(unittest.TestCase):
    def setUp(self):
        self.packageStore = PackageStore()
        self.package      = self.packageStore.createPackage()
    def testCreateAndDelete(self):
        """
        Test we have a resource directory and resource files can be stored in
        """
        myIdevice = Idevice("My Idevice", "UoA", "Testing", "Help tip", "icon", self.package.root)
        oliver = Resource(myIdevice, Path("oliver.jpg"))
        self.assert_((self.package.resourceDir/"oliver.jpg").exists())
        oliver.delete()
        self.assert_(not (self.package.resourceDir/"oliver.jpg").exists())
    def testSaveAndLoad(self):
        pass
Exemple #13
0
class Application:
    """
    Main application class, pulls together everything and runs it.
    """

    def __init__(self):
        """
        Initialize
        """
        self.config = None
        self.packageStore = None
        self.ideviceStore = None
        self.packagePath = None
        self.webServer = None
        self.standalone = False  # Used for the ready to run exe
        self.persistNonPersistants = False
        self.tempWebDir = mkdtemp(".eXe")
        self.afterUpgradeHandlers = []
        assert globals.application is None, "You tried to instantiate two Application objects"
        globals.application = self

    def main(self):
        """
        Main function, starts eXe
        """
        self.processArgs()
        self.loadConfiguration()
        eXeStart = os.path.join(os.path.dirname(globals.application.tempWebDir), "tmpExeStartupTime")
        if os.name == "posix":
            eXeStart = eXeStart + "." + str(os.getuid())
        log.debug(u"eXeStart: " + eXeStart)
        if os.path.exists(eXeStart):
            inStartFH = open(eXeStart, "r")
            lastRunTimeS = 0
            for line in inStartFH:
                lastRunTimeS = int(line)
            inStartFH.close()
            log.debug("lastRunTimeS: " + ` lastRunTimeS `)
            currentTime = int(time.time())
            currentTime2 = int(time.time())
            log.info("currentTime: " + ` currentTime `)
            if currentTime <= lastRunTimeS + 3 and currentTime >= lastRunTimeS:
                return None
        if sys.platform[:3] == "win" and self.packagePath is not None:
            self.packagePath = self.config.getLongPathName(self.packagePath)
        installSafeTranslate()
        self.preLaunch()
        if self.config.port >= 0:
            self.launch()
            log.info("serving")
            self.serve()
            log.info("done serving")
        else:
            log.error("eXe appears to already be running")
            log.error("looks like the eXe server was not able to find a valid port; terminating...")
        shutil.rmtree(self.tempWebDir, True)
        try:
            os.remove(eXeStart)
        except IOError:
            pass

    def processArgs(self):
        """
        Processes the command line arguments
        """
        try:
            options, packages = getopt(sys.argv[1:], "hV", ["help", "version", "standalone"])
        except GetoptError:
            self.usage()
            sys.exit(2)
        if len(packages) == 1:
            self.packagePath = packages[0]
        elif len(packages) > 1:
            self.usage()
            sys.exit(2)
        for option in options:
            if option[0] in ("-V", "--version"):
                print "eXe", version.version
                sys.exit()
            elif option[0] in ("-h", "--help"):
                self.usage()
                sys.exit()
            elif option[0].lower() == "--standalone":
                self.standalone = True

    def loadConfiguration(self):
        """
        Loads the config file and applies all the settings
        """
        if self.standalone:
            from exe.engine.standaloneconfig import StandaloneConfig

            self.config = StandaloneConfig()
        elif sys.platform[:3] == "win":
            from exe.engine.winconfig import WinConfig

            self.config = WinConfig()
        elif sys.platform[:6] == "darwin":
            from exe.engine.macconfig import MacConfig

            self.config = MacConfig()
        else:
            from exe.engine.linuxconfig import LinuxConfig

            self.config = LinuxConfig()
        log.debug("logging set up")

    def preLaunch(self):
        """
        Sets ourself up for running 
        Needed for unit tests
        """
        log.debug("preLaunch")
        self.packageStore = PackageStore()
        self.ideviceStore = IdeviceStore(self.config)
        self.ideviceStore.load()
        sys.path.append(self.config.configDir / "idevices")
        self.webServer = WebServer(self)
        self.webServer.find_port()

    def serve(self):
        """
        Starts the web server,
        this func doesn't return until after the app has finished
        """
        print "Welcome to eXe: the eLearning XHTML editor"
        log.info("eXe running...")
        self.webServer.run()

    def _loadPackage(self, packagePath):
        try:
            log.info("webDir: " + self.config.webDir)
            log.info("tempWebDir: " + self.tempWebDir)
            inSplashFile = self.config.webDir + "/docs/splash.xulTemplate"
            outSplashFile = self.config.webDir + "/docs/splash.xul"
            outSplashData = self.config.webDir + "/docs/splash.dat"
            outSplashFile = self.tempWebDir + "/splash.xul"
            outSplashData = self.tempWebDir + "/splash.dat"
            log.info("inSplashFile: " + inSplashFile)
            log.info("outSplashFile: " + outSplashFile)
            log.info("outSplashData: " + outSplashData)
            outSplashFH = open(outSplashData, "w")
            outSplashFH.write("")
            outSplashFH.close()
            inSplashFH = open(inSplashFile, "r")
            outSplashFH = open(outSplashFile, "w")
            pleaseWaitLoad = _(u"Please wait until loading finishes")
            for line in inSplashFH:
                line = line.replace("LOADING_FILE_NAME", packagePath)
                line = line.replace("PLEASE_WAIT_LOAD", pleaseWaitLoad)
                outSplashFH.write(line)
            inSplashFH.close()
            outSplashFH.close()
            log.info("packagePath: " + packagePath)
            launchBrowser(self.config, outSplashFile, "splash")
            shutil.copyfile(self.config.webDir + "/images/exe_logo.png", self.tempWebDir + "/exe_logo.png")
            package = self.packageStore.loadPackage(packagePath)
            port = self.config.port
            editorUrl = u"http://127.0.0.1:%d/%s" % (port, package.name)
            log.info("package.name: " + package.name)
            log.info("editorUrl: " + editorUrl)
            log.info("TempDirPath: " + editorUrl)
            outSplashFH = open(outSplashData, "w")
            outSplashFH.write("1000;" + editorUrl)
            outSplashFH.close()
            self.webServer.root.bindNewPackage(package)
            return package
        except Exception, e:
            log.error("Error loading first Package (%s): %s" % (packagePath, e))
            message = _(u"Sorry, wrong file format")
            outSplashFH = open(globals.application.tempWebDir + "/splash.dat", "w")
            message = re.sub(";", ":", message)
            port = self.config.port
            outSplashFH.write("1000;http://127.0.0.1:" + ` port ` + "/;" + message)
            outSplashFH.close()
            return None
Exemple #14
0
class Application:
    """
    Main application class, pulls together everything and runs it.
    """
    def __init__(self):
        """
        Initialize
        """
        self.config       = None
        self.packageStore = None
        self.ideviceStore = None
        self.packagePath  = None
        self.webServer    = None
        self.standalone   = False # Used for the ready to run exe
        assert globals.application is None, "You tried to instantiate two Application objects"
        globals.application = self
    def main(self):
        """
        Main function, starts eXe
        """
        self.processArgs()
        self.loadConfiguration()
        installSafeTranslate()
        self.preLaunch()
        self.launch()
        log.info('serving')
        self.serve()
        log.info('done serving')
    def processArgs(self):
        """
        Processes the command line arguments
        """
        try:
            options, packages = getopt(sys.argv[1:], 
                                       "hV", ["help", "version", "standalone"])
        except GetoptError:
            self.usage()
            sys.exit(2)
        if len(packages) == 1:
            self.packagePath = packages[0]
        elif len(packages) > 1:
            self.usage()
            sys.exit(2)
        for option in options:
            if option[0] in ("-V", "--version"):
                print "eXe", version.version
                sys.exit()
            elif option[0] in ("-h", "--help"):
                self.usage()
                sys.exit()
            elif option[0].lower() == '--standalone':
                self.standalone = True
    def loadConfiguration(self):
        """
        Loads the config file and applies all the settings
        """
        if self.standalone:
            from exe.engine.standaloneconfig import StandaloneConfig
            self.config = StandaloneConfig()
        elif sys.platform[:3] == "win":
            from exe.engine.winconfig import WinConfig
            self.config = WinConfig()
        elif sys.platform[:6] == "darwin":
            from exe.engine.macconfig import MacConfig
            self.config = MacConfig()
        else:
            from exe.engine.linuxconfig import LinuxConfig
            self.config = LinuxConfig()
        log.debug("logging set up")
    def preLaunch(self):
        """
        Sets ourself up for running 
        Needed for unit tests
        """
        log.debug("preLaunch")
        self.packageStore = PackageStore()
        self.ideviceStore = IdeviceStore(self.config)
        self.ideviceStore.load()
        sys.path.append(self.config.configDir/'idevices')
        self.webServer = WebServer(self)
    def serve(self):
        """
        Starts the web server,
        this func doesn't return until after the app has finished
        """
        print "Welcome to eXe: the eLearning XHTML editor"
        log.info("eXe running...")
        self.webServer.run()
    def _loadPackage(self, packagePath):
        """
        Convenience function for loading the first package that we'll browse to
        """
        try:
            package = self.packageStore.loadPackage(packagePath)
            log.debug("loading package "+package.name)
            self.webServer.root.bindNewPackage(package)
            launchBrowser(self.config, package.name)
            return package
        except Exception, e:
            log.error('Error loading first Package (%s): %s' % (packagePath, e))
            return None
Exemple #15
0
class Application:
    """
    Main application class, pulls together everything and runs it.
    """
    def __init__(self):
        """
        Initialize
        """
        self.config = None
        self.packageStore = None
        self.ideviceStore = None
        self.packagePath = None
        self.webServer = None
        self.standalone = False  # Used for the ready to run exe
        self.persistNonPersistants = False
        self.tempWebDir = mkdtemp('.eXe')
        self.afterUpgradeHandlers = []
        assert globals.application is None, "You tried to instantiate two Application objects"
        globals.application = self

    def main(self):
        """
        Main function, starts eXe
        """
        self.processArgs()

        self.loadConfiguration()
        try:
            username = getpass.getuser()
        except ImportError:
            username = ''
        eXeStart = globals.application.tempWebDir
        eXeStart = re.sub("[\/|\\\\][^\/|\\\\]*$", "", eXeStart)
        eXeStart = eXeStart + '/tmpExeStartupTime.' + username

        if os.path.exists(eXeStart):
            inStartFH = open(eXeStart, "r")
            lastRunTimeS = 0
            for line in inStartFH:
                try:
                    lastRunTimeS = int(line)
                except ValueError:
                    lastRunTimeS = 0
            inStartFH.close()
            log.debug('lastRunTimeS: ' + ` lastRunTimeS `)

            currentTime = int(time.time())
            currentTime2 = int(time.time())
            log.info('currentTime: ' + ` currentTime `)
            if (currentTime <= lastRunTimeS + 3
                    and currentTime >= lastRunTimeS):
                #self.xulMessage(_('eXe appears to already be running'))
                #log.info('eXe appears to already be running: <html:br/>lastRunTimes: ' + `lastRunTimeS` + '<html:br/> currentTime: ' + `currentTime` + '<html:br/>currentTime2: ' + `currentTime2`)
                return None

        else:
            log.info('eXeStart: ' + eXeStart)
            log.info('tempWebDir: ' + globals.application.tempWebDir)

        # if a document was double clicked to launch on Win32,
        #   make sure we have the long pathname
        if sys.platform[:3] == "win" and self.packagePath is not None:
            self.packagePath = self.config.getLongPathName(self.packagePath)

        installSafeTranslate()
        self.preLaunch()
        # preLaunch() has called find_port() to set config.port (the IP port #)
        if self.config.port >= 0:
            self.launch()
            log.info('serving')
            self.serve()
            log.info('done serving')
        else:
            #self.xulMessage(_('eXe appears to already be running'))
            log.error('eXe appears to already be running')
            log.error(
                'looks like the eXe server was not able to find a valid port; terminating...'
            )
        shutil.rmtree(self.tempWebDir, True)
        try:
            os.remove(eXeStart)
        except OSError:
            pass

    def processArgs(self):
        """
        Processes the command line arguments
        """
        try:
            options, packages = getopt(sys.argv[1:], "hV",
                                       ["help", "version", "standalone"])
        except GetoptError:
            self.usage()
            sys.exit(2)

        if len(packages) == 1:
            self.packagePath = packages[0]

        elif len(packages) > 1:
            self.usage()
            sys.exit(2)

        for option in options:
            if option[0] in ("-V", "--version"):
                print "eXe", version.version
                sys.exit()
            elif option[0] in ("-h", "--help"):
                self.usage()
                sys.exit()
            elif option[0].lower() == '--standalone':
                self.standalone = True

    def loadConfiguration(self):
        """
        Loads the config file and applies all the settings
        """
        if self.standalone:
            from exe.engine.standaloneconfig import StandaloneConfig
            self.config = StandaloneConfig()
        elif sys.platform[:3] == "win":
            from exe.engine.winconfig import WinConfig
            self.config = WinConfig()
        elif sys.platform[:6] == "darwin":
            from exe.engine.macconfig import MacConfig
            self.config = MacConfig()
        else:
            from exe.engine.linuxconfig import LinuxConfig
            self.config = LinuxConfig()
        log.debug("logging set up")

    def preLaunch(self):
        """
        Sets ourself up for running 
        Needed for unit tests
        """
        log.debug("preLaunch")
        self.packageStore = PackageStore()
        self.ideviceStore = IdeviceStore(self.config)
        self.ideviceStore.load()
        # Make it so jelly can load objects from ~/.exe/idevices
        sys.path.append(self.config.configDir / 'idevices')
        self.webServer = WebServer(self)
        # and determine the web server's port before launching the client, so it can use the same port#:
        self.webServer.find_port()

    def serve(self):
        """
        Starts the web server,
        this func doesn't return until after the app has finished
        """
        print "Welcome to eXe: the eLearning XHTML editor"
        log.info("eXe running...")
        self.webServer.run()

    def _loadPackage(self, packagePath):
        #"""
        #Convenience function for loading the first package that we'll browse to
        #"""
        try:
            #XXXX xxxx
            log.info("webDir: " + self.config.webDir)
            log.info("tempWebDir: " + self.tempWebDir)
            inSplashFile = self.config.webDir + "/docs/splash.xulTemplate"

            outSplashFile = self.config.webDir + "/docs/splash.xul"
            outSplashData = self.config.webDir + "/docs/splash.dat"

            outSplashFile = self.tempWebDir + "/splash.xul"
            outSplashData = self.tempWebDir + "/splash.dat"

            log.info("inSplashFile: " + inSplashFile)
            log.info("outSplashFile: " + outSplashFile)
            log.info("outSplashData: " + outSplashData)

            #resets any splash page data
            outSplashFH = open(outSplashData, "w")
            outSplashFH.write("")
            outSplashFH.close()

            inSplashFH = open(inSplashFile, "r")
            outSplashFH = open(outSplashFile, "w")
            pleaseWaitLoad = _(u'Please wait until loading finishes')
            for line in inSplashFH:
                line = line.replace("LOADING_FILE_NAME", packagePath)
                try:
                    # this can fail in non UTF-8 uris
                    line = line.replace("PLEASE_WAIT_LOAD", pleaseWaitLoad)
                except:
                    pass
                outSplashFH.write(line)
            inSplashFH.close()
            outSplashFH.close()

            log.info("packagePath: " + packagePath)

            launchBrowser(self.config, outSplashFile, "splash")
            shutil.copyfile(self.config.webDir + '/images/exe_logo.png',
                            self.tempWebDir + '/exe_logo.png')

            package = self.packageStore.loadPackage(packagePath)
            port = self.config.port
            editorUrl = u'http://127.0.0.1:%d/%s' % (port, package.name)
            log.info("package.name: " + package.name)
            log.info("editorUrl: " + editorUrl)
            log.info("TempDirPath: " + editorUrl)
            outSplashFH = open(outSplashData, "w")
            outSplashFH.write("1000;" + editorUrl)
            outSplashFH.close()

            self.webServer.root.bindNewPackage(package)
            return package

        except Exception, e:
            log.error('Error loading first Package (%s): %s' %
                      (packagePath, e))
            message = _(u'Sorry, wrong file format')

            outSplashFH=open(globals.application.tempWebDir + \
                               '/splash.dat',"w")
            message = re.sub(";", ":", message)
            port = self.config.port
            outSplashFH.write("1000;http://127.0.0.1:" + `port` + "/;" + \
                               message)
            outSplashFH.close()

            return None
Exemple #16
0
 def setUp(self):
     self.packageStore = PackageStore()
     self.package      = self.packageStore.createPackage()
Exemple #17
0
class Application:
    """
    Main application class, pulls together everything and runs it.
    """
    def __init__(self):
        """
        Initialize
        """
        global application
        self.config       = None
        self.packageStore = None
        self.ideviceStore = None
        self.packagePath  = None
        self.webServer    = None
        self.standalone   = False # Used for the ready to run exe
        assert application is None, "You tried to instantiate two Application objects"
        application = self
    def main(self):
        """
        Main function, starts eXe
        """
        self.processArgs()
        self.loadConfiguration()
        self.preLaunch()
        self.launch()
        log.info('serving')
        self.serve()
        log.info('done serving')
    def processArgs(self):
        """
        Processes the command line arguments
        """
        try:
            options, packages = getopt(sys.argv[1:], 
                                       "hV", ["help", "version", "standalone"])
        except GetoptError:
            self.usage()
            sys.exit(2)
        if len(packages) == 1:
            self.packagePath = packages[0]
        elif len(packages) > 1:
            self.usage()
            sys.exit(2)
        for option in options:
            if option[0] in ("-V", "--version"):
                print "eXe", version.version
                sys.exit()
            elif option[0] in ("-h", "--help"):
                self.usage()
                sys.exit()
            elif option[0].lower() == '--standalone':
                self.standalone = True
    def loadConfiguration(self):
        """
        Loads the config file and applies all the settings
        """
        if self.standalone:
            from exe.engine.standaloneconfig import StandaloneConfig
            self.config = StandaloneConfig()
        elif sys.platform[:3] == "win":
            from exe.engine.winconfig import WinConfig
            self.config = WinConfig()
        elif sys.platform[:6] == "darwin":
            from exe.engine.macconfig import MacConfig
            self.config = MacConfig()
        else:
            from exe.engine.linuxconfig import LinuxConfig
            self.config = LinuxConfig()
        log.debug("logging set up")
    def preLaunch(self):
        """
        Sets ourself up for running 
        Needed for unit tests
        """
        log.debug("preLaunch")
        self.packageStore = PackageStore()
        self.ideviceStore = IdeviceStore(self.config)
        self.ideviceStore.load()
        sys.path.append(self.config.configDir/'idevices')
        self.webServer = WebServer(self)
    def serve(self):
        """
        Starts the web server,
        this func doesn't return until after the app has finished
        """
        print "Welcome to eXe: the eLearning XHTML editor"
        log.info("eXe running...")
        self.webServer.run()
    def launch(self):
        """
        launches the webbrowser
        """
        if self.packagePath:
            package = self.packageStore.loadPackage(self.packagePath)
            log.debug("loading package "+package.name)
            self.webServer.root.bindNewPackage(package)
            launchBrowser(self.config, package.name)
        else:
            launchBrowser(self.config, "")
    def usage(self):
        """
        Print usage info
        """
        print "Usage: "+os.path.basename(sys.argv[0])+" [OPTION] [PACKAGE]"
        print "  -V, --version    print version information and exit"
        print "  -h, --help       display this help and exit"
        print "  --standalone     Run totally from current directory"
        print "Settings are read from exe.conf "
        print "in $HOME/.exe on Linux/Unix or"
        print "in Documents and Settings/<user name>/Application Data/exe "
        print "on Windows"
 def setUp(self):
     packageStore = PackageStore()
     package = packageStore.createPackage()
     globals().update(locals())  # Make all local vars global for easy access
class TestIdevice(unittest.TestCase):
    def setUp(self):
        self.packageStore = PackageStore()
        self.package      = self.packageStore.createPackage()

    def testIdevice(self):
        myIdevice = Idevice("My Idevice", "UoA", "Testing", "Help tip", "icon")
        self.assertEquals(myIdevice.title, "My Idevice")
        self.assertEquals(myIdevice.author, "UoA")
        self.assertEquals(myIdevice.purpose, "Testing")
        self.assertEquals(myIdevice.tip, "Help tip")
        
    def testSetParentNode(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        self.assert_(idevice0.parentNode is parentNode)
        
    def testIsfirstAndIsLast(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice1.setParentNode(parentNode)
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        idevice2.setParentNode(parentNode)
        
        self.assert_(idevice0.isFirst)
        self.assert_(idevice2.isLast)
        
        
    def testCmp(self):
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        self.assertEquals(idevice2.__cmp__(idevice1), 1)
        self.assertEquals(idevice1.__cmp__(idevice0), 1)
        self.assertEquals(idevice0.__cmp__(idevice2), -1)
        
    def testDelete(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice1.setParentNode(parentNode)
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        idevice2.setParentNode(parentNode)
        idevice1.delete()
        if idevice1 in parentNode.idevices:
            print "delete failed"
    
    def testMove(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice1.setParentNode(parentNode)
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        idevice2.setParentNode(parentNode)
        
        idevice0.moveNext()
        self.assertEquals(parentNode.idevices[1], idevice0)
        self.assertEquals(parentNode.idevices[0], idevice1)
        
        idevice2.movePrev()
        self.assertEquals(parentNode.idevices[1], idevice2)
        self.assertEquals(parentNode.idevices[2], idevice0)
 def setUp(self):
     packageStore = PackageStore()
     package = packageStore.createPackage()
     globals().update(
         locals())  # Make all local vars global for easy access
Exemple #21
0
class TestIdevice(unittest.TestCase):
    def setUp(self):
        G.application = Application()
        
        G.application.loadConfiguration()
        G.application.preLaunch()
        
        self.packageStore = PackageStore()
        self.package      = self.packageStore.createPackage()

    def testIdevice(self):
        myIdevice = Idevice("My Idevice", "UoA", "Testing", "Help tip", "icon")
        self.assertEquals(myIdevice.title, "My Idevice")
        self.assertEquals(myIdevice.author, "UoA")
        self.assertEquals(myIdevice.purpose, "Testing")
        self.assertEquals(myIdevice.tip, "Help tip")
        
    def testSetParentNode(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        self.assert_(idevice0.parentNode is parentNode)
        
    def testIsfirstAndIsLast(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice1.setParentNode(parentNode)
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        idevice2.setParentNode(parentNode)
        
        self.assert_(idevice0.isFirst)
        self.assert_(idevice2.isLast)
        
        
    def testCmp(self):
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        self.assertEquals(idevice2.__cmp__(idevice1), 1)
        self.assertEquals(idevice1.__cmp__(idevice0), 1)
        self.assertEquals(idevice0.__cmp__(idevice2), -1)
        
    def testDelete(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice1.setParentNode(parentNode)
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        idevice2.setParentNode(parentNode)
        idevice1.delete()
        if idevice1 in parentNode.idevices:
            print "delete failed"
    
    def testMove(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice1.setParentNode(parentNode)
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        idevice2.setParentNode(parentNode)
        
        idevice0.moveNext()
        self.assertEquals(parentNode.idevices[1], idevice0)
        self.assertEquals(parentNode.idevices[0], idevice1)
        
        idevice2.movePrev()
        self.assertEquals(parentNode.idevices[1], idevice2)
        self.assertEquals(parentNode.idevices[2], idevice0)
        
    def tearDown(self):
        from exe import globals
        globals.application = None
        shutil.rmtree('tmp')
class TestIdevice(unittest.TestCase):
    def setUp(self):
        self.packageStore = PackageStore()
        self.package = self.packageStore.createPackage()

    def testIdevice(self):
        myIdevice = Idevice("My Idevice", "UoA", "Testing", "Help tip", "icon")
        self.assertEquals(myIdevice.title, "My Idevice")
        self.assertEquals(myIdevice.author, "UoA")
        self.assertEquals(myIdevice.purpose, "Testing")
        self.assertEquals(myIdevice.tip, "Help tip")

    def testSetParentNode(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        self.assert_(idevice0.parentNode is parentNode)

    def testIsfirstAndIsLast(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice1.setParentNode(parentNode)
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        idevice2.setParentNode(parentNode)

        self.assert_(idevice0.isFirst)
        self.assert_(idevice2.isLast)

    def testCmp(self):
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        self.assertEquals(idevice2.__cmp__(idevice1), 1)
        self.assertEquals(idevice1.__cmp__(idevice0), 1)
        self.assertEquals(idevice0.__cmp__(idevice2), -1)

    def testDelete(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice1.setParentNode(parentNode)
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        idevice2.setParentNode(parentNode)
        idevice1.delete()
        if idevice1 in parentNode.idevices:
            print "delete failed"

    def testMove(self):
        parentNode = Node(self.package)
        idevice0 = Idevice("FirstIdevice", "", "", "", "")
        idevice0.setParentNode(parentNode)
        idevice1 = Idevice("SecondIdevice", "", "", "", "")
        idevice1.setParentNode(parentNode)
        idevice2 = Idevice("ThirdIdevice", "", "", "", "")
        idevice2.setParentNode(parentNode)

        idevice0.moveNext()
        self.assertEquals(parentNode.idevices[1], idevice0)
        self.assertEquals(parentNode.idevices[0], idevice1)

        idevice2.movePrev()
        self.assertEquals(parentNode.idevices[1], idevice2)
        self.assertEquals(parentNode.idevices[2], idevice0)
 def setUp(self):
     self.packageStore = PackageStore()
     self.package = self.packageStore.createPackage()
Exemple #24
0
 def setUp(self):
     SuperTestCase.check_application_for_test()
     packageStore = PackageStore()
     self.package = packageStore.createPackage()
Exemple #25
0
class TestPackage(unittest.TestCase):
    def setUp(self):
        self.packageStore = PackageStore()
    def testCreatePackage(self):
        package      = self.packageStore.createPackage()
        self.assert_(package)
        self.assert_(package.name)
    def testSaveAndLoad(self):
        package = self.packageStore.createPackage()
        self.assertEquals(package.name, "newPackage")
        package.author = "UoA"
        Config._getConfigPathOptions = lambda s: ['exe.conf']
        config  = Config()
        package.save(config.dataDir/'package1.elp')
        filePath = config.dataDir/'package1.elp'
        package1 = self.packageStore.loadPackage(filePath)
        self.assert_(package1)
        self.assertEquals(package1.author, "UoA")
        self.assertEquals(package.name, "package1")
        self.assertEquals(package1.name, "package1")
    def testfindNode(self):
        package = self.packageStore.createPackage()
        node1 = package.root.createChild()
        self.assertEquals(package.findNode(node1.id), node1)
    def testLevelName(self):
        package = self.packageStore.createPackage()
        package._levelNames = ["Month", "Week", "Day"]
        self.assertEquals(package.levelName(0), "Month")
        self.assertEquals(package.levelName(1), "Week")
        self.assertEquals(package.levelName(2), "Day")
    def testNodeIds(self):
        package = self.packageStore.createPackage()
        assert package._nextNodeId == 1, package._nextNodeId
        assert package.findNode(package.root.id) is package.root
        newNode = Node(package, package.root)
        assert package.findNode('123') is None
        assert package.findNode(newNode.id) is newNode
        package.name = 'testing'
        package.save('testing.elp')
        package2 = package.load('testing.elp')
        def checkInst(inst1, inst2):
            d1 = inst1.__dict__
            d2 = inst2.__dict__
            for key, val in d1.items():
                val2 = d2.get(key)
                if key == 'parentNode' and isinstance(val, Node):
                    assert val2.title.title == val.title.title
                elif key == 'package':
                    assert val is package
                    assert val2 is package2
                elif isinstance(val, list):
                    assert len(val) == len(val2)
                    for i, i2 in zip(val, val2):
                        if isinstance(i, basestring):
                            assert (i == i2, 
                                    '%s.%s: [%s/%s]' % 
                                    (inst1.__class__.__name__, key, i2, i))
                        else:
                            checkInst(i, i2)
                elif key == '_nodeIdDict' and isinstance(val, dict):
                    assert len(val) == len(val2)
                    for nodeName in val:
                        assert val2.has_key(nodeName)
                elif isinstance(val, Node):
                    pass
                elif key in Package.nonpersistant:
                    assert d2.has_key(key)
                else:
                    self.assertEquals(val, val2)
                    assert val == val2, '%s.%s: %s/%s' % (inst1.__class__.__name__, key, val2, val)
        checkInst(package, package2)
Exemple #26
0
 def setUp(self):
     self.packageStore = PackageStore()
Exemple #27
0
 def setUp(self):
     SuperTestCase.check_application_for_test()
     packageStore = PackageStore()
     self.package = packageStore.createPackage()
Exemple #28
0
 def __init__(self, *args, **kwargs):
     server.Session.__init__(self, *args, **kwargs)
     self.packageStore = PackageStore()
     self.oauthToken = {}
Exemple #29
0
class Application:
    """
    Main application class, pulls together everything and runs it.
    """

    def __init__(self):
        """
        Initialize
        """
        self.config       = None
        self.packageStore = None
        self.ideviceStore = None
        self.packagePath  = None
        self.webServer    = None
        self.standalone   = False # Used for the ready to run exe
        self.persistNonPersistants = False  
        self.tempWebDir   = mkdtemp('.eXe')
        self.afterUpgradeHandlers = []
        assert globals.application is None, "You tried to instantiate two Application objects"
        globals.application = self

    def main(self):
        """
        Main function, starts eXe
        """
        self.processArgs()

        self.loadConfiguration()
        try:
            username = getpass.getuser()
        except ImportError:
            username = ''
        eXeStart = globals.application.tempWebDir
        eXeStart = re.sub("[\/|\\\\][^\/|\\\\]*$","",eXeStart)
        eXeStart = eXeStart + '/tmpExeStartupTime.' + username

        if os.path.exists(eXeStart):
            inStartFH=open(eXeStart, "r")
            lastRunTimeS = 0
            for line in inStartFH:
                try:
                    lastRunTimeS = int(line)
                except ValueError:
                    lastRunTimeS = 0
            inStartFH.close()
            log.debug('lastRunTimeS: ' + `lastRunTimeS`)

            currentTime = int (time.time())
            currentTime2 = int (time.time())
            log.info('currentTime: ' + `currentTime`)
            if(currentTime <= lastRunTimeS + 3 and currentTime >= lastRunTimeS):
                #self.xulMessage(_('eXe appears to already be running'))
                #log.info('eXe appears to already be running: <html:br/>lastRunTimes: ' + `lastRunTimeS` + '<html:br/> currentTime: ' + `currentTime` + '<html:br/>currentTime2: ' + `currentTime2`)
                return None

        else:
            log.info('eXeStart: ' + eXeStart)
            log.info('tempWebDir: ' + globals.application.tempWebDir)

        # if a document was double clicked to launch on Win32,
        #   make sure we have the long pathname
        if sys.platform[:3] == "win" and self.packagePath is not None:
            self.packagePath = self.config.getLongPathName(self.packagePath)

        installSafeTranslate()
        self.preLaunch()
        # preLaunch() has called find_port() to set config.port (the IP port #)
        if self.config.port >= 0:
            self.launch()
            log.info('serving')
            self.serve()
            log.info('done serving')
        else:
            #self.xulMessage(_('eXe appears to already be running'))
            log.error('eXe appears to already be running')
            log.error('looks like the eXe server was not able to find a valid port; terminating...')
        shutil.rmtree(self.tempWebDir, True)
        try:
            os.remove(eXeStart)
        except OSError:
            pass

    def processArgs(self):
        """
        Processes the command line arguments
        """
        try:
            options, packages = getopt(sys.argv[1:], 
                                       "hV", ["help", "version", "standalone"])
        except GetoptError:
            self.usage()
            sys.exit(2)

        if len(packages) == 1:
            self.packagePath = packages[0]

        elif len(packages) > 1:
            self.usage()
            sys.exit(2)

        for option in options:
            if option[0] in ("-V", "--version"):
                print "eXe", version.version
                sys.exit()
            elif option[0] in ("-h", "--help"):
                self.usage()
                sys.exit()
            elif option[0].lower() == '--standalone':
                self.standalone = True

    
    def loadConfiguration(self):
        """
        Loads the config file and applies all the settings
        """
        if self.standalone:
            from exe.engine.standaloneconfig import StandaloneConfig
            self.config = StandaloneConfig()
        elif sys.platform[:3] == "win":
            from exe.engine.winconfig import WinConfig
            self.config = WinConfig()
        elif sys.platform[:6] == "darwin":
            from exe.engine.macconfig import MacConfig
            self.config = MacConfig()
        else:
            from exe.engine.linuxconfig import LinuxConfig
            self.config = LinuxConfig()
        log.debug("logging set up")


    def preLaunch(self):
        """
        Sets ourself up for running 
        Needed for unit tests
        """
        log.debug("preLaunch")
        self.packageStore = PackageStore()
        self.ideviceStore = IdeviceStore(self.config)
        self.ideviceStore.load()
        # Make it so jelly can load objects from ~/.exe/idevices
        sys.path.append(self.config.configDir/'idevices')
        self.webServer = WebServer(self)
        # and determine the web server's port before launching the client, so it can use the same port#:
        self.webServer.find_port()


    def serve(self):
        """
        Starts the web server,
        this func doesn't return until after the app has finished
        """
        print "Welcome to eXe: the eLearning XHTML editor"
        log.info("eXe running...")
        self.webServer.run()

    def _loadPackage(self, packagePath):
        #"""
        #Convenience function for loading the first package that we'll browse to
        #"""
        try:
            #XXXX xxxx
            log.info("webDir: " + self.config.webDir)
            log.info("tempWebDir: " + self.tempWebDir)
            inSplashFile =  self.config.webDir + "/docs/splash.xulTemplate"

            outSplashFile = self.config.webDir + "/docs/splash.xul"
            outSplashData = self.config.webDir + "/docs/splash.dat"

            outSplashFile = self.tempWebDir + "/splash.xul"
            outSplashData = self.tempWebDir + "/splash.dat"

            log.info("inSplashFile: " + inSplashFile)
            log.info("outSplashFile: " + outSplashFile)
            log.info("outSplashData: " + outSplashData)

            #resets any splash page data
            outSplashFH = open(outSplashData, "w")
            outSplashFH.write("")
            outSplashFH.close()

            inSplashFH = open(inSplashFile, "r")
            outSplashFH = open(outSplashFile, "w")
            pleaseWaitLoad = _(u'Please wait until loading finishes')
            for line in inSplashFH:
                line = line.replace("LOADING_FILE_NAME", packagePath)
                try:
                    # this can fail in non UTF-8 uris
                    line = line.replace("PLEASE_WAIT_LOAD", pleaseWaitLoad)
                except:
                    pass
                outSplashFH.write(line)
            inSplashFH.close()
            outSplashFH.close()
   
            log.info("packagePath: " + packagePath)

            launchBrowser(self.config, outSplashFile, "splash")
            shutil.copyfile(self.config.webDir + '/images/exe_logo.png', 
                                      self.tempWebDir + '/exe_logo.png')

            package = self.packageStore.loadPackage(packagePath)
            port = self.config.port
            editorUrl = u'http://127.0.0.1:%d/%s' % (port, package.name)
            log.info("package.name: "+package.name)
            log.info("editorUrl: " + editorUrl)
            log.info("TempDirPath: " + editorUrl)
            outSplashFH = open(outSplashData, "w")
            outSplashFH.write("1000;" + editorUrl)
            outSplashFH.close()

            self.webServer.root.bindNewPackage(package)
            return package

        except Exception, e:
            log.error('Error loading first Package (%s): %s' % (packagePath, e))
            message = _(u'Sorry, wrong file format')

            outSplashFH=open(globals.application.tempWebDir + \
                               '/splash.dat',"w")
            message = re.sub(";",":",message)
            port = self.config.port
            outSplashFH.write("1000;http://127.0.0.1:" + `port` + "/;" + \
                               message)
            outSplashFH.close()

            return None