1
# Miro - an RSS based video player application
2
# Copyright (C) 2005-2010 Participatory Culture Foundation
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# In addition, as a special exception, the copyright holders give
19
# permission to link the code of portions of this program with the OpenSSL
22
# You must obey the GNU General Public License in all respects for all of
23
# the code used other than OpenSSL. If you modify file(s) with this
24
# exception, you may extend this exception to your version of the file(s),
25
# but you are not obligated to do so. If you do not wish to do so, delete
26
# this exception statement from your version. If you delete this exception
27
# statement from all source files in the program, then also delete it here.
29
"""dbupgradeprogress.py -- Send updates about progress upgrading the
33
from miro.gtcache import gettext as _
34
from miro import messages
36
_doing_20_upgrade = False
38
def doing_20_upgrade():
39
"""Call this if we are upgrading from a 2.0-style database.
41
This will calibrate the progress bar to take into account the fact
42
that we are running old-style upgrades and running the code in
45
global _doing_20_upgrade
46
_doing_20_upgrade = True
49
"""Call at the begining of the database upgrades."""
50
messages.DatabaseUpgradeStart().send_to_frontend()
53
"""Call at the end of the database upgrades."""
54
messages.DatabaseUpgradeEnd().send_to_frontend()
56
def old_style_progress(start_version, current_version, end_version):
57
"""Call while stepping through old-style upgrades"""
58
progress = _calc_progress(start_version, current_version, end_version)
59
total = 0.05 * progress # old style upgrades take us from 0% -> 5%
60
_send_message(_('Upgrading Old Database'), progress, total)
62
def convert20_progress(current_step, total_step):
63
"""Call while stepping through 2.0 DB conversion code."""
64
progress = _calc_progress(0, current_step, total_step)
65
total = 0.05 + 0.80 * progress # conversion take us from 5% -> 85%
66
_send_message(_('Converting Old Database'), progress, total)
68
def new_style_progress(start_version, current_version, end_version):
69
"""Call while stepping through new-style upgrades"""
70
progress = _calc_progress(start_version, current_version, end_version)
72
total = 0.85 + 0.15 * progress
73
# new style upgrades take us from 85% -> 100%
76
# We didn't do 2.0 conversion. New style upgrades take us
78
_send_message(_('Upgrading Database'), progress, total)
80
def _send_message(stage, stage_progress, total_progress):
81
messages.DatabaseUpgradeProgress(stage, stage_progress,
82
total_progress).send_to_frontend()
84
def _calc_progress(start, current, end):
86
# if total is 0.0 or less, then we return 0.0 to avoid the
87
# ZeroDivisionError. this happens in unit testing.
90
return float(current - start) / (end - start)