Force updating modules after upgrade

fixes #1066

Also, some small PEP8 fixes.
This commit is contained in:
Laurent Bachelier 2013-03-09 15:02:48 +01:00
commit 5b12a3c17e

View file

@ -41,9 +41,10 @@ from weboob.tools.browser import StandardBrowser, BrowserUnavailable
from ConfigParser import RawConfigParser, DEFAULTSECT from ConfigParser import RawConfigParser, DEFAULTSECT
__all__ = ['IProgress', 'ModuleInstallError', 'ModuleInfo', 'RepositoryUnavailable', \ __all__ = ['IProgress', 'ModuleInstallError', 'ModuleInfo', 'RepositoryUnavailable',
'Repository', 'Versions', 'Repositories', 'InvalidSignature', 'Keyring'] 'Repository', 'Versions', 'Repositories', 'InvalidSignature', 'Keyring']
class WeboobBrowser(StandardBrowser): class WeboobBrowser(StandardBrowser):
""" """
Browser with a specific useragent. Browser with a specific useragent.
@ -53,6 +54,7 @@ class WeboobBrowser(StandardBrowser):
def set_version(klass, version): def set_version(klass, version):
klass.USER_AGENT = 'weboob/%s' % version klass.USER_AGENT = 'weboob/%s' % version
class ModuleInfo(object): class ModuleInfo(object):
""" """
Information about a module available on a repository. Information about a module available on a repository.
@ -108,11 +110,13 @@ class ModuleInfo(object):
('urls', self.urls), ('urls', self.urls),
) )
class RepositoryUnavailable(Exception): class RepositoryUnavailable(Exception):
""" """
Repository in not available. Repository in not available.
""" """
class Repository(object): class Repository(object):
""" """
Represents a repository. Represents a repository.
@ -149,7 +153,7 @@ class Repository(object):
""" """
Get a local path of a file:// URL. Get a local path of a file:// URL.
""" """
assert self.local == True assert self.local is True
if self.url.startswith('file://'): if self.url.startswith('file://'):
return self.url[len('file://'):] return self.url[len('file://'):]
@ -348,6 +352,7 @@ class Repository(object):
with open(filename, 'wb') as f: with open(filename, 'wb') as f:
config.write(f) config.write(f)
class Versions(object): class Versions(object):
VERSIONS_LIST = 'versions.list' VERSIONS_LIST = 'versions.list'
@ -380,6 +385,7 @@ class Versions(object):
with open(os.path.join(self.path, self.VERSIONS_LIST), 'wb') as fp: with open(os.path.join(self.path, self.VERSIONS_LIST), 'wb') as fp:
config.write(fp) config.write(fp)
class IProgress(object): class IProgress(object):
def progress(self, percent, message): def progress(self, percent, message):
print '=== [%3.0f%%] %s' % (percent*100, message) print '=== [%3.0f%%] %s' % (percent*100, message)
@ -387,9 +393,11 @@ class IProgress(object):
def error(self, message): def error(self, message):
print >>sys.stderr, 'ERROR: %s' % message print >>sys.stderr, 'ERROR: %s' % message
class ModuleInstallError(Exception): class ModuleInstallError(Exception):
pass pass
DEFAULT_SOURCES_LIST = \ DEFAULT_SOURCES_LIST = \
"""# List of Weboob repositories """# List of Weboob repositories
# #
@ -404,6 +412,7 @@ http://updates.weboob.org/%(version)s/main/
#file:///home/rom1/src/weboob/modules/ #file:///home/rom1/src/weboob/modules/
""" """
class Repositories(object): class Repositories(object):
SOURCES_LIST = 'sources.list' SOURCES_LIST = 'sources.list'
MODULES_DIR = 'modules' MODULES_DIR = 'modules'
@ -421,7 +430,7 @@ class Repositories(object):
self.workdir = workdir self.workdir = workdir
self.datadir = datadir self.datadir = datadir
self.sources_list = os.path.join(self.workdir, self.SOURCES_LIST) self.sources_list = os.path.join(self.workdir, self.SOURCES_LIST)
self.modules_dir = os.path.join(self.datadir, self.MODULES_DIR) self.modules_dir = os.path.join(self.datadir, self.MODULES_DIR, self.version)
self.repos_dir = os.path.join(self.datadir, self.REPOS_DIR) self.repos_dir = os.path.join(self.datadir, self.REPOS_DIR)
self.keyrings_dir = os.path.join(self.datadir, self.KEYRINGS_DIR) self.keyrings_dir = os.path.join(self.datadir, self.KEYRINGS_DIR)
self.icons_dir = os.path.join(self.datadir, self.ICONS_DIR) self.icons_dir = os.path.join(self.datadir, self.ICONS_DIR)
@ -521,7 +530,7 @@ class Repositories(object):
try: try:
icon = browser.openurl(icon_url) icon = browser.openurl(icon_url)
except BrowserUnavailable: except BrowserUnavailable:
pass # no icon, no problem pass # no icon, no problem
else: else:
with open(dest_path, 'wb') as fp: with open(dest_path, 'wb') as fp:
fp.write(icon.read()) fp.write(icon.read())