示例#1
0
文件: __init__.py 项目: herlo/uptrack
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}
示例#2
0
文件: sync.py 项目: herlo/uptrack
    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()
示例#3
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'))