Exemple #1
0
    def rename(self, srch, name):
        team = self._query_or_err(srch)
        old_nameid = nameid(team)
        team.name = name

        try:
            self.db.commit()
        except IntegrityError as e:
            # todennäkösesti nimi on jo jollakin toisella joukkueella
            self.db.rollback()
            raise RsxError("Rename failed: %s" % str(e))

        click.echo("%s %s %s" %
                   (old_nameid, click.style("=>", bold=True), nameid(team)))
Exemple #2
0
    def print_scores(self, scores):
        for s in scores:
            if hasattr(s, "decoded_score"):
                score = str(s.decoded_score)
            else:
                score = ""

            if s.has_score:
                data = b64encode(s.data).decode("utf8")
            else:
                data = ""

            yield (styleid(s.event_id), nameid(s.team), nameid(s.judge), score,
                   data)
Exemple #3
0
    def print_teams(self, team_info):
        for team, blocks in team_info:
            bs = ", ".join(
                styleid(b) if isinstance(b, str) else nameid(b)
                for b in blocks)

            yield (styleid(team.id), team.name,
                   "Shadow" if team.is_shadow else "", bs)
Exemple #4
0
 def print_block(self, events):
     for e in events:
         yield (styleid(e.id), localts(e.ts_sched),
                "\n".join(map(nameid, e.teams)), "\n".join(
                    ("%s %s" %
                     (nameid(j.judge),
                      ("%s (%s)" % (click.style("OK", fg="green"),
                                    localts(e.ts_sched, "%d.%m %H:%M"))
                       ) if not j.is_future else "")) for j in e.judgings))
Exemple #5
0
def shadow_command(**kwargs):
    db = kwargs["db"]
    team = query_selectors(db, model.Team, [kwargs["selector"]]).first()

    if team is None:
        raise RsxError("Team not found: %s" % kwargs["selector"])

    old_nameid = nameid(team)

    v = {
        "on": True,
        "off": False,
        "toggle": not team.is_shadow
    }[kwargs["state"]]
    team.is_shadow = v

    click.echo("%s %s %s" %
               (old_nameid, click.style("=>", bold=True), nameid(team)))

    db.commit()
Exemple #6
0
    def del_(self, srch):
        team = self._query_or_err(srch)
        self.db.delete(team)

        try:
            self.db.commit()
        except IntegrityError:
            # jos joukkueella on suorituksia niin ei anna poistaa
            self.db.rollback()
            raise RsxError("Cannot delete team with events")

        click.echo("%s %s" % (del_sym, nameid(team)))
Exemple #7
0
def insert_missing_interactive(db,
                               cls,
                               selectors,
                               creator=None,
                               autoconfirm=None,
                               echo=True):
    ids, names = _split_selectors(selectors)
    have_ids = db.query(cls).filter(cls.id.in_(ids)).all()

    if len(have_ids) < len(ids):
        raise RsxError("Missing ids: %s (from class: %s)" %
                       (set(ids).difference(x.id
                                            for x in have_ids), cls.__name__))

    have_names = db.query(cls).filter(cls.name.in_(names)).all()

    if len(have_names) < len(names):
        missing = set(names).difference(x.name for x in have_names)

        if autoconfirm is False or creator is None:
            raise RsxError("Missing names: %s (from class: %s)" %
                           (missing, cls.__name__))

        if not autoconfirm:
            click.echo("Not in db (%d): %s" %
                       (len(missing), ", ".join(missing)))
            click.confirm("OK to add?", default=True, abort=True)

        add = list(map(creator, missing))

        db.add_all(add)

        # commit että tietokanta antaa niille primary keyt
        db.commit()

        if echo:
            for x in add:
                click.echo("%s %s" % (add_sym, nameid(x)))

        have_names += add

    return have_ids + have_names
Exemple #8
0
 def print_ranking(self, ranking):
     for rank, (team, score) in enumerate_rank(ranking,
                                               key=operator.itemgetter(1)):
         yield ("#%d" % rank, nameid(team), score)