예제 #1
0
    def test_set_and_save(self):
        config = self._read()
        config.set('b', 'option0', 'y')
        config.set('a', 'option0', 'x')
        config.set('a', 'option2', "Voilà l'été")  # UTF-8
        config.set('a', 'option1', u"Voilà l'été") # unicode
        # Note: the following would depend on the locale.getpreferredencoding()
        # config.set('a', 'option3', "Voil\xe0 l'\xe9t\xe9") # latin-1
        self.assertEquals('x', config.get('a', 'option0'))
        self.assertEquals(u"Voilà l'été", config.get('a', 'option1'))
        self.assertEquals(u"Voilà l'été", config.get('a', 'option2'))
        config.save()

        configfile = open(self.filename, 'r')
        self.assertEquals(['# -*- coding: utf-8 -*-\n',
                           '\n',
                           '[a]\n',
                           'option0 = x\n', 
                           "option1 = Voilà l'été\n", 
                           "option2 = Voilà l'été\n", 
                           # "option3 = Voilà l'été\n", 
                           '\n',
                           '[b]\n',
                           'option0 = y\n', 
                           '\n'],
                          configfile.readlines())
        configfile.close()
        config2 = Configuration(self.filename)
        self.assertEquals('x', config2.get('a', 'option0'))
        self.assertEquals(u"Voilà l'été", config2.get('a', 'option1'))
        self.assertEquals(u"Voilà l'été", config2.get('a', 'option2'))
예제 #2
0
 def __init__(self, methodName='runTest', filename=None):  # @UnusedVariable
     """
     Initialize the test procedure.
     """
     unittest.TestCase.__init__(self, methodName)
     self.default_config = Configuration()
     #set a few standard settings
     self.default_config.set('seishub', 'log_level', 'OFF')
     self.default_config.set('seishub', 'auth_uri', 'sqlite://')
     self.default_config.set('db', 'uri', USE_TEST_DB)
     self.default_config.set('db', 'verbose', VERBOSE_DATABASE)
예제 #3
0
 def __init__(self,
              path,
              application=None,
              config_file="seishub.ini",
              log_file="seishub.log",
              create=None):
     """
     Initialize the SeisHub environment.
     """
     # set application
     self.app = application
     self._path = path
     # check Python version
     if not sys.hexversion >= 0x2060000:
         print("ERROR: SeisHub needs at least Python 2.6 or higher in " +
               "order to run.")
         exit()
     if not sys.hexversion <= 0x3000000:
         print("ERROR: SeisHub is not yet compatible with Python 3.x.")
         exit()
     # check if new environment must be created
     if create:
         self.create(path)
     # set a start up timestamp
     self.startup_time = int(time.time())
     # set configuration handler
     if isinstance(config_file, Configuration):
         self.config = config_file
     else:
         config_file = os.path.join(path, 'conf', config_file)
         self.config = Configuration(config_file)
     self.config.path = path
     self.config.hubs = {}
     # set log handler
     self.log = Logger(self, log_file)
     # initialize all default options
     self.initDefaultOptions()
     # set up DB handler
     self.db = DatabaseManager(self)
     # set up component manager
     ComponentManager.__init__(self)
     self.compmgr = self
     # initialize all default options
     self.initDefaultOptions()
     # set XML catalog
     self.catalog = XmlCatalog(self)
     # user and group management
     self.auth = AuthenticationManager(self)
     # load plug-ins
     ComponentLoader(self)
     # Package manager
     # initialize ComponentRegistry after ComponentLoader(), as plug-ins
     # may provide registry objects
     self.registry = ComponentRegistry(self)
     # trigger auto installer
     PackageInstaller.install(self)
     # initialize the resource tree
     self.tree = ResourceTree(self)
     self.update()
     # XSLT transformation parameters
     self.xslt_params = {}
     # check if new environment has been created
     if create:
         exit()