Beispiel #1
0
def uptodate(request):
    distro = request.context

    upstream_id = int(request.GET["upstream"])
    upstream = DBSession.query(Upstream).filter(Upstream.id == upstream_id).first()

    packages = DBSession.query(Package)
    packages = packages.filter(and_(Package.distro == distro, Package.upstream == upstream))
    packages = packages.order_by(Package.name)

    def filter_uptodate(pkgs):
        for pkg in pkgs:
            try:
                if pkg.uptodate:
                    yield pkg

            except:
                continue

    packages = list(filter_uptodate(packages))

    return {
        "page": "uptodate",
        "status": "Up to date",
        "distro": distro.name,
        "upstream": upstream.name,
        "packages": packages,
    }
Beispiel #2
0
def save(request):

    schema = request.context.__schema__().bind()
    form = deform.Form(schema)

    controls = request.POST.items()

    try:
        postvars = form.validate(controls)

    except deform.ValidationFailure as e:
        # TODO: pass back validation errors to the user
        return {}

    if postvars["id"]:
        # We were editing an existing instance
        o = DBSession.query(request.context.__model__).get(request.POST["id"])

    else:
        # This is a new instance
        o = request.context.__model__()

    for attr, value in postvars.items():
        if attr == "id":
            continue

        if value == colander.null:
            value = None

        setattr(o, attr, value)

    DBSession.add(o)
    DBSession.flush()

    return {'item': o}
Beispiel #3
0
def overview(request):
    pkgquery = DBSession.query(Package)

    distros = []

    for distro in DBSession.query(Distro):
        downstream = 0
        problems = 0
        renamed = 0

        pkgs = pkgquery.filter(Package.distro==distro)
        total = pkgs.count()
        bases = {}

        for pkg in pkgs:
            if pkg.downstream:
                downstream += 1
                continue

            if pkg.upstream_pkgname is not None:
                renamed += 1

            if not pkg.upstream:
                problems += 1
                continue

            upstream = pkg.upstream.name

            if not upstream in bases:
                bases[upstream] = {"name": upstream, "id": pkg.upstream.id,
                                   "uptodate": 0, "outofdate": 0}

            try:
                if pkg.uptodate:
                    bases[upstream]["uptodate"] += 1

                else:
                    bases[upstream]["outofdate"] += 1

            except:
                problems += 1

        def display_filter(base):
            return (base["uptodate"] + base["outofdate"]) > 0

        bases = filter(display_filter, bases.values())

        def display_orderer(base):
            return base["uptodate"] + base["outofdate"]

        bases = sorted(bases, key=display_orderer, reverse=True)

        d = distro.__json__()
        d.update({"downstream": downstream, "problems": problems,
                  "renamed": renamed, "total": total, "bases": bases})
        distros.append(d)

    return {'page': 'overview', "distros": distros}
Beispiel #4
0
def main():
    args = get_args()
    config_uri = args.config

    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    sync = Sync(settings)
    sync.run(distro_name=args.distro)
Beispiel #5
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    sync = Sync(settings)
    sync.run()
Beispiel #6
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)

    # Create the default admin user
    with transaction.manager:
        DBSession.add(User(login=u'admin', password='******',
                           name=u'Default Admin'))
Beispiel #7
0
def problems(request):
    distro = request.context

    packages = DBSession.query(Package)
    packages = packages.filter(Package.distro==distro)
    packages = packages.order_by(Package.name)

    def filter_problems(pkgs):
        for pkg in pkgs:
            if pkg.downstream:
                continue

            if not pkg.upstream:
                yield pkg
                continue

            try:
                # We're only interested in the exception case
                pkg.uptodate

            except:
                yield pkg

    packages = list(filter_problems(packages))

    return {"page": "problems", "status": "Problematic",
            "distro": distro.name, "packages": packages}
Beispiel #8
0
def renamed(request):
    distro = request.context

    packages = DBSession.query(Package)
    packages = packages.filter(Package.distro==distro)
    packages = packages.filter(Package.upstream_pkgname!=None)
    packages = list(packages)

    return {"page": "renamed", "status": "Renamed",
            "distro": distro.name, "packages": packages}
Beispiel #9
0
def downstream(request):
    distro = request.context

    packages = DBSession.query(Package)
    packages = packages.filter(Package.distro==distro)
    packages = packages.filter(Package.downstream==True)
    packages = packages.order_by(Package.name)
    packages = list(packages)

    return {"page": "downstream", "status": "Downstream-only",
            "distro": distro.name, "packages": packages}
Beispiel #10
0
def admin(request):
    objects = DBSession.query(request.context.__model__)

    name = request.context.__name__
    schema = request.context.__schema__().bind()
    form = deform.Form(schema,
                       # Passing title= sets the legend not only for the form,
                       # but also for all the fields. :-/
                       #title="New %s"%name[:-1],
                       action="/%s/save"%name, buttons=('submit',),
                       autocomplete=False)

    return {'page': name, "items": objects,
            'form': form}
Beispiel #11
0
    def run(self):
        """Run the sync"""
        pkgs = DBSession.query(Package)
        distros = DBSession.query(Distro)

        for distro in distros:
            self.log.info("Synchronizing %s..." % distro.name)
            builds = self.get_latest_builds(distro)

            for build in builds:
                self.log.info("Processing %s..." % build.name)
                pkg = pkgs.filter(and_(Package.name==build.name,
                                       Package.distro==distro)).first()

                if not pkg and build.blocked:
                    self.log.debug("Ignoring %s: it was never sync-ed and is "
                                   "now blocked" % build.name)
                    continue

                elif not pkg and not build.blocked:
                    pkg = Package(name=build.name, distro=distro,
                                  evr=build.evr)
                    DBSession.add(pkg)
                    self.log.debug("%s is a newly sync-ed package" % pkg.name)

                elif pkg and build.blocked:
                    self.log.warning("%s has been blocked, deleting it"
                                     % pkg.name)
                    DBSession.delete(pkg)

                elif pkg and not build.blocked:
                    if pkg.evr != build.evr:
                        self.log.debug("%s was updated to %s" % (pkg, build.evr))
                        pkg.evr = build.evr

                try:
                    pkg.upstream = self.get_upstream(pkg)
                    self.log.debug("Found package upstream: %s"
                                   % pkg.upstream)

                except SyncError as e:
                    self.log.error(e)
                    pkg.upstream = None
                    continue

                try:
                    pkg.upstream_evr = self.get_upstream_evr(pkg)
                    self.log.debug("Found package upstream evr: %s"
                                   % pkg.upstream_evr)

                except YumError as e:
                    self.log.error(e)
                    pkg.upstream_evr = None
                    continue

        transaction.commit()
Beispiel #12
0
    def get_upstream(self, pkg):
        if pkg.distro.upstream:
            # Packages from this distro all come from the same upstream
            return pkg.distro.upstream

        # Otherwise, check in Git
        try:
            branch = self.gitbase.get_upstream_branch(pkg.name,
                                                      pkg.distro.git_branch)

        except GitError as e:
            raise SyncError(e)

        upstreams = DBSession.query(Upstream)
        upstream = upstreams.filter(Upstream.git_branch==branch).first()

        if not upstream:
            raise SyncError("No upstream in DB with branch %s" % branch)

        return upstream
Beispiel #13
0
def login(request):
    login_url = request.route_url("login")
    referrer = request.url
    if referrer == login_url:
        referrer = "/"  # never use the login form itself as came_from
    came_from = request.params.get("came_from", referrer)

    message = login = password = ""

    if "form.submitted" in request.params:
        login = request.params["login"]
        password = request.params["password"]

        user = DBSession.query(User).filter(User.login == login).first()
        if user and user.validate_password(password):
            headers = remember(request, login)

            return HTTPFound(location=came_from, headers=headers)

        message = "Failed login"

    return dict(page="login", message=message, came_from=came_from, login=login, url=request.application_url + "/login")
Beispiel #14
0
def login(request):
    login_url = request.route_url('login')
    referrer = request.url
    if referrer == login_url:
        referrer = '/' # never use the login form itself as came_from
    came_from = request.params.get('came_from', referrer)

    message = login = password = ''

    if 'form.submitted' in request.params:
        login = request.params['login']
        password = request.params['password']

        user = DBSession.query(User).filter(User.login==login).first()
        if user and user.validate_password(password):
            headers = remember(request, login)

            return HTTPFound(location=came_from, headers=headers)

        message = 'Failed login'

    return dict(page='login', message=message, came_from=came_from,
                login=login, url=request.application_url+'/login')
Beispiel #15
0
def get_upstream_options():
    yield ('', '--')
    for upstream in DBSession.query(Upstream):
        yield (upstream.id, upstream.name)
Beispiel #16
0
def remove(request):
    DBSession.delete(request.context)
    return {}
Beispiel #17
0
def get_upstream_options():
    yield ("", "--")
    for upstream in DBSession.query(Upstream):
        yield (upstream.id, upstream.name)