def __init__(self, **kwargs): """Creates a new OpenERP service. :param \**kwargs: keyword arguments passed to the config """ config = config_from_environment('OPENERP', [], **kwargs) import netsvc import tools update_config(tools.config, **config) if hasattr(tools.config, 'parse'): tools.config.parse() from tools import config as default_config self.config = update_config(default_config, **config) import pooler import workflow self.pooler = pooler self.db = None self.pool = None if 'db_name' in config: try: self.db_name = config['db_name'] except psycopg2.OperationalError as e: logger.info("Error opening named database '%s', creating it", config['db_name']) self.db_name = self.create_database(False, db_name=config['db_name']) # Stop the cron netsvc.Agent.quit()
def __init__( self, queue_name="default", max_procs=None, skip_failed=True, default_result_ttl=DEFAULT_RESULT_TTL, ): self.queue_name = queue_name if max_procs is None: self.max_procs = MAX_PROCS elif 1 <= max_procs < MAX_PROCS + 1: self.max_procs = max_procs else: raise ValueError("Max procs {} not supported".format(max_procs)) self.processes = [] self.config = config_from_environment( "AUTO_WORKER", ["redis_url"], queue_class="rq.Queue", worker_class="rq.Worker", job_class="rq.Job", ) self.skip_failed = skip_failed self.default_result_ttl = default_result_ttl self.connection = Redis.from_url(self.config["redis_url"]) queue_class = import_attribute(self.config["queue_class"]) self.queue = queue_class(queue_name, connection=self.connection)
def __init__(self, **kwargs): """Creates a new OpenERP service. :param \**kwargs: keyword arguments passed to the config """ config = config_from_environment('OPENERP', [], **kwargs) import netsvc import tools update_config(tools.config, **config) if hasattr(tools.config, 'parse'): tools.config.parse() from tools import config as default_config self.config = update_config(default_config, **config) import pooler import workflow self.pooler = pooler self.db = None self.pool = None if 'db_name' in config: try: self.db_name = config['db_name'] except psycopg2.OperationalError as e: logger.info( "Error opening named database '%s', creating it", config['db_name']) self.db_name = self.create_database(False, db_name=config['db_name']) # Stop the cron netsvc.Agent.quit()
def get_spec_suite(module): """ Get spec suite to run Mamba :param module: Module to get the spec suite :return: suite """ spec_dir = os.path.join(module, 'spec') specs_dir = os.path.join(module, 'specs') junitxml = config_from_environment('DESTRAL', ['verbose', 'junitxml'], verbose=2, junitxml=False).get('junitxml', False) if os.path.exists(spec_dir) or os.path.exists(specs_dir): # Create a fake arguments object arguments = type('Arguments', (object, ), {}) arguments.specs = [spec_dir, specs_dir] arguments.slow = 0.075 arguments.enable_coverage = False arguments.format = 'junitxml' if junitxml else 'progress' arguments.no_color = True arguments.watch = False arguments.coverage_file = '.coverage' arguments.tags = None if 'erp/server/bin' in module: module = 'root_path' factory = JUnitXMLApplicationFactory(arguments, modulename=module, junitxml_file=junitxml) logger.info('Mamba application factory created for specs: {0}'.format( spec_dir)) return factory.runner() return None
def get_spec_suite(module): """ Get spec suite to run Mamba :param module: Module to get the spec suite :return: suite """ spec_dir = os.path.join(module, 'spec') specs_dir = os.path.join(module, 'specs') junitxml = config_from_environment( 'DESTRAL', ['verbose', 'junitxml'], verbose=2, junitxml=False ).get('junitxml', False) if os.path.exists(spec_dir) or os.path.exists(specs_dir): # Create a fake arguments object arguments = type('Arguments', (object, ), {}) arguments.specs = [spec_dir, specs_dir] arguments.slow = 0.075 arguments.enable_coverage = False arguments.format = 'junitxml' if junitxml else 'progress' arguments.no_color = True arguments.watch = False arguments.coverage_file = '.coverage' arguments.tags = None if 'erp/server/bin' in module: module = 'root_path' factory = JUnitXMLApplicationFactory( arguments, modulename=module, junitxml_file=junitxml) logger.info('Mamba application factory created for specs: {0}'.format( spec_dir )) return factory.runner() return None
def __init__( self, name="default", default_timeout=None, connection=None, is_async=True, job_class=None, max_workers=None, serializer=None, ): self.name = name self.config = config_from_environment( "AUTO_WORKER", ["redis_url"], queue_class="rq.Queue", worker_class="rq.Worker", job_class="rq.Job", ) super(AutoWorkerQueue, self).__init__( name=name, default_timeout=default_timeout, connection=connection, is_async=is_async, job_class=job_class, serializer=serializer, ) if max_workers is None: max_workers = MAX_PROCS self.max_workers = max_workers
def __init__(self, **kwargs): import sys sys.argv = [sys.argv[0]] config = config_from_environment('OPENERP', [], **kwargs) import netsvc logging.disable(logging.CRITICAL) import tools for key, value in config.iteritems(): tools.config[key] = value tools.config.parse() from tools import config as default_config for key, value in config.iteritems(): default_config[key] = value # Disable cron default_config['cron'] = False self.config = default_config import pooler import workflow self.pooler = pooler self.db = None self.pool = None if 'db_name' in config: self.db_name = config['db_name'] try: from netsvc import Agent Agent.quit() except ImportError: pass
def create_app(self): conf = config_from_environment('TEST', ['secret']) app = Flask(__name__) Backend(app, '/') #app.register_blueprint(backend, url_prefix='') app.config['TESTING'] = True app.config['SECRET_KEY'] = conf['secret'] return app
def setUp(self): self.config = config_from_environment('DESTRAL', ['module']) self.openerp = OpenERPService() self.drop_database = False if not self.openerp.db_name: self.openerp.db_name = self.openerp.create_database() self.drop_database = True self.openerp.install_module(self.config['module'])
def __init__(self, tests=()): super(OOTestSuite, self).__init__(tests) self.config = config_from_environment('DESTRAL', ['module'], use_template=True) ooconfig = {} self.config['use_template'] = False ooconfig['demo'] = {'all': 1} if self.config['module'] == 'base': ooconfig.setdefault('update', {}) ooconfig['update'].update({'base': 1}) self.openerp = OpenERPService(**ooconfig) self.drop_database = True
def run_unittest_suite(suite): """Run test suite """ logger.info('Running test suit: {0}'.format(suite)) confs = config_from_environment('DESTRAL', ['verbose', 'junitxml'], verbose=2, junitxml=False) verbose = confs.get('verbose', 2) junitxml = confs.get('junitxml', False) result = JUnitXMLResult if junitxml else unittest.TextTestResult return unittest.TextTestRunner(verbosity=verbose, resultclass=result, stream=LoggerStream).run(suite)
def __init__(self, tests=()): super(OOTestSuite, self).__init__(tests) self.config = config_from_environment( 'DESTRAL', ['module', 'testing_langs'], use_template=True, testing_langs=[] ) ooconfig = {} self.config['use_template'] = False ooconfig['demo'] = {'all': 1} if self.config['module'] == 'base': ooconfig.setdefault('update', {}) ooconfig['update'].update({'base': 1}) self.openerp = OpenERPService(**ooconfig) self.drop_database = True
def run_unittest_suite(suite): """Run test suite """ logger.info('Running test suit: {0}'.format(suite)) confs = config_from_environment( 'DESTRAL', ['verbose', 'junitxml'], verbose=2, junitxml=False ) verbose = confs.get('verbose', 2) junitxml = confs.get('junitxml', False) result = JUnitXMLResult if junitxml else unittest.TextTestResult return unittest.TextTestRunner( verbosity=verbose, resultclass=result, stream=LoggerStream ).run(suite)
def __init__(self, **kwargs): config = config_from_environment('OPENERP', [], **kwargs) import netsvc import tools update_config(tools.config, **config) tools.config.parse() from tools import config as default_config self.config = update_config(default_config, **config) import pooler import workflow self.pooler = pooler self.db = None self.pool = None if 'db_name' in config: self.db_name = config['db_name']
def setup_logging(logfile=None): log_config = config_from_environment('LOG') if log_config: logging.basicConfig(**log_config) logger = logging.getLogger('atr') if logfile: handler = logging.FileHandler(logfile) formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(message)s') handler.setFormatter(formatter) logger.addHandler(handler) sentry = Client() sentry.tags_context({'version': VERSION}) sentry_handler = SentryHandler(sentry, level=logging.ERROR) logger.addHandler(sentry_handler) logger.debug('ATR Logging setup done')
def __init__(self, **kwargs): """ Creates a new OpenERP service. :param kwargs: keyword arguments passed to the config """ if 'LOGGER_NAME' in kwargs: self.logger = logging.getLogger(kwargs['LOGGER_NAME']) else: self.logger = logging.getLogger('OpenERPService') import sys sys.argv = [sys.argv[0]] config = config_from_environment('OPENERP', [], **kwargs) import netsvc logging.disable(logging.CRITICAL) import tools for key, value in config.iteritems(): tools.config[key] = value if hasattr(tools.config, 'parse'): tools.config.parse() tools.config.parse() from tools import config as default_config for key, value in config.iteritems(): default_config[key] = value # Disable cron default_config['cron'] = False self.config = default_config import pooler import workflow self.pooler = pooler self.db = None self.pool = None self.DEFAULT_USER = 1 if 'db_name' in config: self.db_name = config['db_name'] try: from netsvc import Agent Agent.quit() except ImportError: pass
def load_config(self, config=None): """ Loads the configuration from the file :config_file: Configuration as a dict :return: None """ if not config: self.env_vars = config_from_environment('bard', ['config']) self.conf = ConfigObj(self.env_vars["config"]) else: self.conf = config languages = ['en'] if 'email' in self.conf and 'language' in self.conf['email']: tmp = languages tmp.append(self.conf['email']['language']) languages = tmp if "email" not in self.conf or "url_locales" not in self.conf["email"] : dir_path = os.path.dirname(os.path.realpath(__file__)) url_locales = os.path.join(dir_path, '../locales') else: url_locales = self.conf["email"]["url_locales"] lang = gettext.translation( 'messages', localedir=url_locales, languages=languages) lang.install() translations = gettext.translation( 'messages', localedir=url_locales, languages=languages) self.jinja_env.install_gettext_translations(translations) self.handler.set_bbox(*self.conf["area"]["bbox"]) for name in self.conf["tags"]: key, value = self.conf["tags"][name]["tags"].split("=") types = self.conf["tags"][name]["tags"].split(",") self.stats["name"] = 0 self.handler.set_tags(name, key, value, types)
def __init__(self, **kwargs): """Creates a new OpenERP service. :param \**kwargs: keyword arguments passed to the config """ config = config_from_environment('OPENERP', [], **kwargs) import netsvc import tools update_config(tools.config, **config) if hasattr(tools.config, 'parse'): tools.config.parse() from tools import config as default_config self.config = update_config(default_config, **config) import pooler import workflow self.pooler = pooler self.db = None self.pool = None if 'db_name' in config: self.db_name = config['db_name'] # Stop the cron netsvc.Agent.quit()
def setUpClass(cls): """Set up the test * Sets the config using environment variables prefixed with `DESTRAL_`. * Creates a new OpenERP service. * Installs the module to test if a database is not defined. """ cls.config = config_from_environment( 'DESTRAL', ['module'], use_template=True ) ooconfig = {} if cls.require_demo_data: cls.config['use_template'] = False ooconfig['demo'] = {'all': 1} cls.openerp = OpenERPService(**ooconfig) cls.drop_database = False if not cls.openerp.db_name: cls.openerp.db_name = cls.openerp.create_database( cls.config['use_template'] ) cls.drop_database = True cls.install_module()
def __init__(self, **kwargs): """Creates a new OpenERP service. :param \**kwargs: keyword arguments passed to the config """ patch_root_logger() config = config_from_environment('OPENERP', [], **kwargs) import netsvc import tools update_config(tools.config, **config) if hasattr(tools.config, 'parse'): tools.config.parse() from tools import config as default_config self.config = update_config(default_config, **config) import pooler import workflow self.pooler = pooler self.db = None self.pool = None if 'db_name' in config: self.db_name = config['db_name'] # Stop the cron netsvc.Agent.quit()
def github_config(**config): return config_from_environment('GITHUB', ['token'], **config)
def transexport(modules=[], verbose=False, debug=False): verbosity = logging.DEBUG if debug else ( logging.INFO if verbose else logging.WARNING) initialize_logger(verbosity) log_info('Running with verbosity: {}'.format('DEBUG' if debug else 'INFO')) if modules: log_debug('Modules: {}'.format(modules)) else: log_error('No Modules to export!') exit(-1) log_info('Starting OpenERP Service') log_debug('Checking for OpenERP env vars') dbname = 'translate_{}'.format(str(int(time.time()))) try: confs = osconf.config_from_environment( 'OPENERP', ['addons_path', 'root_path', 'db_user', 'db_password', 'db_name'], db_name=dbname) except: log_error( 'Please, make sure you provide the following environment vars:' '\n\tOPENERP_ADDONS_PATH' '\n\tOPENERP_ROOT_PATH' '\n\tOPENERP_DB_USER' '\n\tOPENERP_DB_PASSWORD') exit(-1) dbname = confs['db_name'] environ['OPENERP_DB_NAME'] = dbname log_debug('DB_NAME: {}'.format(dbname)) addons_path = confs['addons_path'] log_debug('ADDONS_PATH: {}'.format(addons_path)) root_path = confs['root_path'] log_debug('ROOT_PATH: {}'.format(root_path)) try: oerp_service = OpenERPService() log_info('Using database: {}'.format(dbname)) except: log_info('Creating database: {}'.format(dbname)) createdb(dbname=dbname) log_debug('Initialize OpenERPService') oerp_service = OpenERPService() for module_name in modules: log_info('Exporting module "{}"'.format(module_name)) if module_name not in listdir(addons_path): log_error( 'Module "{}" not found in addons path!'.format(module_name)) continue try: with Transaction().start(database_name=dbname) as temp: temp.service.install_module(module_name) uid = temp.user pool = temp.pool cursor = temp.cursor module_obj = pool.get('ir.module.module') export_wizard_obj = pool.get('wizard.module.lang.export') module_id = module_obj.search(cursor, uid, [('name', '=', module_name)]) if len(module_id) > 1: print('More than one module found with this name: "{}"!' ''.format(module_name)) module_id = module_id[0] if not len(module_id): log_error('Module "{}" not found with this name'.format( module_name)) continue wizard_id = export_wizard_obj.create( cursor, uid, { 'format': 'po', 'modules': [(6, 0, module_id)] }) wizard = export_wizard_obj.browse(cursor, uid, wizard_id) wizard.act_getfile() if not isdir(join(addons_path, module_name, 'i18n')): makedirs(join(addons_path, module_name, 'i18n')) with open( join(addons_path, module_name, 'i18n', module_name + '.pot'), 'w') as potfile: potfile.write(decodestring(wizard.data)) except Exception as err: log_error( 'Couldn\'t export translations for module "{}": {}'.format( module_name, err)) continue log_info('Removing temp database {}'.format(dbname)) oerp_service.drop_database()
def setup_peek(**peek_config): config = config_from_environment( 'PEEK', ['server', 'user', 'password', 'db'], **peek_config ) logger.debug('Using peek config: %s' % config) return PeekClient(**config)
# Due: https://www.python.org/dev/peps/pep-0476 import ssl try: _create_unverified_https_context = ssl._create_unverified_context except AttributeError: # Legacy Python that doesn't verify HTTPS certificates by default pass else: # Handle target environment that doesn't support HTTPS verification ssl._create_default_https_context = _create_unverified_https_context except ImportError: pass application = Flask(__name__) sentry = Sentry(application) sentry.captureMessage("Modul backend inicat", level=logging.INFO) Backend(application, url_prefix='/') required = [ 'openerp_server', 'openerp_database', ] config = config_from_environment('BACKEND', required, session_cookie_name=None) for k, v in config.items(): k = k.upper() print('CONFIG: {0}: {1}'.format(k, v)) if v is not None: application.config[k] = v if __name__ == "__main__": application.run(host='0.0.0.0', debug=True)
import os from flask import Flask from mandrill_webhooks import MandrillWebhooks from osconf import config_from_environment app = Flask(__name__) for k, v in config_from_environment('MANDRILL_WEBHOOKS').items(): app.config['MANDRILL_WEBHOOKS_%s' % k.upper()] = v mandrill = MandrillWebhooks(app) @mandrill.hook('*') def log_event(payload, event): print "New event: %s received! with payload: %s" % (event, payload) if __name__ == '__main__': app.run(host='0.0.0.0', debug=True, use_reloader=False)
def apply_pr_config(**config): return config_from_environment('APPLY_PR', **config)
from __future__ import absolute_import import os from osconf import config_from_environment try: VERSION = __import__('pkg_resources') \ .get_distribution(__name__).version except Exception, e: VERSION = 'unknown' from cchloader.logging import setup_logging logging_config = config_from_environment('CCHLOADER_LOGGING') logger = setup_logging(**logging_config) _ROOT = os.path.abspath(os.path.dirname(__file__)) def get_data(path): return os.path.join(_ROOT, 'data', path)
def setUp(self): self.config = config_from_environment('DESTRAL', ['module']) self.openerp = OpenERPService() if not self.openerp.db_name: self.openerp.db_name = self.openerp.create_database() self.openerp.install_module(self.config['module'])
from __future__ import absolute_import import os from osconf import config_from_environment try: VERSION = __import__('pkg_resources') \ .get_distribution(__name__).version except Exception, e: VERSION = 'unknown' from sippers.logging import setup_logging logging_config = config_from_environment('SIPPERS_LOGGING') logger = setup_logging(**logging_config) _ROOT = os.path.abspath(os.path.dirname(__file__)) def get_data(path): return os.path.join(_ROOT, 'data', path)