コード例 #1
0
ファイル: interface.py プロジェクト: tanglu-org/debile
    def create_user(self, name, email, pgp, ssl):
        if NAMESPACE.session.query(Person).filter_by(email=email).first():
            raise ValueError("User already exists.")

        pgp = import_pgp(self.pgp_keyring, pgp)
        ssl = import_ssl(self.ssl_keyring, ssl, name, email)

        p = Person(name=name, email=email, pgp=pgp, ssl=ssl)
        NAMESPACE.session.add(p)

        emit('create', 'user', p.debilize())
        return p.debilize()
コード例 #2
0
ファイル: interface.py プロジェクト: opencollab/debile
    def create_user(self, name, email, pgp, ssl=None, ip=None):
        if NAMESPACE.session.query(Person).filter_by(email=email).first():
            raise ValueError("User already exists.")

        pgp = import_pgp(self.pgp_keyring, pgp)

        if ssl is not None:
            ssl = import_ssl(self.ssl_keyring, ssl, name, email)

        p = Person(name=name, email=email, pgp=pgp, ssl=ssl, ip=ip)
        NAMESPACE.session.add(p)

        emit('create', 'user', p.debilize())
        return p.debilize()
コード例 #3
0
ファイル: dimport.py プロジェクト: opencollab/debile
def dimport(args, s):
    obj = yaml.safe_load(open(args.file, 'r'))

    users = obj.pop("Users", [])
    builders = obj.pop("Builders", [])
    suites = obj.pop("Suites", [])
    components = obj.pop("Components", [])
    arches = obj.pop("Arches", [])
    checks = obj.pop("Checks", [])
    groups = obj.pop("Groups", [])

    Base.metadata.create_all(s.bind)

    for user in users:
        s.add(Person(**user))

    for builder in builders:
        # FIXME: check that builder['maintainer'] exists in the DB/config file
        who = s.query(Person).filter_by(email=builder['maintainer']).one()
        builder['maintainer'] = who
        builder['last_ping'] = datetime.utcnow()
        s.add(Builder(**builder))

    for suite in suites:
        s.add(Suite(**suite))

    for component in components:
        s.add(Component(**component))

    for arch in ["source", "all"]:
        s.add(Arch(name=arch))

    for arch in arches:
        s.add(Arch(name=arch['name']))

    for check in checks:
        s.add(Check(**check))

    for group in groups:
        suites = group.pop('suites')

        # FIXME: check that group['maintainer'] exists in the DB/config file
        who = s.query(Person).filter_by(email=group['maintainer']).one()
        group['maintainer'] = who
        group = Group(**group)
        s.add(group)

        for suite in suites:
            gs = GroupSuite(
                group=group,
                suite=s.query(Suite).filter_by(name=suite['suite']).one())

            for component in suite.pop('components'):
                component = s.query(Component).filter_by(name=component).one()
                gs.components.append(component)

            for arch in ["source", "all"] + suite.pop('arches'):
                arch = s.query(Arch).filter_by(name=arch).one()
                gs.arches.append(arch)

            for check in suite.pop('checks'):
                check = s.query(Check).filter_by(name=check).one()
                gs.checks.append(check)

            s.add(gs)

        sane = True
        for key in obj:
            print "Unknown key '%s' in yaml file '%s'" % (key, args.file)
            sane = False

        if not s.query(exists().where(Person.id == Person.id)).scalar():
            print "No users in yaml file '%s'" % args.file
            sane = False
        elif not s.query(exists().where((
            (Person.ssl != None) & (Person.ssl != DEADBEEF))
                                        | (Person.ip != None))).scalar():
            print(
                "No enabled users in yaml file '%s' (user 'ssl' key missing or dummy 'DEADBEEF' string"
                "and no ip address configured)" % args.file)
            sane = False

        if not s.query(
                exists().where(GroupSuite.id == GroupSuite.id)).scalar():
            print "No group in yaml file '%s'" % args.file
            sane = False

        for group in s.query(Group).filter(~Group.group_suites.any()):
            print "No suites in group '%s' " % group.name
            sane = False

        for gs in s.query(GroupSuite).filter(~GroupSuite.arches.any(
            (Arch.name != 'source') & (Arch.name != 'all'))):
            print "No arches in group '%s' suite '%s'" % (gs.group.name,
                                                          gs.suite.name)
            sane = False

        for gs in s.query(GroupSuite).filter(~GroupSuite.components.any()):
            print "No components in group '%s' suite '%s'" % (gs.group.name,
                                                              gs.suite.name)
            sane = False

        for gs in s.query(GroupSuite).filter(~GroupSuite.checks.any()):
            print "No checks in group '%s' suite '%s'" % (gs.group.name,
                                                          gs.suite.name)
            sane = False

        if not sane and not args.force:
            raise Exception("Sanity checks failed, use --force to override")
コード例 #4
0
def import_dict(obj):
    maintainer = obj.pop("Maintainer", None)
    users = obj.pop("Users", [])
    builders = obj.pop("Builders", [])
    suites = obj.pop("Suites", [])
    groups = obj.pop("Groups", [])
    checks = obj.pop("Checks", [])
    arches = obj.pop("Arches", [])

    if obj != {}:
        for key in obj:
            print "Igorning key %s" % (key)

    with session() as s:
        for user in users:
            existing = None
            try:
                existing = s.query(Person).filter_by(
                    username=user['username']).one()
            except NoResultFound:
                pass

            p = Person(**user)

            if existing:
                p.id = existing.id
                s.merge(p)
            else:
                s.add(p)

        for builder in builders:
            username = builder.pop('maintainer')
            who = s.query(Person).filter_by(username=username).one()
            builder['maintainer'] = who
            builder['last_ping'] = dt.datetime.utcnow()
            s.add(Builder(**builder))

        for suite in suites:
            s.add(Suite(**suite))

        for arch in arches:
            s.add(Arch(name=arch['name']))

        for group in groups:
            arches = group.pop('arches')
            suites = group.pop('suites')

            who = s.query(Person).filter_by(username=group['maintainer']).one()
            group['maintainer'] = who
            group = Group(**group)
            s.add(group)

            for arch in arches:
                arch = s.query(Arch).filter_by(name=arch).one()
                ga = GroupArch(group=group, arch=arch)
                s.add(ga)

            for suite in suites:
                suite = s.query(Suite).filter_by(name=suite).one()
                ga = GroupSuite(group=group, suite=suite)
                s.add(ga)

        for check in checks:
            group = s.query(Group).filter_by(name=check['group']).one()
            check['group'] = group
            s.add(Check(**check))
コード例 #5
0
ファイル: dimport.py プロジェクト: lfaraone/debile
def import_dict(obj):
    maintainer = obj.pop("Maintainer")
    users = obj.pop("Users")
    builders = obj.pop("Builders")
    suites = obj.pop("Suites")
    groups = obj.pop("Groups")
    checks = obj.pop("Checks")
    arches = obj.pop("Arches")

    if obj != {}:
        for key in obj:
            print "Igorning key %s" % (key)

    with session() as s:
        for user in users:
            existing = None
            try:
                existing = s.query(Person).filter_by(
                    username=user['username']
                ).one()
            except NoResultFound:
                pass

            p = Person(**user)

            if existing:
                p.id = existing.id
                s.merge(p)
            else:
                s.add(p)

        for builder in builders:
            username = builder.pop('maintainer')
            who = s.query(Person).filter_by(username=username).one()
            builder['maintainer'] = who
            builder['last_ping'] = dt.datetime.utcnow()
            s.add(Builder(**builder))

        for suite in suites:
            s.add(Suite(**suite))

        for arch in arches:
            s.add(Arch(name=arch['name']))

        for group in groups:
            arches = group.pop('arches')
            suites = group.pop('suites')

            who = s.query(Person).filter_by(username=group['maintainer']).one()
            group['maintainer'] = who
            group = Group(**group)
            s.add(group)

            for arch in arches:
                arch = s.query(Arch).filter_by(name=arch).one()
                ga = GroupArch(group=group, arch=arch)
                s.add(ga)

            for suite in suites:
                suite = s.query(Suite).filter_by(name=suite).one()
                ga = GroupSuite(group=group, suite=suite)
                s.add(ga)

        for check in checks:
            group = s.query(Group).filter_by(name=check['group']).one()
            check['group'] = group
            s.add(Check(**check))
コード例 #6
0
ファイル: dimport.py プロジェクト: tianon/debile
def import_dict(obj):
    users = obj.pop("Users", [])
    builders = obj.pop("Builders", [])
    suites = obj.pop("Suites", [])
    components = obj.pop("Components", [])
    arches = obj.pop("Arches", [])
    checks = obj.pop("Checks", [])
    groups = obj.pop("Groups", [])

    if obj != {}:
        for key in obj:
            print "Igorning key %s" % (key)

    with session() as s:
        for user in users:
            existing = None
            try:
                existing = s.query(Person).filter_by(
                    username=user['username']
                ).one()
            except NoResultFound:
                pass

            p = Person(**user)

            if existing:
                p.id = existing.id
                s.merge(p)
            else:
                s.add(p)

        for builder in builders:
            username = builder.pop('maintainer')
            who = s.query(Person).filter_by(username=username).one()
            builder['maintainer'] = who
            builder['last_ping'] = datetime.utcnow()
            s.add(Builder(**builder))

        for suite in suites:
            s.add(Suite(**suite))

        for component in components:
            s.add(Component(**component))

        for arch in arches:
            s.add(Arch(name=arch['name']))

        for check in checks:
            s.add(Check(**check))

        for group in groups:
            suites = group.pop('suites')

            who = s.query(Person).filter_by(username=group['maintainer']).one()
            group['maintainer'] = who
            group = Group(**group)
            s.add(group)

            for suite in suites:
                gs = GroupSuite(
                    group=group,
                    suite=s.query(Suite).filter_by(name=suite['suite']).one()
                )

                for component in suite.pop('components'):
                    component = s.query(Component).filter_by(name=component).one()
                    gs.components.append(component)
                for arch in suite.pop('arches'):
                    arch = s.query(Arch).filter_by(name=arch).one()
                    gs.arches.append(arch)
                for check in suite.pop('checks'):
                    check = s.query(Check).filter_by(name=check).one()
                    gs.checks.append(check)

                s.add(gs)