Exemplo n.º 1
0
 def testUpgradeAppDir(self):
     """
     Tests that config files with
     'appDataDir' are upgraded to 'configDir'
     """
     # Write the old style config file
     configPath = Path(u'test.exe.conf')
     if configPath.exists():
         configPath.remove()
     oldParser = ConfigParser()
     system = oldParser.addSection('system')
     system.appDataDir = 'my old app data dir'
     oldParser.write(configPath)
     del system
     del oldParser
     # Make the config instance load it
     Config._getConfigPathOptions = lambda self: ['test.exe.conf']
     myconfig = Config()
     myconfig.loadSettings()
     # Check if it reads the old value into the new variable
     assert not hasattr(myconfig, 'appDataDir')
     self.assertEquals(myconfig.configPath, 'test.exe.conf')
     self.assertEquals(myconfig.configDir, 'my old app data dir')
     # Check if it has upgraded the file and added in some nice default values
     newParser = ConfigParser()
     newParser.read(configPath)
     self.assertEquals(newParser.system.configDir, 'my old app data dir')
Exemplo n.º 2
0
 def testReadFileName(self):
     """Can read text"""
     goodDict = {'second': 
                     {'good': 'yes',
                      'bad': 'no',
                       'available': 'yes',
                       'funny-name_mate': 'crusty the clown'}, 
                 'main': 
                     {'running': u'on\t\u0100\u01100',
                      'testing': 'false',
                      'two words': 'are better than one',
                      'no_value': '',
                      'power': 'on',
                      'level': '5'}}
     file_ = open('temp.ini', 'w')
     file_.write(TEST_TEXT)
     file_.close()
     self.c.read('temp.ini')
     assert self.c._sections == goodDict, self.c._sections
     # Can read unicode filenames
     self.c = ConfigParser()
     self.c.read(u'temp.ini')
     assert self.c._sections == goodDict, self.c._sections
     # Can read funny string object filenames
     class MyStr(str):
         """Simply overrides string to make it a different type"""
     self.c.read(MyStr('temp.ini'))
     assert self.c._sections == goodDict, self.c._sections
Exemplo n.º 3
0
 def testCreation(self):
     """
     When one creates a section with the same name
     as an existing section the existing section should
     just be returned
     """
     mysec = Section('main', self.c)
     assert mysec is self.c.main
     othersec = Section('main', self.c)
     assert othersec is mysec is self.c.main is self.c._sections['main']
     newsec = Section('newsection', self.c)
     assert newsec is \
            self.c.addSection('newsection') is \
            self.c.newsection is \
            self.c._sections['newsection']
     newsec2 = self.c.addSection('newsection2')
     assert newsec2 is \
            self.c.addSection('newsection2') is \
            Section('newsection2', self.c) is \
            self.c.newsection2 is \
            self.c._sections['newsection2'] and \
            newsec2 is not newsec
     # Different parent should create new object
     otherConf = ConfigParser()
     sec1 = otherConf.addSection('x')
     sec2 = self.c.addSection('x')
     assert sec1 is not sec2
Exemplo n.º 4
0
 def testUnicodeFileName(self):
     """
     Should be able to write to unicode filenames
     """
     # Invent a unicode filename
     dirName = unicode('\xc4\x80\xc4\x900', 'utf8')
     fn = os.path.join(dirName, dirName)
     fn += '.ini'
     if not os.path.exists(dirName):
         os.mkdir(dirName)
     # Write some test data to our unicode file
     file_ = open(fn, 'wb')
     file_.write(TEST_TEXT)
     file_.close()
     # See if we can read and write it
     self.c.read(fn)
     self.assertEquals(self.c.main.power, 'on')
     self.c.main.power = 'off'
     self.c.write()
     # Check that it was written ok
     c2 = ConfigParser()
     c2.read(fn)
     self.assertEquals(c2.main.power, 'off')
     # Clean up
     os.remove(fn)
     os.rmdir(dirName)
Exemplo n.º 5
0
    def setUp(self):
        """
        Creates an application and
        almost launches it.
        """
        # Make whatever config class that application uses only look for our
        # Set up our customised config file
        logFileName = Path('tmp/app data/test.conf')
        sys.argv[0] = 'exe/exe'
        Config._getConfigPathOptions = lambda s: [logFileName]
        if not logFileName.dirname().exists():
            logFileName.dirname().makedirs()
        confParser = ConfigParser()
        self._setupConfigFile(confParser)
        confParser.write(logFileName)
        # Start up the app and friends
        if G.application is None:
            G.application = Application()

        self.app = G.application
        G.application = self.app
        self.app.loadConfiguration()
        self.app.preLaunch()
        self.client = FakeClient()
        self.package = Package('temp')
        self.session = FakeSession()
        self.app.webServer.root.bindNewPackage(self.package, self.session)
        self.mainpage = self.app.webServer.root.mainpages[
            self.session.uid]['temp']
        self.mainpage.idevicePane.client = self.client
Exemplo n.º 6
0
 def setUp(self):
     """
     Creates a ConfigParser to play with and
     reads in the test text
     """
     self.c = ConfigParser()
     file_ = testFile()
     self.c.read(file_)
Exemplo n.º 7
0
 def testFromScratch(self):
     """
     Tests adding stuff from nothing
     """
     x = ConfigParser()
     testing = x.addSection('testing')
     assert x.testing is testing
     testing.myval = 4
     self.assertEquals(x.get('testing', 'myval'), '4')
Exemplo n.º 8
0
 def testStringIO(self):
     file_ = testFile()
     c = ConfigParser()
     c.read(file_)
     c.autoWrite = True
     assert 'Matthew' not in self.getVal(file_)
     c.main.name = 'Matthew'
     assert 'name = Matthew' in self.getVal(file_), self.getVal(file_)
     del c.main.name
     assert 'Matthew' not in self.getVal(file_)
Exemplo n.º 9
0
 def testShortening(self):
     """There was a bug (Issue 66) where when a longer name was read
     and a shorter name was written, the extra characters of the 
     longer name would remain in the entry"""
     file_ = open('temp.ini', 'w')
     file_.write(TEST_TEXT)
     file_.close()
     self.c.read('temp.ini')
     self.c.set('second', 'available', 'abcdefghijklmnop')
     self.c.write('temp.ini')
     c2 = ConfigParser()
     c2.read('temp.ini')
     c2.set('second', 'available', 'short')
     c2.write('temp.ini')
     self.c.read('temp.ini')
     assert self.c.get('second', 'available', '') == 'short', \
         self.c.get('second', 'available', '')
Exemplo n.º 10
0
    def check_application_for_test(cls):
        logFileName = Path('tmp/app data/test.conf')
        sys.argv[0] = 'exe/exe'
        Config._getConfigPathOptions = lambda s: [logFileName]
        if not logFileName.dirname().exists():
            logFileName.dirname().makedirs()
        confParser = ConfigParser()
        SuperTestCase.update_config_parser(confParser)
        confParser.write(logFileName)

        if G.application is None:
            G.application = Application()

            G.application.loadConfiguration()
            SuperTestCase.update_config_parser(
                G.application.config.configParser)
            G.application.config.loadSettings()

            G.application.preLaunch()
Exemplo n.º 11
0
 def testUnicodeSet(self):
     """
     Should be able to set unicode option values
     with both python internal unicode strings
     or raw string containing utf8 encoded data
     """
     file_ = open('temp.ini', 'w')
     file_.write(TEST_TEXT)
     file_.close()
     self.c.read('temp.ini')
     self.c.set('main', 'power', '\xc4\x80\xc4\x900')
     self.c.set('main', 'name', unicode('\xc4\x80\xc4\x900', 'utf8'))
     self.c.set('newSecy', 'unicode', unicode('\xc4\x80\xc4\x900', 'utf8'))
     self.c.write('temp.ini')
     c2 = ConfigParser()
     c2.read('temp.ini')
     val = unicode('\xc4\x80\xc4\x900', 'utf8')
     self.assertEquals(c2.main.power, val)
     self.assertEquals(c2.main.name, val)
     self.assertEquals(c2.newSecy.unicode, val)
Exemplo n.º 12
0
 def setUp(self):
     """
     Creates an application and 
     almost launches it.
     """
     # Make whatever config class that application uses only look for our
     # Set up our customised config file
     logFileName = Path('tmp/app data/test.conf')
     Config._getConfigPathOptions = lambda s: [logFileName]
     if not logFileName.dirname().exists():
         logFileName.dirname().makedirs()
     confParser = ConfigParser()
     self._setupConfigFile(confParser)
     confParser.write(logFileName)
     # Start up the app and friends
     self.app = Application()
     self.app.loadConfiguration()
     self.app.preLaunch()
     self.client = FakeClient()
     self.package = Package('temp')
     self.app.webServer.root.bindNewPackage(self.package)
     self.mainpage = self.app.webServer.root.children['temp']
Exemplo n.º 13
0
 def __init__(self):
     """
     Initialise
     """
     self.configPath = None
     self.configParser = ConfigParser(self.onWrite)
     # Set default values
     # idevices is the list of hidden idevices selected by the user
     self.someone = 0
     # exePath is the whole path and filename of the exe executable
     self.exePath = Path(sys.argv[0]).abspath()
     # webDir is the parent directory for styles,scripts and templates
     self.webDir = self.exePath.dirname()
     # xulDir is the parent directory for styles,scripts and templates
     self.xulDir = self.exePath.dirname()
     # localeDir is the base directory where all the locales are stored
     self.localeDir = self.exePath.dirname() / "locale"
     # port is the port the exe webserver will listen on
     # (previous default, which earlier users might still use, was 8081)
     self.port = 51235
     # dataDir is the default directory that is shown to the user
     # to save packages and exports in
     self.dataDir = Path(".")
     # configDir is the dir for storing user profiles
     # and user made idevices and the config file
     self.configDir = Path(".")
     # browserPath is the entire pathname to firefox
     self.browserPath = Path("firefox")
     # locale is the language of the user
     self.locale = chooseDefaultLocale(self.localeDir)
     # internalAnchors indicate which exe_tmp_anchor tags to generate for each tinyMCE field
     # available values = "enable_all", "disable_autotop", or "disable_all"
     self.internalAnchors = "enable_all"
     # styles is the list of style names available for loading
     self.styles = []
     # The documents that we've recently looked at
     self.recentProjects = []
     # canonical (English) names of iDevices not to show in the iDevice pane
     self.hiddeniDevices = []
     # likewise, a canonical (English) names of iDevices not to show in the
     # iDevice pane but, contrary to the hiddens, these are ones that the
     # configuration can specify to turn ON:
     self.deprecatediDevices = [ "flash with text", "flash movie", "mp3", \
                                 "attachment"]
     # by default, only allow embedding of media types for which a
     # browser plugin is found:
     self.assumeMediaPlugins = False
     # Let our children override our defaults depending
     # on the OS that we're running on
     self._overrideDefaultVals()
     # Try to make the defaults a little intelligent
     # Under devel trees, webui is the default webdir
     self.webDir = Path(self.webDir)
     if not (self.webDir/'scripts').isdir() \
        and (self.webDir/'webui').isdir():
         self.webDir /= 'webui'
     # Under devel trees, xului is the default xuldir
     self.xulDir = Path(self.xulDir)
     if not (self.xulDir/'scripts').isdir() \
        and (self.xulDir/'xului').isdir():
         self.xulDir /= 'xului'
     # Find where the config file will be saved
     self.__setConfigPath()
     # Fill in any undefined config options with our defaults
     self._writeDefaultConfigFile()
     # Now we are ready to serve the application
     self.loadSettings()
     self.setupLogging()
     self.loadStyles()
     self.loadLocales()
Exemplo n.º 14
0
    def __init__(self):
        """
        Initialise
        """
        self.configPath = None
        self.configParser = ConfigParser(self.onWrite)
        # Set default values
        # exePath is the whole path and filename of the exe executable
        self.exePath     = Path(sys.argv[0]).abspath()
        # webDir is the parent directory for styles,scripts and templates
        self.webDir      = self.exePath.dirname()
        self.jsDir       = self.exePath.dirname()
        self.locales     = {}
        # localeDir is the base directory where all the locales are stored
        self.localeDir   = self.exePath.dirname()/"locale"
        # port is the port the exe webserver will listen on
        # (previous default, which earlier users might still use, was 8081)
        self.port        = 51235
        # dataDir is the default directory that is shown to the user
        # to save packages and exports in
        self.dataDir     = Path(".")
        # configDir is the dir for storing user profiles
        # and user made idevices and the config file
        self.configDir   = Path(".")
        # FM: New Styles Directory path
        self.stylesDir   = Path(self.configDir/'style').abspath()
        # FM: Default Style name
        self.defaultStyle = u"INTEF"
        # Styles repository XML-RPC endpoint
        # self.stylesRepository = 'http://www.exelearning.es/xmlrpc.php'
        self.stylesRepository = 'http://www.exelearning.net/xmlrpc.php'
        # browser is the name of a predefined browser specified
        # at http://docs.python.org/library/webbrowser.html.
        # None for system default
        self.browser = None
        # docType  is the HTML export format
        self.docType = 'HTML5'
        # internalAnchors indicate which exe_tmp_anchor tags to generate for each tinyMCE field
        # available values = "enable_all", "disable_autotop", or "disable_all"
        self.internalAnchors = "enable_all"
        self.lastDir = None
        self.showPreferencesOnStart = "1"
        self.showIdevicesGrouped = "1"
        # tinymce option
        self.editorMode = 'permissive'
        self.editorVersion = '4'
        # styleSecureMode : if this [user] key is = 0  , exelearning can run python files in styles
        # as websitepage.py , ... ( deactivate secure mode )
        self.styleSecureMode = "1"
        # styles is the list of style names available for loading
        self.styles = []
        # The documents that we've recently looked at
        self.recentProjects = []
        # canonical (English) names of iDevices not to show in the iDevice pane
        self.hiddeniDevices = []
        # Media conversion programs used for XML export system
        self.videoMediaConverter_ogv = ""
        self.videoMediaConverter_3gp = ""
        self.videoMediaConverter_avi = ""
        self.videoMediaConverter_mpg = ""
        self.audioMediaConverter_ogg = ""
        self.audioMediaConverter_au = ""
        self.audioMediaConverter_mp3 = ""
        self.audioMediaConverter_wav = ""
        self.ffmpegPath = ""
        self.mediaProfilePath = self.exePath.dirname()/'mediaprofiles'

        # likewise, a canonical (English) names of iDevices not to show in the
        # iDevice pane but, contrary to the hiddens, these are ones that the
        # configuration can specify to turn ON:
        self.deprecatediDevices = ["flash with text", "flash movie", "mp3",
                                   "attachment"]
        # by default, only allow embedding of media types for which a
        # browser plugin is found:

        self.defaultLicense='creative commons: attribution - share alike 4.0'

        self.assumeMediaPlugins = False
        # Let our children override our defaults depending
        # on the OS that we're running on
        self._overrideDefaultVals()
        # locale is the language of the user. localeDir can be overridden
        # that's why we must set it _after_ the call to _overrideDefaultVals()
        self.locale = chooseDefaultLocale(self.localeDir)
        # Try to make the defaults a little intelligent
        # Under devel trees, webui is the default webdir
        self.webDir = Path(self.webDir)
        if not (self.webDir/'scripts').isdir() \
           and (self.webDir/'webui').isdir():
            self.webDir /= 'webui'
        self.jsDir = Path(self.jsDir)
        if not (self.jsDir/'scripts').isdir() \
           and (self.jsDir/'jsui').isdir():
            self.jsDir /= 'jsui'
        # Find where the config file will be saved
        self.__setConfigPath()
        # Fill in any undefined config options with our defaults
        self._writeDefaultConfigFile()
        # Now we are ready to serve the application
        self.loadSettings()
        self.setupLogging()
        self.loadLocales()
        self.loadStyles()
Exemplo n.º 15
0
 def getConfigPath(cls):
     obj = cls.__new__(cls)
     obj.configParser = ConfigParser()
     obj._overrideDefaultVals()
     obj.__setConfigPath()
     return obj.configPath
Exemplo n.º 16
0
 def setUp(self):
     """
     Creates a ConfigParser to play with
     """
     self.c = ConfigParser()