Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/test_enumerator.py
blob: e4af60470fdda0a5ad0c6e68e12b83e452ca357b (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
# coding: UTF8
# Copyright 2009 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 sys
import cairo
import ka_debug
import ka_factory
import ka_random
import ka_extensionpoint
import model_protozoon
import model_constraintpool
import model_layer

class VariantEnumerator(object):

    def explain_permutation(self):
        ka_random.set_flurry(9)
        cpool = model_constraintpool.ConstraintPool.get_pool()
 
        for operator_key in model_layer.Layer.OPERATORS:
            for merger_key in ka_factory.get_factory('merger').keys():
                cpool.clear_all()
                cpool.set('/Protozoon', 'layernumberofconstraint', [4, 4])
                cpool.set('/Protozoon', 'layertypeconstraint',
                                                     ['image', 'markovchain'])
                cpool.set('/Protozoon/ImageLayer', 'operatorconstraint', 
                                                               [operator_key])
                cpool.set('/Protozoon/MarkovChainLayer', 'operatorconstraint', 
                                                               [operator_key])
                cpool.set('/Protozoon', 'mergertypeconstraint', merger_key)
                self._explain_protozon(
                    model_layer.Layer.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('/Protozoon', 'layernumberofconstraint', [3, 3])
                cpool.set('/Protozoon', 'layertypeconstraint', layer_key)
                cpool.set('/Protozoon', 'mergertypeconstraint', merger_key)
                cpool.set('/Protozoon/ImageLayer', 'operatorconstraint', 
                                                         [cairo.OPERATOR_OVER])
                cpool.set('/Protozoon/MarkovChainLayer', 'operatorconstraint', 
                                                         [cairo.OPERATOR_OVER])
                cpool.set('/Protozoon/ReferencePattern', 'operatorconstraint', 
                                                         [cairo.OPERATOR_OVER])
                cpool.set('/Protozoon/LetterPress', 'operatorconstraint', 
                                                         [cairo.OPERATOR_OVER])
                self._explain_protozon(layer_key, merger_key)

    def _explain_protozon(self, key1, key2):
        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)
        a_protozoon.explain(formater)
        file_path = formater.get_pathname('html')
        formater.write_html_file(file_path)

    def _write_file(self, file_path, page):
        out_file = None
        try:
            out_file = open(file_path, 'w')
            out_file.write(page)
        except:
            print 'failed writing [%s] [%s] [%s]' % \
                       (out_file.name, sys.exc_info()[0], sys.exc_info()[1])
        finally:
            if out_file:
                out_file.close()

def explain():
    ve = VariantEnumerator()
    ve.explain_permutation()

if __name__ == '__main__':
    explain()