def initialize_triple_store(connect_string): """ Does the Actual Initializations. Configures SQLAlchemy engine and creates triple store if it does not exist connect_string - SQLAlchemy engine configuration string """ engine = create_engine(connect_string, echo=True) metadata = MetaData() # create tables for triple store triples_table = Table('triples', metadata, # explicit sequence directive for oracle db Column('id', Integer, Sequence('triple_id_seq'), primary_key=True), # columns for URIs Column('subject_uri', String(255)), Column('predicate_uri', String(255)), Column('object_uri', String(255)), sqlite_autoincrement = True ) triples_with_datatype_table = Table('triples_with_datatype', metadata, Column('id', Integer, Sequence('triple_object_id_seq'), primary_key=True), # columns for URIs Column('subject_uri', String(255)), Column('predicate_uri', String(255)), # polymorphic value column Column('object_type', String(255)), Column('object_value', String(255)), sqlite_autoincrement = True ) # create the tables(if they dont already exist) metadata.create_all(engine) # bind model classes to tables mapper(models.Triple, triples_table) mapper(models.TripleWithDatatype,triples_with_datatype_table) session = create_session(engine) return session
from functools import wraps from flask.ext.fas_openid import FAS import lib as pkgdblib __version__ = '0.1.0' APP = flask.Flask(__name__) APP.config.from_object('pkgdb.default_config') if 'PKGDB_CONFIG' in os.environ: # pragma: no cover APP.config.from_envvar('PKGDB_CONFIG') # Set up FAS extension FAS = FAS(APP) SESSION = pkgdblib.create_session(APP.config['DB_URL']) class FakeFasUser(object): """ Fake FAS user used for the tests. """ id = 100 username = '******' groups = ['packager', 'cla_done'] def is_pkgdb_admin(user): """ Is the user a pkgdb admin. """ if not user: return False if not user.cla_done or len(user.groups) < 1:
def ask_user(message, options): user_input = '' while user_input not in options: user_input = input('message: %s' % options).rstrip() return user_input def create_github_session(): s = requests.Session() s.headers.update( {'Authorization': 'token %s' % os.environ['GITHUB_TOKEN']}) return s shippable_session = lib.create_session() github_session = lib.create_session() r = github_session.get( 'https://api.github.com/search/issues?q=repo:ansible/ansible is:pr is:open -label:needs_rebase -label:ci_verified -label:wip -label:needs_ci_update+status:failure' ) failed_prs = r.json()['items'] for pr in failed_prs: pr = github_session.get(pr['pull_request']['url']).json() statuses_url = pr['statuses_url'] statuses = github_session.get(statuses_url).json() shippable_statuses = [s for s in statuses if s['context'] == 'Shippable'] current_shippable_status = shippable_statuses[0] if current_shippable_status['state'] != 'failure': continue
import requests import os import lib import functools import datetime def get_last_runs(s, project_id, branch): created_after = (datetime.datetime.now() - datetime.timedelta(hours=24)).isoformat() response = s.get('https://api.shippable.com/runs?createdAfter={created_after}&projectIds={project_id}&branch={branch}&isPullRequest=false'.format(created_after=created_after, project_id=project_id, branch=branch)) return response.json() s = lib.create_session() project_id = lib.get_project_by_name(s, 'ansible/ansible')['id'] def get_success_rates(branch): results = {} for run in get_last_runs(s, project_id, branch): for job in s.get('https://api.shippable.com/jobs?runIds={id}'.format(**run)).json(): if job['testsPassed'] == 0: continue env = job['env'][0] if env not in results: results[env] = [] results[env].append(job['statusCode']) success_rates = {} for env in results: r = results[env] success_rates[env] = int(len([i for i in r if i == 30]) / len(r) * 100) return success_rates
import notifications from utils import ReverseProxied __version__ = '0.1.0' APP = flask.Flask(__name__) APP.config.from_object('nuancier.default_config') if 'NUANCIER_CONFIG' in os.environ: # pragma: no cover APP.config.from_envvar('NUANCIER_CONFIG') APP.wsgi_app = ReverseProxied(APP.wsgi_app) # Set up FAS extension FAS = FAS(APP) SESSION = nuancierlib.create_session(APP.config['DB_URL']) def is_nuancier_admin(): """ Is the user a nuancier admin. """ if not hasattr(flask.g, 'fas_user') or not flask.g.fas_user: return False if not flask.g.fas_user.cla_done or \ len(flask.g.fas_user.groups) < 1: return False admins = APP.config['ADMIN_GROUP'] if isinstance(admins, basestring): admins = set([admins]) else:
from flask.ext.fas_openid import FAS import lib as pkgdblib __version__ = '0.1.0' APP = flask.Flask(__name__) APP.config.from_object('pkgdb.default_config') if 'PKGDB_CONFIG' in os.environ: # pragma: no cover APP.config.from_envvar('PKGDB_CONFIG') # Set up FAS extension FAS = FAS(APP) SESSION = pkgdblib.create_session(APP.config['DB_URL']) class FakeFasUser(object): """ Fake FAS user used for the tests. """ id = 100 username = '******' groups = ['packager', 'cla_done'] def is_pkgdb_admin(user): """ Is the user a pkgdb admin. """ if not user: return False if not user.cla_done or len(user.groups) < 1: