<commit_before>#!/usr/bin/python2.4
import telepathy.errors
import inspect 
import gengobject

out = open("telepathy-errors.h", 'w')

gengobject.print_license(out, "telepathy-errors.h", "Header for Telepathy error types")

gengobject.print_header_begin(out, "telepathy_errors")
out.write("typedef enum\n{\n")

errors = [];
max_name_length = 0
for (cname,val) in telepathy.errors.__dict__.items():
    if inspect.isclass(val):
        if '_dbus_error_name' in val.__dict__:
            errors.append(val)
            if len(val.__name__) > max_name_length:
                max_name_length = len(val.__name__)


for val in errors:
    line = "  "+val.__name__ + ","
    line = line.ljust(max_name_length + 4)
    line += "/** "+val.__doc__.strip()
    while len (line) > 79:
        cut = line[:80]
        cutidx = cut.rfind(' ')
        if cutidx == 80:
            out.write(cut[:79])
        else:
            out.write(cut[:cutidx]) 
        out.write('\n')
        line = ' ' * (max_name_length +4) + ' * ' + line[cutidx:]
    out.write(line + '\n')
    out.write(' ' * (max_name_length + 4) + ' */\n')

out.write("} TelepathyErrors; \n\n")

gengobject.print_header_end(out, "telepathy_errors");<commit_msg>added to generrors.py to generate the error quark needed to register the errors with dbus<commit_after>#!/usr/bin/python2.4
import telepathy.errors
import inspect 
import gengobject

out = open("telepathy-errors.h", 'w')

gengobject.print_license(out, "telepathy-errors.h", "Header for Telepathy error types")

gengobject.print_header_begin(out, "telepathy_errors")
out.write("typedef enum\n{\n")

errors = [];
max_name_length = 0
for (cname,val) in telepathy.errors.__dict__.items():
    if inspect.isclass(val):
        if '_dbus_error_name' in val.__dict__:
            errors.append(val)
            if len(val.__name__) > max_name_length:
                max_name_length = len(val.__name__)


for val in errors:
    line = "  "+val.__name__ + ","
    line = line.ljust(max_name_length + 4)
    line += "/** "+val.__doc__.strip()
    while len (line) > 79:
        cut = line[:80]
        cutidx = cut.rfind(' ')
        if cutidx == 80:
            out.write(cut[:79])
        else:
            out.write(cut[:cutidx]) 
        out.write('\n')
        line = ' ' * (max_name_length +4) + ' * ' + line[cutidx:]
    out.write(line + '\n')
    out.write(' ' * (max_name_length + 4) + ' */\n')

out.write("} TelepathyErrors; \n\n")

out.write(
"""
  GQuark telepathy_errors_quark (void);
  #define TELEPATHY_ERRORS telepathy_errors_quark ()
""")


gengobject.print_header_end(out, "telepathy_errors");

out = open("telepathy-errors.c", 'w')

out.write(
"""
#include <glib.h>
#include "telepathy-errors.h"

GQuark
telepathy_errors_quark (void)
{
  static GQuark quark = 0;
  if (!quark)
    quark = g_quark_from_static_string ("telepathy_errors");
  return quark;
}
""")
{'fraction_non_alphanumeric': 0.15619576535925025, 'fraction_numerical': 0.010065949323151684, 'mean_word_length': 3.0648801128349787, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '1831252', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1011, 'n_words': 204}