• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / Products.ZCatalog / 3979545908

pending completion
3979545908

push

github

GitHub
Drop support for Python 2.7, 3.5, 3.6. (#143)

817 of 1057 branches covered (77.29%)

Branch coverage included in aggregate %.

49 of 49 new or added lines in 12 files covered. (100.0%)

3144 of 3538 relevant lines covered (88.86%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.15
/src/Products/ZCatalog/ProgressHandler.py
1
##############################################################################
2
#
3
# Copyright (c) 2002 Zope Foundation and Contributors.
4
#
5
# This software is subject to the provisions of the Zope Public License,
6
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
7
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10
# FOR A PARTICULAR PURPOSE.
11
#
12
##############################################################################
13

14

15
import sys
1✔
16
import time
1✔
17
from logging import getLogger
1✔
18

19
import transaction
1✔
20
from DateTime.DateTime import DateTime
1✔
21
from zope.interface import implementer
1✔
22

23
from .interfaces import IProgressHandler
1✔
24

25

26
LOG = getLogger('ProgressHandler')
1✔
27

28

29
@implementer(IProgressHandler)
1✔
30
class StdoutHandler:
1✔
31
    """ A simple progress handler """
32

33
    def __init__(self, steps=100):
1✔
34
        self._steps = steps
1✔
35

36
    def init(self, ident, max, savepoint=True):
1✔
37
        self._ident = ident
1✔
38
        self._max = max
1✔
39
        self.savepoint = savepoint
1✔
40
        self._start = time.time()
1✔
41
        self.fp = sys.stdout
1✔
42
        self.output('Process started (%d objects to go)' % self._max)
1✔
43

44
    def info(self, text):
1✔
45
        self.output(text)
×
46

47
    def finish(self):
1✔
48
        self.output('Process terminated. Duration: %0.2f seconds' %
1✔
49
                    (time.time() - self._start))
50

51
    def report(self, current, *args, **kw):
1✔
52
        if current > 0:
1✔
53
            if current % self._steps == 0:
1!
54
                if self.savepoint:
×
55
                    transaction.savepoint(optimistic=True)
×
56
                seconds_so_far = time.time() - self._start
×
57
                seconds_to_go = (seconds_so_far
×
58
                                 / current
59
                                 * (self._max - current))
60
                end = DateTime(time.time() + seconds_to_go)
×
61
                self.output('%d/%d (%.2f%%) Estimated termination: %s' %
×
62
                            (current, self._max, (100.0 * current / self._max),
63
                             end.strftime('%Y/%m/%d %H:%M:%Sh')))
64

65
    def output(self, text):
1✔
66
        print('{}: {}'.format(self._ident, text), file=self.fp)
×
67

68

69
class ZLogHandler(StdoutHandler):
1✔
70
    """ Use Zope logger"""
71

72
    def output(self, text):
1✔
73
        LOG.info(text)
1✔
74

75

76
class FilelogHandler(StdoutHandler):
1✔
77
    """ Use a custom file for logging """
78

79
    def __init__(self, filename, steps=100):
1✔
80
        StdoutHandler.__init__(self, steps)
×
81
        self.filename = filename
×
82

83
    def output(self, text):
1✔
84
        with open(self.filename, 'a') as fd:
×
85
            fd.write(text + '\n')
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc