Statistics
| Branch: | Tag: | Revision:

root / image_creator / output / composite.py @ b87b7a14

History | View | Annotate | Download (3.3 kB)

1 c3fe132c Nikos Skalkotos
# Copyright 2012 GRNET S.A. All rights reserved.
2 c3fe132c Nikos Skalkotos
#
3 c3fe132c Nikos Skalkotos
# Redistribution and use in source and binary forms, with or
4 c3fe132c Nikos Skalkotos
# without modification, are permitted provided that the following
5 c3fe132c Nikos Skalkotos
# conditions are met:
6 c3fe132c Nikos Skalkotos
#
7 c3fe132c Nikos Skalkotos
#   1. Redistributions of source code must retain the above
8 c3fe132c Nikos Skalkotos
#      copyright notice, this list of conditions and the following
9 c3fe132c Nikos Skalkotos
#      disclaimer.
10 c3fe132c Nikos Skalkotos
#
11 c3fe132c Nikos Skalkotos
#   2. Redistributions in binary form must reproduce the above
12 c3fe132c Nikos Skalkotos
#      copyright notice, this list of conditions and the following
13 c3fe132c Nikos Skalkotos
#      disclaimer in the documentation and/or other materials
14 c3fe132c Nikos Skalkotos
#      provided with the distribution.
15 c3fe132c Nikos Skalkotos
#
16 c3fe132c Nikos Skalkotos
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 c3fe132c Nikos Skalkotos
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 c3fe132c Nikos Skalkotos
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 c3fe132c Nikos Skalkotos
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 c3fe132c Nikos Skalkotos
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 c3fe132c Nikos Skalkotos
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 c3fe132c Nikos Skalkotos
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 c3fe132c Nikos Skalkotos
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 c3fe132c Nikos Skalkotos
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 c3fe132c Nikos Skalkotos
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 c3fe132c Nikos Skalkotos
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 c3fe132c Nikos Skalkotos
# POSSIBILITY OF SUCH DAMAGE.
28 c3fe132c Nikos Skalkotos
#
29 c3fe132c Nikos Skalkotos
# The views and conclusions contained in the software and
30 c3fe132c Nikos Skalkotos
# documentation are those of the authors and should not be
31 c3fe132c Nikos Skalkotos
# interpreted as representing official policies, either expressed
32 c3fe132c Nikos Skalkotos
# or implied, of GRNET S.A.
33 c3fe132c Nikos Skalkotos
34 c3fe132c Nikos Skalkotos
from image_creator.output import Output
35 c3fe132c Nikos Skalkotos
36 c3fe132c Nikos Skalkotos
37 c3fe132c Nikos Skalkotos
class CompositeOutput(Output):
38 c3fe132c Nikos Skalkotos
    """This class can be used to composite different outputs into a single one
39 c3fe132c Nikos Skalkotos

40 c3fe132c Nikos Skalkotos
    You may create an instance of this class and then add other output
41 c3fe132c Nikos Skalkotos
    instances to it. Executing a method on this instance will cause the
42 c3fe132c Nikos Skalkotos
    execution of the same method in each output instance that has been added to
43 c3fe132c Nikos Skalkotos
    this one.
44 c3fe132c Nikos Skalkotos
    """
45 c3fe132c Nikos Skalkotos
46 c3fe132c Nikos Skalkotos
    def __init__(self, outputs=[]):
47 c3fe132c Nikos Skalkotos
        self._outputs = outputs
48 c3fe132c Nikos Skalkotos
49 c3fe132c Nikos Skalkotos
    def add(self, output):
50 c3fe132c Nikos Skalkotos
        self._outputs.append(output)
51 c3fe132c Nikos Skalkotos
52 c3fe132c Nikos Skalkotos
    def remove(self, output):
53 c3fe132c Nikos Skalkotos
        self._outputs.remove(output)
54 c3fe132c Nikos Skalkotos
55 c3fe132c Nikos Skalkotos
    def error(self, msg, new_line=True):
56 c3fe132c Nikos Skalkotos
        for out in self._outputs:
57 c3fe132c Nikos Skalkotos
            out.error(msg, new_line)
58 c3fe132c Nikos Skalkotos
59 c3fe132c Nikos Skalkotos
    def warn(self, msg, new_line=True):
60 c3fe132c Nikos Skalkotos
        for out in self._outputs:
61 c3fe132c Nikos Skalkotos
            out.warn(msg, new_line)
62 c3fe132c Nikos Skalkotos
63 c3fe132c Nikos Skalkotos
    def success(self, msg, new_line=True):
64 c3fe132c Nikos Skalkotos
        for out in self._outputs:
65 c3fe132c Nikos Skalkotos
            out.success(msg, new_line)
66 c3fe132c Nikos Skalkotos
67 c3fe132c Nikos Skalkotos
    def output(self, msg='', new_line=True):
68 c3fe132c Nikos Skalkotos
        for out in self._outputs:
69 c3fe132c Nikos Skalkotos
            out.output(msg, new_line)
70 c3fe132c Nikos Skalkotos
71 c3fe132c Nikos Skalkotos
    def cleanup(self):
72 c3fe132c Nikos Skalkotos
        for out in self._outputs:
73 c3fe132c Nikos Skalkotos
            out.cleanup()
74 c3fe132c Nikos Skalkotos
75 c3fe132c Nikos Skalkotos
    def clear(self):
76 c3fe132c Nikos Skalkotos
        for out in self._outputs:
77 c3fe132c Nikos Skalkotos
            out.clear()
78 c3fe132c Nikos Skalkotos
79 c3fe132c Nikos Skalkotos
    class _Progress(object):
80 c3fe132c Nikos Skalkotos
81 c3fe132c Nikos Skalkotos
        def __init__(self, size, title, bar_type='default'):
82 c3fe132c Nikos Skalkotos
            self._progresses = []
83 c3fe132c Nikos Skalkotos
            for out in self.output._outputs:
84 c3fe132c Nikos Skalkotos
                self._progresses.append(out.Progress(size, title, bar_type))
85 c3fe132c Nikos Skalkotos
86 c3fe132c Nikos Skalkotos
        def goto(self, dest):
87 c3fe132c Nikos Skalkotos
            for progress in self._progresses:
88 c3fe132c Nikos Skalkotos
                progress.goto(dest)
89 c3fe132c Nikos Skalkotos
90 c3fe132c Nikos Skalkotos
        def next(self):
91 c3fe132c Nikos Skalkotos
            for progress in self._progresses:
92 c3fe132c Nikos Skalkotos
                progress.next()
93 c3fe132c Nikos Skalkotos
94 c3fe132c Nikos Skalkotos
        def success(self, result):
95 c3fe132c Nikos Skalkotos
            for progress in self._progresses:
96 c3fe132c Nikos Skalkotos
                progress.success(result)
97 c3fe132c Nikos Skalkotos
98 c3fe132c Nikos Skalkotos
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :