<commit_before>import time
import handlers
import games
import games.settlers.stats
import hlib
import hlib.log
import hlib.error
import hlib.event
import events.game
import tournaments

import hlib.event

import lib.play

# Handlers
from handlers import page, require_write, require_hosts
from hlib.api import api

from hlib.input import validate_by

# pylint: disable-msg=F0401
import hruntime

maint_require_hosts = lambda: hruntime.app.config['hosts']['maint.*']

class Handler(handlers.GenericHandler):
  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @api
  def process_free_deadlines(self):
    canceled = []

    for g in hruntime.dbroot.games.values():
      if not g.is_waiting_begin or g.deadline > hruntime.time:
        continue

      t = (g.id, g.type, hruntime.time - g.deadline)
      g.cancel(reason = events.game.GameCanceled.REASON_EMPTY, user = None)
      canceled.append(t)

    return hlib.api.Reply(200, canceled_games = canceled)

  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @api
  def process_active_deadlines(self):
    canceled = []

    for g in hruntime.dbroot.games.values():
      if not g.is_waiting_turn or g.deadline > hruntime.time:
        continue

      d = [g.id, hruntime.time - g.deadline, [p.user.name for p in g.players.values()], g.forhont_player.user.name]

      g.cancel(reason = events.game.GameCanceled.REASON_ABSENTEE, user = g.forhont_player.user)
      canceled.append(d)

    return hlib.api.Reply(200, canceled_games = canceled)

  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @api
  def process_archive_deadlines(self):
    def __process_list(playable_list, playable_archived_list, event_name, handle_name):
      archived = []

      for p in playable_list.values():
        try:
          if p.archive_deadline >= hruntime.time:
            continue

        except lib.play.CannotBeArchivedError:
          continue

        archived.append(p)

      for p in archived:
        del playable_list[p.id]

        playable_archived_list[p.id] = p

        # pylint: disable-msg=W0142
        hlib.event.trigger(event_name, p, **{handle_name: p})

      return [p.id for p in archived]

    return hlib.api.Reply(200, archived_games = __process_list(hruntime.dbroot.games, hruntime.dbroot.games_archived, 'game.GameArchived', 'game'),
                               archived_tournaments = __process_list(hruntime.dbroot.tournaments, hruntime.dbroot.tournaments_archived, 'tournament.Archived', 'tournament'))

  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @validate_by(schema = games.GenericValidateKind)
  @api
  def refresh_stats_games(self, kind = None):
    gm = games.game_module(kind, submodule = 'stats')
    gm.stats.refresh_stats()

  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @api
  def create_system_games(self):
    def __create_games(count, limit, sleep = 5):
      for _ in range(0, count):
        games.create_system_game('settlers', limit = limit, turn_limit = 604800)
        time.sleep(sleep)
        hruntime.time = None

    cnt = hruntime.app.config['system_games.limit'] - hruntime.dbroot.counters.games_free()
    if cnt > 0:
      __create_games(cnt, 3, sleep = hruntime.app.config['system_games.sleep'])

      # pylint: disable-msg=W0212
      games._game_lists.inval_all('active')

    else:
      cnt = 0

    return hlib.api.Reply(200, created_games = cnt)

  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @api
  def pack_db(self):
    hruntime.db.pack()
<commit_msg>Output the same info for free/running games when dumping in maint handler<commit_after>import time
import handlers
import games
import games.settlers.stats
import hlib
import hlib.log
import hlib.error
import hlib.event
import events.game
import tournaments

import hlib.event

import lib.play

# Handlers
from handlers import page, require_write, require_hosts
from hlib.api import api

from hlib.input import validate_by

# pylint: disable-msg=F0401
import hruntime

maint_require_hosts = lambda: hruntime.app.config['hosts']['maint.*']

class Handler(handlers.GenericHandler):
  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @api
  def process_free_deadlines(self):
    canceled = []

    for g in hruntime.dbroot.games.values():
      if not g.is_waiting_begin or g.deadline > hruntime.time:
        continue

      t = (g.id, g.type, hruntime.time - g.deadline, [p.user.name for p in g.players.values()], g.forhont_player.user.name)
      g.cancel(reason = events.game.GameCanceled.REASON_EMPTY, user = None)
      canceled.append(t)

    return hlib.api.Reply(200, canceled_games = canceled)

  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @api
  def process_active_deadlines(self):
    canceled = []

    for g in hruntime.dbroot.games.values():
      if not g.is_waiting_turn or g.deadline > hruntime.time:
        continue

      t = (g.id, g.type, hruntime.time - g.deadline, [p.user.name for p in g.players.values()], g.forhont_player.user.name)
      #g.cancel(reason = events.game.GameCanceled.REASON_ABSENTEE, user = g.forhont_player.user)
      canceled.append(t)

    return hlib.api.Reply(200, canceled_games = canceled)

  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @api
  def process_archive_deadlines(self):
    def __process_list(playable_list, playable_archived_list, event_name, handle_name):
      archived = []

      for p in playable_list.values():
        try:
          if p.archive_deadline >= hruntime.time:
            continue

        except lib.play.CannotBeArchivedError:
          continue

        archived.append(p)

      for p in archived:
        del playable_list[p.id]

        playable_archived_list[p.id] = p

        # pylint: disable-msg=W0142
        hlib.event.trigger(event_name, p, **{handle_name: p})

      return [p.id for p in archived]

    return hlib.api.Reply(200, archived_games = __process_list(hruntime.dbroot.games, hruntime.dbroot.games_archived, 'game.GameArchived', 'game'),
                               archived_tournaments = __process_list(hruntime.dbroot.tournaments, hruntime.dbroot.tournaments_archived, 'tournament.Archived', 'tournament'))

  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @validate_by(schema = games.GenericValidateKind)
  @api
  def refresh_stats_games(self, kind = None):
    gm = games.game_module(kind, submodule = 'stats')
    gm.stats.refresh_stats()

  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @api
  def create_system_games(self):
    def __create_games(count, limit, sleep = 5):
      for _ in range(0, count):
        games.create_system_game('settlers', limit = limit, turn_limit = 604800)
        time.sleep(sleep)
        hruntime.time = None

    cnt = hruntime.app.config['system_games.limit'] - hruntime.dbroot.counters.games_free()
    if cnt > 0:
      __create_games(cnt, 3, sleep = hruntime.app.config['system_games.sleep'])

      # pylint: disable-msg=W0212
      games._game_lists.inval_all('active')

    else:
      cnt = 0

    return hlib.api.Reply(200, created_games = cnt)

  @require_hosts(get_hosts = maint_require_hosts)
  @require_write
  @api
  def pack_db(self):
    hruntime.db.pack()

{'fraction_non_alphanumeric': 0.10318436517698511, 'fraction_numerical': 0.00956676233429001, 'mean_word_length': 3.4978488014751075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2843788', 'n_tokens_mistral': 2630, 'n_tokens_neox': 2435, 'n_words': 496}