<commit_before>#!/usr/bin/python3
import os
from os.path import join, dirname, realpath
import string
import re
import subprocess

import django
from django.template import Template, loader, Context
from django.conf import settings


myDir = dirname(realpath(__file__))
apiDir = join(myDir, "api_v1")
myParentDir = dirname(myDir)
templatesDir = join(myParentDir, 'templates')


activeEventTypes = (
	"allDayTask",
	"dailyNote",
	"largeScale",
	"lifeTime",
	"monthly",
	"task",
	"universityClass",
	"universityExam",
	"weekly",
	"yearly",
	"custom",
)


def djangoInit():
	settings.configure(
		TEMPLATES = [
			{
				'BACKEND': 'django.template.backends.django.DjangoTemplates',
				'DIRS': [templatesDir],
				'APP_DIRS': False,
			}
		]
	)
	django.setup()


def genEventTypeHandlers():
	djangoInit()
	tpl = loader.get_template('event_handlers.got')
	basePatchParams = extractEventBasePatchParams()
	for eventType in activeEventTypes:
		eventTypeCap = eventType[0].upper() + eventType[1:]
		typeParams = extractEventTypeParams(eventType)
		goText = tpl.render(Context(dict(
			EVENT_TYPE=eventType,
			EVENT_TYPE_CAP=eventTypeCap, # instead of {{EVENT_TYPE|capfirst}}
			EVENT_PATCH_PARAMS=basePatchParams + typeParams,
		)))
		goText = re.sub(r'^\s+\n', '', goText, flags=re.M)
		goText = goText.replace("\t  ", "\t")
		# use 2 spaces for template block indentation
		# and tab for Golang block indentation (as expected by `go fmt`)<commit_msg>src/scal/rest_server/gen.py: remove template indents 5 times<commit_after>#!/usr/bin/python3
import os
from os.path import join, dirname, realpath
import string
import re
import subprocess

import django
from django.template import Template, loader, Context
from django.conf import settings


myDir = dirname(realpath(__file__))
apiDir = join(myDir, "api_v1")
myParentDir = dirname(myDir)
templatesDir = join(myParentDir, 'templates')


activeEventTypes = (
	"allDayTask",
	"dailyNote",
	"largeScale",
	"lifeTime",
	"monthly",
	"task",
	"universityClass",
	"universityExam",
	"weekly",
	"yearly",
	"custom",
)


def djangoInit():
	settings.configure(
		TEMPLATES = [
			{
				'BACKEND': 'django.template.backends.django.DjangoTemplates',
				'DIRS': [templatesDir],
				'APP_DIRS': False,
			}
		]
	)
	django.setup()


def genEventTypeHandlers():
	djangoInit()
	tpl = loader.get_template('event_handlers.got')
	basePatchParams = extractEventBasePatchParams()
	for eventType in activeEventTypes:
		eventTypeCap = eventType[0].upper() + eventType[1:]
		typeParams = extractEventTypeParams(eventType)
		goText = tpl.render(Context(dict(
			EVENT_TYPE=eventType,
			EVENT_TYPE_CAP=eventTypeCap, # instead of {{EVENT_TYPE|capfirst}}
			EVENT_PATCH_PARAMS=basePatchParams + typeParams,
		)))
		goText = re.sub(r'^\s+\n', '', goText, flags=re.M)
		for _ in range(5):
			goText = goText.replace("\t  ", "\t")
		# use 2 spaces for template block indentation
		# and tab for Golang block indentation (as expected by `go fmt`)
{'fraction_non_alphanumeric': 0.1303613644039176, 'fraction_numerical': 0.004052684903748734, 'mean_word_length': 5.082135523613963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3487917', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1018, 'n_words': 227}