move part of update() to update_repositories()
This commit is contained in:
parent
6deaa9ac44
commit
b4154b5843
1 changed files with 50 additions and 14 deletions
|
|
@ -39,12 +39,23 @@ from weboob.tools.misc import to_unicode
|
||||||
from weboob.tools.browser import StandardBrowser, BrowserUnavailable
|
from weboob.tools.browser import StandardBrowser, BrowserUnavailable
|
||||||
from ConfigParser import RawConfigParser, DEFAULTSECT
|
from ConfigParser import RawConfigParser, DEFAULTSECT
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['IProgress', 'ModuleInstallError', 'ModuleInfo', 'RepositoryUnavailable', \
|
||||||
|
'Repository', 'Versions', 'Repositories', 'InvalidSignature', 'Keyring']
|
||||||
|
|
||||||
class WeboobBrowser(StandardBrowser):
|
class WeboobBrowser(StandardBrowser):
|
||||||
|
"""
|
||||||
|
Browser with a specific useragent.
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
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.
|
||||||
|
"""
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
|
@ -97,9 +108,14 @@ class ModuleInfo(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
class RepositoryUnavailable(Exception):
|
class RepositoryUnavailable(Exception):
|
||||||
pass
|
"""
|
||||||
|
Repository in not available.
|
||||||
|
"""
|
||||||
|
|
||||||
class Repository(object):
|
class Repository(object):
|
||||||
|
"""
|
||||||
|
Represents a repository.
|
||||||
|
"""
|
||||||
INDEX = 'modules.list'
|
INDEX = 'modules.list'
|
||||||
KEYDIR = '.keys'
|
KEYDIR = '.keys'
|
||||||
KEYRING = 'trusted.gpg'
|
KEYRING = 'trusted.gpg'
|
||||||
|
|
@ -143,7 +159,8 @@ class Repository(object):
|
||||||
Retrieve the index file of this repository. It can use network
|
Retrieve the index file of this repository. It can use network
|
||||||
if this is a remote repository.
|
if this is a remote repository.
|
||||||
|
|
||||||
@param repo_path [str] path to save the downloaded index file.
|
:param repo_path: path to save the downloaded index file.
|
||||||
|
:type repo_path: str
|
||||||
"""
|
"""
|
||||||
if self.local:
|
if self.local:
|
||||||
# Repository is local, open the file.
|
# Repository is local, open the file.
|
||||||
|
|
@ -205,7 +222,8 @@ class Repository(object):
|
||||||
"""
|
"""
|
||||||
Parse index of a repository
|
Parse index of a repository
|
||||||
|
|
||||||
@param fp [buffer] file descriptor to read
|
:param fp: file descriptor to read
|
||||||
|
:type fp: buffer
|
||||||
"""
|
"""
|
||||||
config = RawConfigParser()
|
config = RawConfigParser()
|
||||||
config.readfp(fp)
|
config.readfp(fp)
|
||||||
|
|
@ -247,8 +265,10 @@ class Repository(object):
|
||||||
"""
|
"""
|
||||||
Rebuild index of modules of repository.
|
Rebuild index of modules of repository.
|
||||||
|
|
||||||
@param path [str] path of the repository
|
:param path: path of the repository
|
||||||
@param filename [str] file to save index
|
:type path: str
|
||||||
|
:param filename: file to save index
|
||||||
|
:type filename: str
|
||||||
"""
|
"""
|
||||||
print 'Rebuild index'
|
print 'Rebuild index'
|
||||||
self.modules.clear()
|
self.modules.clear()
|
||||||
|
|
@ -302,8 +322,10 @@ class Repository(object):
|
||||||
"""
|
"""
|
||||||
Save repository into a file (modules.list for example).
|
Save repository into a file (modules.list for example).
|
||||||
|
|
||||||
@param filename [str] path to file to save repository.
|
:param filename: path to file to save repository.
|
||||||
@param private [bool] if enabled, save URL of repository.
|
:type filename: str
|
||||||
|
:param private: if enabled, save URL of repository.
|
||||||
|
:type private: bool
|
||||||
"""
|
"""
|
||||||
config = RawConfigParser()
|
config = RawConfigParser()
|
||||||
config.set(DEFAULTSECT, 'name', self.name)
|
config.set(DEFAULTSECT, 'name', self.name)
|
||||||
|
|
@ -435,8 +457,9 @@ class Repositories(object):
|
||||||
"""
|
"""
|
||||||
Get all ModuleInfo instances available.
|
Get all ModuleInfo instances available.
|
||||||
|
|
||||||
@param caps [list(str)] Filter on capabilities.
|
:param caps: filter on capabilities:
|
||||||
@return [dict(ModuleInfo)]
|
:type caps: list[str]
|
||||||
|
:rtype: dict[:class:`ModuleInfo`]
|
||||||
"""
|
"""
|
||||||
modules = {}
|
modules = {}
|
||||||
for repos in reversed(self.repositories):
|
for repos in reversed(self.repositories):
|
||||||
|
|
@ -499,12 +522,13 @@ class Repositories(object):
|
||||||
with open(dest_path, 'wb') as fp:
|
with open(dest_path, 'wb') as fp:
|
||||||
fp.write(icon.read())
|
fp.write(icon.read())
|
||||||
|
|
||||||
def update(self, progress=IProgress()):
|
def update_repositories(self, progress=IProgress()):
|
||||||
"""
|
"""
|
||||||
Update list of repositories by downloading them
|
Update list of repositories by downloading them
|
||||||
and put them in ~/.weboob/repositories/.
|
and put them in ~/.weboob/repositories/.
|
||||||
|
|
||||||
@param progress [IProgress] observer object.
|
:param progress: observer object.
|
||||||
|
:type progress: :class:`IProgress`
|
||||||
"""
|
"""
|
||||||
self.repositories = []
|
self.repositories = []
|
||||||
for name in os.listdir(self.repos_dir):
|
for name in os.listdir(self.repos_dir):
|
||||||
|
|
@ -534,6 +558,15 @@ class Repositories(object):
|
||||||
else:
|
else:
|
||||||
self.repositories.append(repository)
|
self.repositories.append(repository)
|
||||||
|
|
||||||
|
def update(self, progress=IProgress()):
|
||||||
|
"""
|
||||||
|
Update repositories and install new packages versions.
|
||||||
|
|
||||||
|
:param progress: observer object.
|
||||||
|
:type progress: :class:`IProgress`
|
||||||
|
"""
|
||||||
|
self.update_repositories()
|
||||||
|
|
||||||
to_update = []
|
to_update = []
|
||||||
for name, info in self.get_all_modules_info().iteritems():
|
for name, info in self.get_all_modules_info().iteritems():
|
||||||
if not info.is_local() and info.is_installed():
|
if not info.is_local() and info.is_installed():
|
||||||
|
|
@ -557,8 +590,10 @@ class Repositories(object):
|
||||||
"""
|
"""
|
||||||
Install a module.
|
Install a module.
|
||||||
|
|
||||||
@paran module [str,ModuleInfo] module to install.
|
:param module: module to install
|
||||||
@param progress [IProgress] observer object.
|
:type module: :class:`str` or :class:`ModuleInfo`
|
||||||
|
:param progress: observer object
|
||||||
|
:type progress: :class:`IProgress`
|
||||||
"""
|
"""
|
||||||
if isinstance(module, ModuleInfo):
|
if isinstance(module, ModuleInfo):
|
||||||
info = module
|
info = module
|
||||||
|
|
@ -625,7 +660,8 @@ class Repositories(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def url2filename(url):
|
def url2filename(url):
|
||||||
"""
|
"""
|
||||||
Get a safe file name for an URL
|
Get a safe file name for an URL.
|
||||||
|
|
||||||
All non-alphanumeric characters are replaced by _.
|
All non-alphanumeric characters are replaced by _.
|
||||||
"""
|
"""
|
||||||
return ''.join([l if l.isalnum() else '_' for l in url])
|
return ''.join([l if l.isalnum() else '_' for l in url])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue