create PrintProgress class instead of using IProgress as default one

This commit is contained in:
Romain Bignon 2014-10-08 17:08:56 +02:00
commit a2a9db4f09
2 changed files with 17 additions and 11 deletions

View file

@ -23,7 +23,7 @@ import os
from weboob.core.bcall import BackendsCall from weboob.core.bcall import BackendsCall
from weboob.core.modules import ModulesLoader, RepositoryModulesLoader, ModuleLoadError from weboob.core.modules import ModulesLoader, RepositoryModulesLoader, ModuleLoadError
from weboob.core.backendscfg import BackendsConfig from weboob.core.backendscfg import BackendsConfig
from weboob.core.repositories import Repositories, IProgress from weboob.core.repositories import Repositories, PrintProgress
from weboob.core.scheduler import Scheduler from weboob.core.scheduler import Scheduler
from weboob.tools.backend import Module from weboob.tools.backend import Module
from weboob.tools.config.iconfig import ConfigError from weboob.tools.config.iconfig import ConfigError
@ -362,7 +362,7 @@ class Weboob(WebNip):
elif not os.path.isdir(name): elif not os.path.isdir(name):
self.logger.error(u'"%s" is not a directory', name) self.logger.error(u'"%s" is not a directory', name)
def update(self, progress=IProgress()): def update(self, progress=PrintProgress()):
""" """
Update modules from repositories. Update modules from repositories.
""" """

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright(C) 2010-2012 Romain Bignon, Laurent Bachelier # Copyright(C) 2010-2014 Romain Bignon, Laurent Bachelier
# #
# This file is part of weboob. # This file is part of weboob.
# #
@ -41,10 +41,6 @@ except ImportError:
from configparser import RawConfigParser, DEFAULTSECT from configparser import RawConfigParser, DEFAULTSECT
__all__ = ['IProgress', 'ModuleInstallError', 'ModuleInfo', 'RepositoryUnavailable',
'Repository', 'Versions', 'Repositories', 'InvalidSignature', 'Keyring']
class ModuleInfo(object): class ModuleInfo(object):
""" """
Information about a module available on a repository. Information about a module available on a repository.
@ -375,6 +371,16 @@ class Versions(object):
class IProgress(object): class IProgress(object):
def progress(self, percent, message):
raise NotImplementedError()
def error(self, message):
raise NotImplementedError()
def __repr__(self):
return '<%s>' % self.__class__.__name__
class PrintProgress(IProgress):
def progress(self, percent, message): def progress(self, percent, message):
print('=== [%3.0f%%] %s' % (percent*100, message)) print('=== [%3.0f%%] %s' % (percent*100, message))
@ -546,7 +552,7 @@ class Repositories(object):
l.append(line) l.append(line)
return l return l
def update_repositories(self, progress=IProgress()): def update_repositories(self, progress=PrintProgress()):
self.load_browser() self.load_browser()
""" """
Update list of repositories by downloading them Update list of repositories by downloading them
@ -594,7 +600,7 @@ class Repositories(object):
l.append(repository) l.append(repository)
return True return True
def update(self, progress=IProgress()): def update(self, progress=PrintProgress()):
""" """
Update repositories and install new packages versions. Update repositories and install new packages versions.
@ -608,7 +614,7 @@ class Repositories(object):
if not info.is_local() and info.is_installed(): if not info.is_local() and info.is_installed():
to_update.append(info) to_update.append(info)
class InstallProgress(IProgress): class InstallProgress(PrintProgress):
def __init__(self, n): def __init__(self, n):
self.n = n self.n = n
@ -622,7 +628,7 @@ class Repositories(object):
except ModuleInstallError as e: except ModuleInstallError as e:
inst_progress.progress(1.0, unicode(e)) inst_progress.progress(1.0, unicode(e))
def install(self, module, progress=IProgress()): def install(self, module, progress=PrintProgress()):
""" """
Install a module. Install a module.