示例#1
0
def main(args):
    """The main entry point of the application

    The script follows a simple workflow in order to parse and persist
    the test run information to a database. It runs the main logic under a
    TestRun/PerfTestRun object designed to encapsulate information for a
    specific test run.

    The parser expects at least two arguments, an xml and a log file, in order
    to parse minimum information regarding the tests that have been run and
    the test environment.
    """
    # Parse arguments and check if they exist
    arg_parser = config.init_arg_parser()
    parsed_arguments = arg_parser.parse_args(args)

    if not config.validate_input(parsed_arguments):
        print('Invalid command line arguments')
        print(arg_parser.parse_args(['-h']))
        sys.exit(0)

    config.setup_logging(
        default_level=int(parsed_arguments.loglevel)
    )

    logger.debug('Parsing env variables')
    env.read_envfile(parsed_arguments.config)

    logger.info('Initializing TestRun object')
    if parsed_arguments.perf:
        test_run = PerfTestRun(parsed_arguments.perf,
                               parsed_arguments.skipkvp)
    else:
        test_run = TestRun(skip_vm_check=parsed_arguments.skipkvp)

    logger.info('Parsing XML file - %s', parsed_arguments.xml_file_path)
    test_run.update_from_xml(parsed_arguments.xml_file_path)

    logger.info('Parsing log file - %s', parsed_arguments.log_file_path)
    test_run.update_from_ica(parsed_arguments.log_file_path)

    if not parsed_arguments.skipkvp:
        logger.info('Getting KVP values from VM')
        test_run.update_from_vm([
            'OSBuildNumber', 'OSName', 'OSMajorVersion'
        ], stop_vm=True)

    # Parse values to be inserted
    logger.info('Parsing test run for database insertion')
    insert_values = test_run.parse_for_db_insertion()
    # Connect to db and insert values in the table
    logger.info('Initializing database connection')
    db_connection, db_cursor = sql_utils.init_connection()

    logger.info('Executing insertion commands')
    for table_line in insert_values:
        sql_utils.insert_values(db_cursor, table_line)

    logger.info('Committing changes to the database')
    db_connection.commit()
示例#2
0
def environ(monkeypatch, request):
    """Setup environment with sample variables."""
    if request.param == 'environ':
        for key, val in env_vars.items():
            monkeypatch.setenv(key, val)
    elif request.param == 'envfile':
        env.read_envfile('tests/envfile')
示例#3
0
def get_connection_string(env_file='config/.env'):
    """Constructs the connection string for the DB with values from env file

    """
    env.read_envfile(env_file)

    connection_string = Template("Driver={$SQLDriver};"
                                 "Server=$server,$port;"
                                 "Database=$db_name;"
                                 "Uid=$db_user;"
                                 "Pwd=$db_password;"
                                 "Encrypt=$encrypt;"
                                 "TrustServerCertificate=$certificate;"
                                 "Connection Timeout=$timeout;")

    return connection_string.substitute(
        SQLDriver=env.str('Driver'),
        server=env.str('Server'),
        port=env.str('Port'),
        db_name=env.str('Database'),
        db_user=env.str('User'),
        db_password=env.str('Password'),
        encrypt=env.str('Encrypt'),
        certificate=env.str('TrustServerCertificate'),
        timeout=env.str('ConnectionTimeout')
    )
示例#4
0
 def __init__(self):
     #self.connection = psycopg2.connect(host='localhost', database='seoscraperdb', user='******')
     env.read_envfile()
     self.connection = psycopg2.connect(host=env.str('PG_HOST'), database=env.str('PG_DATABASE'), user=env.str('PG_USER'))
     self.api_key = env.str('GOOGLE_PAGESPEED_API_KEY')
     delete_table('pagespeed')
     logging.debug('__init__:' + self.PAGESPEED_URL + self.api_key)
示例#5
0
 def __init__(self):
     env.read_envfile()
     self.audience = 'https://www.googleapis.com/oauth2/v4/token'
     self.issued_at = None
     self.expire = None
     self.str_jwt = None
     self.token = None
     self.headers = None
示例#6
0
def main(args):
    """The main entry point of the application

    The script follows a simple workflow in order to parse and persist
    the test run information to a database. It runs the main logic under a
    TestRun/PerfTestRun object designed to encapsulate information for a
    specific test run.

    The parser expects at least two arguments, an xml and a log file, in order
    to parse minimum information regarding the tests that have been run and
    the test environment.
    """
    # Parse arguments and check if they exist
    arg_parser = config.init_arg_parser()
    parsed_arguments = arg_parser.parse_args(args)
    config.setup_logging(default_level=int(parsed_arguments.loglevel))

    print(parsed_arguments)
    path_validation = config.validate_input(parsed_arguments)
    if isinstance(path_validation, list):
        print("\n%s \n" % path_validation[1])
        print(arg_parser.parse_args(['-h']))
        sys.exit(0)

    # Connect to db
    env.read_envfile(parsed_arguments.config)
    logger.info('Initializing database connection')
    db_connection, db_cursor = sql_utils.init_connection()
    # Parse results
    test_run = parse_results(parsed_arguments.xml_file_path,
                             parsed_arguments.log_file_path,
                             parsed_arguments.perf,
                             parsed_arguments.skipkvp,
                             parsed_arguments.snapshot,
                             db_cursor)

    insert_list = test_run.parse_for_db_insertion()
    if not parsed_arguments.nodbcommit:
        if test_run:
            commit_results(db_connection, db_cursor, insert_list)
        else:
            logger.warning('Results need to be parsed first.')
    else:
        logger.info('Skipping db insertion.') 

    if parsed_arguments.report:
        MonitorRuns.write_json(parsed_arguments.report, MonitorRuns.get_test_summary(insert_list))
    if parsed_arguments.summary:
        MonitorRuns(parsed_arguments.summary)()
示例#7
0
def commit_results(insert_values, config_file_path):
    env.read_envfile(config_file_path)
    # Connect to db and insert values in the table
    logger.info('Initializing database connection')
    db_connection, db_cursor = sql_utils.init_connection()

    logger.info('Executing insertion commands')
    for table_line in insert_values:
        sql_utils.insert_values(db_cursor, table_line)

    logger.info('Committing changes to the database')
    db_connection.commit()

    logger.info("Checking insert validity")
    sql_utils.check_insert(db_cursor, insert_values)
示例#8
0
文件: parser.py 项目: LIS/lis-test
def main():
    env.read_envfile('db.config')
    logger.debug('Initializing database connection')
    db_connection, db_cursor = init_connection()

    logger.debug('Executing insertion commands')
    data = json.load(open('tests.json'))

    for row in data:
        print row
        insert_values(db_cursor, row)

    logger.debug('Executing insertion commands')
    db_connection.commit()

    print_rows(db_cursor)
示例#9
0
def main(args):
    """The main entry point of the application

    """
    # Parse arguments and check if they exist
    parsed_arguments = config.parse_arguments(args)

    if not config.validate_input(parsed_arguments):
        print('Invalid command line arguments')
        sys.exit(0)

    config.setup_logging(
        default_level=int(parsed_arguments['level'])
    )

    logger.debug('Parsing env variables')
    env.read_envfile(parsed_arguments['env'])

    logger.info('Initializing TestRun object')
    test_run = TestRun()

    logger.info('Parsing XML file - %s', parsed_arguments['xml'])
    test_run.update_from_xml(parsed_arguments['xml'])

    logger.info('Parsing log file - %s', parsed_arguments['log'])
    test_run.update_from_ica(parsed_arguments['log'])

    if parsed_arguments['kvp']:
        logger.info('Getting KVP values from VM')
        test_run.update_from_vm([
            'OSBuildNumber', 'OSName', 'OSMajorVersion'
        ], stop_vm=True)

    # Parse values to be inserted
    logger.info('Parsing test run for database insertion')
    insert_values = test_run.parse_for_db_insertion()

    # Connect to db and insert values in the table
    logger.info('Initializing database connection')
    db_connection, db_cursor = sql_utils.init_connection()

    logger.info('Executing insertion commands')
    for table_line in insert_values:
        sql_utils.insert_values(db_cursor, table_line)

    logger.info('Committing changes to the database')
    db_connection.commit()
示例#10
0
    def __init__(self, *args):
        config.setup_logging()
        args = args[0]
        arg_parser = config.LT_arg_parser()
        parsed_arguments = arg_parser.parse_args(args)
        env.read_envfile(parsed_arguments.config)

        self.url = parsed_arguments.build
        self.functions = {}
        self.regexes = {}

        self.content = urlopen(self.url + "consoleText").read()
        self.suite_tests = self.compute_tests(parsed_arguments.tests)
        self.parse_regexes(parsed_arguments.regex)
        self.suite = re.search('(?<=job/)\D+/', self.url).group(0)[:-1]

        for function_name, regex in self.regexes.items():
            function = add_get_function(regex, self.content)
            setattr(self, "get_" + function_name, function)
            self.functions[function_name] = function
def create_settings():
    get_or_create(Setting, app_name='Open Event')

    if current_app.config['DEVELOPMENT']:
        # get the stripe keys from the env file and save it in the settings.
        env.read_envfile()
        stripe_secret_key = env('STRIPE_SECRET_KEY', default=None)
        stripe_publishable_key = env('STRIPE_PUBLISHABLE_KEY', default=None)
        stripe_client_id = env('STRIPE_CLIENT_ID', default=None)
        paypal_sandbox_client = env('PAYPAL_SANDBOX_CLIENT', default=None)
        paypal_sandbox_secret = env('PAYPAL_SANDBOX_SECRET', default=None)
        fb_client_id = env('FACEBOOK_CLIENT_ID', default=None)
        fb_client_secret = env('FACEBOOK_CLIENT_SECRET', default=None)
        google_client_id = env('GOOGLE_CLIENT_ID', default=None)
        google_client_secret = env('GOOGLE_CLIENT_SECRET', default=None)
        tw_consumer_key = env('TWITTER_CONSUMER_KEY', default=None)
        tw_consumer_secret = env('TWITTER_CONSUMER_SECRET', default=None)
        in_client_id = env('INSTAGRAM_CLIENT_ID', default=None)
        in_client_secret = env('INSTAGRAM_CLIENT_SECRET', default=None)

        setting, _ = get_or_create(Setting, app_name='Open Event')
        setting.stripe_client_id = stripe_client_id
        setting.stripe_publishable_key = stripe_publishable_key
        setting.stripe_secret_key = stripe_secret_key
        setting.paypal_sandbox_client = paypal_sandbox_client
        setting.paypal_sandbox_secret = paypal_sandbox_secret
        setting.fb_client_id = fb_client_id
        setting.fb_client_secret = fb_client_secret
        setting.google_client_id = google_client_id
        setting.google_client_secret = google_client_secret
        setting.tw_consumer_key = tw_consumer_key
        setting.tw_consumer_secret = tw_consumer_secret
        setting.in_client_id = in_client_id
        setting.in_client_secret = in_client_secret
        db.session.add(setting)
        db.session.commit()
示例#12
0
 def __init__(self):
     env.read_envfile()
     self._aws_region = env.str("AWS_REGION")
     self._aws_access_key_id = env.str("SSM_AWS_ACCESS_KEY_ID")
     self._aws_secret_access_key = env.str("SSM_AWS_SECRET_ACCESS_KEY")
     self._kms_id = env.str("KMS_ID")
示例#13
0
from os.path import isfile
from envparse import env

if isfile('.env'):
    env.read_envfile('.env')

DEBUG = env.bool('DEBUG', default=False)

TOKEN_SECRET_KEY = env.str('TOKEN_SECRET_KEY')

SITE_HOST = env.str('HOST', default='127.0.0.1')
SITE_PORT = env.int('PORT', default=8701)

DATABASE_URL = env.str('DATABASE_URL', default='mysql://*****:*****@localhost:3306/pinax_mysite')
DATABASE_URL_r = env.str('DATABASE_URL_r', default='mysql://*****:*****@localhost:3306/pinax_mysite')  # 只读库

REDIS_URL = env.str('REDIS_URL', default=False)  # cluster
# REDIS_URL_1 = env.str('REDIS_URL_1', default=False)
# REDIS_URL_2 = env.str('REDIS_URL_2', default=False)
# REDIS_URL_3 = env.str('REDIS_URL_3', default=False)

# REDIS_URL = env.str('REDIS_URL', default=False)  # cluster

VERIFY_SMS_CHANNEL = env.json('VERIFY_SMS_CHANNEL') # help='根据包名确定推送中心的产品id'

STATUS = {
	'OK': 1,
	'ERROR': 2,
	'INFO': 3,
	'UPDATE_USERS': 4
}
示例#14
0
 def __init__(self):
     #self.connection = psycopg2.connect(host='localhost', database='seoscraperdb', user='******')
     env.read_envfile()
     self.connection = psycopg2.connect(host=env.str('PG_HOST'), database=env.str('PG_DATABASE'), user=env.str('PG_USER'))
示例#15
0
import logging
from os.path import isfile

from envparse import env

ENV = env.str('ENV', default='.env')
if isfile(ENV):
    env.read_envfile(ENV)

# Define settings
DB_HOST = env.str('DB_HOST')
DB_PORT = env.int('DB_PORT')
DB_NAME = env.str('DB_NAME')
DB_USER = env.str('DB_USER')
DB_PASSWORD = env.str('DB_PASSWORD')

# logging
LOG_LEVEL = env.str('LOG_LEVEL', default='ERROR')
LOG_HANDLER = logging.StreamHandler()
LOF_FORMATTER = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')

APP_HOST = env.str('APP_HOST', default='127.0.0.1')
APP_PORT = env.str('APP_PORT', default='8000')
API_ITEMS_PER_PAGE = env.int('API_ITEMS_PER_PAGE', default=10)
示例#16
0
"""This is the top-level API of our library"""

from . import auth
from envparse import env
from pathlib import Path

for path in (env("PYDUCK_CONFIG_PATH", ""), "config.env"):
    if Path(path).is_file():
        env.read_envfile(path)


def do_something():
    username = env("PYDUCK_USER", default="")
    password = env("PYDUCK_PASSWORD", default="")
    is_valid = auth.is_user_valid(username, password)
    if not is_valid:
        print("You are NOT authorized to use this library")
        return

    print("Welcome to the library")
示例#17
0
import os

from envparse import env

root_dir = os.path.dirname(os.path.dirname(__file__))
env.read_envfile(os.path.join(root_dir, 'ramsey_server/.env'))


class Settings:
    SITE_HOST = env.str('HOST')
    SITE_PORT = os.environ.get('PORT', env.str('PORT'))
    SECRET_KEY = env.str('SECRET_KEY')

示例#18
0
import os
import logging
from envparse import env

envfile = os.environ.get('APP_SETTINGS', os.path.join(os.getcwd(), '.env'))

if os.path.exists(envfile):
    env.read_envfile(envfile)


class Config:
    DEBUG: bool = env('DEBUG', default=False)
    STRAVA_VERIFY_TOKEN: str = env('STRAVA_VERIFY_TOKEN', default='STRAVA')
    BEANSTALKD_HOST: str = env('BEANSTALKD_HOST', default='127.0.0.1')
    BEANSTALKD_PORT: int = env('BEANSTALKD_PORT', cast=int, default=11300)


config = Config()


def init_logging():
    logging.basicConfig(level=logging.DEBUG if config.DEBUG else logging.INFO)
示例#19
0
from envparse import env

env.read_envfile()

SERVICE_TOKEN = env.str('SERVICE_TOKEN')
API_VERSION = env.float('API_VERSION', default=5.103)

BIT_TOKEN = env.str('BIT_TOKEN')

BOT_TOKEN = env.str('BOT_TOKEN')

REDIS_HOST = env.str('REDIS_HOST', default='localhost')
REDIS_PORT = env.int('REDIS_PORT', default=6379)
REDIS_PASS = env.str('REDIS_PASS', default=None)
示例#20
0
文件: settings.py 项目: sloria/sir
from envparse import env

env.read_envfile()  # Read .env

ENV = env.str('NODE_ENV', default='production')
DEBUG = ENV != 'production'

CACHE = {
    'STRATEGY': 'redis',
    'PARAMS': {
        'host': env('REDIS_HOST', default='localhost'),
        'port': env.int('REDIS_PORT', default=6379),
    }
}

ROUTES = {
    'URL_PREFIX': '/v1/'
}

GITHUB = {
    'CLIENT_ID': env('SIR_GITHUB_CLIENT_ID'),
    'CLIENT_SECRET': env('SIR_GITHUB_CLIENT_SECRET'),
}
def parse():
    env.read_envfile("./config/server.config")
示例#22
0
"""
Django settings for datingbot project.

Generated by 'django-admin startproject' using Django 3.0.4.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os
from envparse import env

env.read_envfile('.env')

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['SECRET_KEY']


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(int(os.environ['DEBUG']))
示例#23
0
# -*- coding: utf-8 -*-
import os

from envparse import env

env.read_envfile()

basedir = os.path.abspath(os.path.dirname(__file__))

VERSION_NAME = '2.1.0-alpha.0'

LANGUAGES = {
    'en': 'English',
    'bn': 'Bengali/Bangla',
    'zh_Hans': 'Chinese (Simplified)',
    'zh_Hant': 'Chinese (Traditional)',
    'fr': 'French',
    'de': 'German',
    'id': 'Indonesian',
    'ko': 'Korean',
    'pl': 'Polish',
    'es': 'Spanish',
    'th': 'Thai',
    'vi': 'Vietnamese',
    'hi': 'Hindi',
    'ja': 'Japanese',
    'ru': 'Russian',
}


class Config(object):
示例#24
0
import logging
import os
from typing import List
from datetime import datetime, tzinfo

from colorlog import ColoredFormatter
from envparse import env

import arrow
import pytz


envfile = os.environ.get('APP_SETTINGS', os.path.join(os.getcwd(), '.env'))

if os.path.exists(envfile):
    env.read_envfile(envfile)

_basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))


class Config:

    DEBUG: bool = env('DEBUG', cast=bool, default=False)
    SECRET_KEY = env('SECRET_KEY')

    SQLALCHEMY_URL = env('SQLALCHEMY_URL')
    BEANSTALKD_HOST = env('BEANSTALKD_HOST', default='beanstalkd.container')
    BEANSTALKD_PORT: int = env('BEANSTALKD_PORT', cast=int, default=11300)

    STRAVA_CLIENT_ID = env('STRAVA_CLIENT_ID')
    STRAVA_CLIENT_SECRET = env('STRAVA_CLIENT_SECRET')
示例#25
0
import os
from envparse import env

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
env.read_envfile(os.path.expanduser('~/Desktop/key.env'))
SECRET_KEY = env.str('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'accounts.apps.AccountsConfig',
    'home',
    'product',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',