Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/test_enumerator.py
blob: ff1f39e9c7b828c99cfa4f8d55dd9d9a0d131e8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# coding: UTF-8
# Copyright 2009, 2010 Thomas Jourdan
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import traceback
import sys
import cairo
import ka_debug
import ka_factory
import model_random
import ka_extensionpoint
import ep_merger_combine
import model_protozoon
import model_constraintpool

class VariantEnumerator(object):
    
    def __init__(self):
        self.exception_counter = 0

    def explain_permutation(self):
        model_random.set_flurry(9)
        cpool = model_constraintpool.ConstraintPool.get_pool()
 
        for layer_key in ka_factory.get_factory('layer').keys():
            for modifier_key in ka_factory.get_factory('modifier').keys():
                cpool.clear_all()
                cpool.set('*', 'colorconstraint', ['colorconstraint_none', ])
                cpool.set('*', 'layernumberofconstraint', [1, 3])
                cpool.set('*', 'layertypeconstraint',
                                               ['letterpress', 'markovchain'])
                cpool.set('*', 'layertypeconstraint', layer_key)
                cpool.set('*', 'modifiertypeconstraint', modifier_key)
                cpool.set('*', 'operatorconstraint', [cairo.OPERATOR_OVER])
                self._explain_protozon(layer_key, modifier_key)

        for operator_key in ep_merger_combine.CombineMerger.OPERATORS:
            for merger_key in ka_factory.get_factory('merger').keys():
                cpool.clear_all()
                cpool.set('*', 'colorconstraint', ['colorconstraint_none', ])
                cpool.set('*', 'layernumberofconstraint', [3, 3])
                cpool.set('*', 'layertypeconstraint',
                                               ['letterpress', 'markovchain'])
                cpool.set('*', 'operatorconstraint', [operator_key])
                cpool.set('*', 'mergertypeconstraint', merger_key)
                self._explain_protozon(
                    ep_merger_combine.CombineMerger.OPERATOR_NAMES[operator_key], merger_key)

        for layer_key in ka_factory.get_factory('layer').keys():
            for merger_key in ka_factory.get_factory('merger').keys():
                cpool.clear_all()
                cpool.set('*', 'colorconstraint', ['colorconstraint_none', ])
                cpool.set('*', 'layernumberofconstraint', [3, 2])
                cpool.set('*', 'layertypeconstraint', layer_key)
                cpool.set('*', 'mergertypeconstraint', merger_key)
                cpool.set('*', 'operatorconstraint', [cairo.OPERATOR_OVER])
                self._explain_protozon(layer_key, merger_key)

    def _explain_protozon(self, key1, key2):
        try:
            a_protozoon = model_protozoon.Protozoon()
            a_protozoon.randomize()
    
            base_name = 'index'
            base_folder = '/dev/shm/'
            explain_id = '_' + key1 + '_' + key2
            ep_list = ka_extensionpoint.list_extensions('formater')
            formater = ka_extensionpoint.create(ep_list[0],
                                                base_name, 
                                                explain_id,
                                                base_folder)
            class DummyTask:
                def __init__(self):
                    self.quit = False
            a_protozoon.explain(DummyTask(), formater)
            file_path = formater.get_absolutename('html')
            formater.write_html_file(file_path)
        except:
            self.exception_counter += 1
            ka_debug.err('failed rendering [%s] [%s] [%s]' % \
                   (explain_id, sys.exc_info()[0], sys.exc_info()[1]))
            traceback.print_exc(file=sys.__stderr__)

def explain():
    vae = VariantEnumerator()
    vae.explain_permutation()
    return vae.exception_counter

if __name__ == '__main__':
    explain()