def __init__(self, options): format = '[%(asctime)s] %(levelname)s:%(name)s:%(message)s' datefmt = '%a %b %d %H:%M:%S %Y' logging.basicConfig(level=logging.INFO, format=format, datefmt=datefmt) CONFIG.update_etc(options['configfile']) CONFIG.update_cmdline(options) CONFIG.set_timezone() if CONFIG['logfile']: logf = CONFIG['logfile'] # test if the directories exist, else create them try: diff = 0 if os.path.isfile(logf): diff = int(time.time()) - int(os.stat(logf)[-1]) handler = logging.handlers.TimedRotatingFileHandler( logf, 'D', 1, 30) handler.rolloverAt -= diff except Exception, exception: sys.stderr.write( "ERROR: couldn't create the logfile directory:" + str(exception)) else: formatter = logging.Formatter(format, datefmt) # tell the handler to use this format handler.setFormatter(formatter) # add the handler to the root logger logging.getLogger().addHandler(handler) logging.getLogger().setLevel(logging.INFO)
def run(config, host, port, debug, threaded): """ Runs the application on a local development server. """ if config: CONFIG.update_etc(config) if hasattr(CONFIG, 'set_timezone'): CONFIG.set_timezone() from application import app app.run(host, port, debug=debug, threaded=threaded)
def run(config, host, port, debug, threaded): """ Runs the application on a local development server. """ if config: CONFIG.update_etc(config) if hasattr(CONFIG, 'set_timezone'): CONFIG.set_timezone() from application import app app.run(host, port, debug=debug, threaded=threaded)
def __init__(self, database_name=None, user='******', database_type=None, language='en_US', password='', config_file=None): super(TrytondConfig, self).__init__() from trytond.config import CONFIG CONFIG.update_etc(config_file) CONFIG.set_timezone() if database_type is not None: CONFIG['db_type'] = database_type from trytond.pool import Pool from trytond import backend from trytond.protocols.dispatcher import create from trytond.cache import Cache from trytond.transaction import Transaction self.database_type = CONFIG['db_type'] if database_name is None: if self.database_type == 'sqlite': database_name = ':memory:' else: database_name = 'test_%s' % int(time.time()) self.database_name = database_name self._user = user self.config_file = config_file Pool.start() with Transaction().start(None, 0) as transaction: cursor = transaction.cursor databases = backend.get('Database').list(cursor) if database_name not in databases: create(database_name, CONFIG['admin_passwd'], language, password) database_list = Pool.database_list() self.pool = Pool(database_name) if database_name not in database_list: self.pool.init() with Transaction().start(self.database_name, 0) as transaction: Cache.clean(database_name) User = self.pool.get('res.user') transaction.context = self.context self.user = User.search([ ('login', '=', user), ], limit=1)[0].id with transaction.set_user(self.user): self._context = User.get_preferences(context_only=True) Cache.resets(database_name)
def load_backend(self): """ This method loads the configuration file if specified and also connects to the backend, initialising the pool on the go """ if self.tryton_configfile is not None: warnings.warn(DeprecationWarning( 'TRYTON_CONFIG configuration will be deprecated in future.' )) CONFIG.update_etc(self.tryton_configfile) CONFIG.set_timezone() register_classes() # Load and initialise pool Database = backend.get('Database') self._database = Database(self.database_name).connect() self._pool = Pool(self.database_name) self._pool.init()
def load_backend(self): """ This method loads the configuration file if specified and also connects to the backend, initialising the pool on the go """ if self.tryton_configfile is not None: from trytond.config import CONFIG CONFIG.update_etc(self.tryton_configfile) CONFIG.set_timezone() from trytond import backend from trytond.modules import register_classes register_classes() from trytond.pool import Pool # Load and initialise pool Database = backend.get('Database') self._database = Database(self.database_name).connect() self._pool = Pool(self.database_name) self._pool.init()
def load_backend(self): """ This method loads the configuration file if specified and also connects to the backend, initialising the pool on the go """ if self.tryton_configfile is not None: warnings.warn( DeprecationWarning( 'TRYTON_CONFIG configuration will be deprecated in future.' )) CONFIG.update_etc(self.tryton_configfile) CONFIG.set_timezone() register_classes() # Load and initialise pool Database = backend.get('Database') self._database = Database(self.database_name).connect() self._pool = Pool(self.database_name) self._pool.init()