support repositories to manage backends (closes #747)

This commit is contained in:
Romain Bignon 2012-01-03 12:10:21 +01:00
commit 14a7a1d362
410 changed files with 1079 additions and 297 deletions

View file

@ -780,8 +780,8 @@ class Boobathon(ReplApplication):
print "Ok, so leave now, fag."
sys.exit(0)
def is_backend_loadable(self, backend):
def is_module_loadable(self, module):
"""
Overload a ConsoleApplication method.
"""
return backend.name == 'redmine'
return module.name == 'redmine'

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Romain Bignon, Christophe Benz
# Copyright(C) 2010-2012 Romain Bignon, Christophe Benz
#
# This file is part of weboob.
#
@ -24,6 +24,7 @@ import re
from copy import copy
from weboob.capabilities.account import ICapAccount
from weboob.core.repositories import IProgress
from weboob.core.modules import ModuleLoadError
from weboob.tools.application.repl import ReplApplication
from weboob.tools.ordereddict import OrderedDict
@ -35,10 +36,10 @@ __all__ = ['WeboobCfg']
class WeboobCfg(ReplApplication):
APPNAME = 'weboob-config'
VERSION = '0.a'
COPYRIGHT = 'Copyright(C) 2010-2011 Christophe Benz, Romain Bignon'
COPYRIGHT = 'Copyright(C) 2010-2012 Christophe Benz, Romain Bignon'
DESCRIPTION = "Weboob-Config is a console application to add/edit/remove backends, " \
"and to register new website accounts."
COMMANDS_FORMATTERS = {'backends': 'table',
COMMANDS_FORMATTERS = {'modules': 'table',
'list': 'table',
}
DISABLE_REPL = True
@ -53,10 +54,10 @@ class WeboobCfg(ReplApplication):
"""
add NAME [OPTIONS ...]
Add a configured backend.
Add a backend.
"""
if not line:
print >>sys.stderr, 'You must specify a backend name. Hint: use the "backends" command.'
print >>sys.stderr, 'You must specify a module name. Hint: use the "modules" command.'
return 2
name, options = self.parse_command_args(line, 2, 1)
if options:
@ -78,9 +79,9 @@ class WeboobCfg(ReplApplication):
def do_register(self, line):
"""
register NAME
register MODULE
Register a new account on a backend.
Register a new account on a module.
"""
self.register_backend(line)
@ -117,15 +118,15 @@ class WeboobCfg(ReplApplication):
"""
list [CAPS ..]
Show configured backends.
Show backends.
"""
caps = line.split()
for instance_name, name, params in sorted(self.weboob.backends_config.iter_backends()):
backend = self.weboob.modules_loader.get_or_load_module(name)
if caps and not self.caps_included(backend.iter_caps(), caps):
continue
row = OrderedDict([('Instance name', instance_name),
('Backend', name),
row = OrderedDict([('Name', instance_name),
('Module', name),
('Configuration', ', '.join(
'%s=%s' % (key, ('*****' if key in backend.config and backend.config[key].masked \
else value)) \
@ -138,7 +139,7 @@ class WeboobCfg(ReplApplication):
"""
remove NAME
Remove a configured backend.
Remove a backend.
"""
if not self.weboob.backends_config.remove_backend(instance_name):
print >>sys.stderr, 'Backend instance "%s" does not exist' % instance_name
@ -155,7 +156,7 @@ class WeboobCfg(ReplApplication):
def do_enable(self, name):
"""
enable NAME
enable BACKEND
Enable a disabled backend
"""
@ -163,7 +164,7 @@ class WeboobCfg(ReplApplication):
def do_disable(self, name):
"""
disable NAME
disable BACKEND
Disable a backend
"""
@ -171,7 +172,7 @@ class WeboobCfg(ReplApplication):
def do_edit(self, line):
"""
edit NAME
edit BACKEND
Edit a backend
"""
@ -181,20 +182,17 @@ class WeboobCfg(ReplApplication):
print >>sys.stderr, 'Error: backend "%s" not found' % line
return 1
def do_backends(self, line):
def do_modules(self, line):
"""
backends [CAPS ...]
modules [CAPS ...]
Show available backends.
Show available modules.
"""
caps = line.split()
self.weboob.modules_loader.load_all()
for name, backend in sorted(self.weboob.modules_loader.loaded.iteritems()):
if caps and not self.caps_included(backend.iter_caps(), caps):
continue
for name, info in sorted(self.weboob.repositories.get_all_modules_info(caps).iteritems()):
row = OrderedDict([('Name', name),
('Capabilities', ', '.join(cap.__name__ for cap in backend.iter_caps())),
('Description', backend.description),
('Capabilities', ', '.join(info.capabilities)),
('Description', info.description),
])
self.format(row)
self.flush()
@ -203,40 +201,44 @@ class WeboobCfg(ReplApplication):
"""
info NAME
Display information about a backend.
Display information about a module.
"""
if not line:
print >>sys.stderr, 'You must specify a backend name. Hint: use the "backends" command.'
print >>sys.stderr, 'You must specify a module name. Hint: use the "modules" command.'
return 2
try:
backend = self.weboob.modules_loader.get_or_load_module(line)
except ModuleLoadError:
backend = None
if not backend:
print >>sys.stderr, 'Backend "%s" does not exist.' % line
minfo = self.weboob.repositories.get_module_info(line)
if not minfo:
print >>sys.stderr, 'Module "%s" does not exist.' % line
return 1
try:
module = self.weboob.modules_loader.get_or_load_module(line)
except ModuleLoadError:
module = None
print '.------------------------------------------------------------------------------.'
print '| Backend %-68s |' % backend.name
print '| Module %-69s |' % minfo.name
print "+-----------------.------------------------------------------------------------'"
print '| Version | %s' % backend.version
print '| Maintainer | %s' % backend.maintainer
print '| License | %s' % backend.license
print '| Description | %s' % backend.description
print '| Capabilities | %s' % ', '.join([cap.__name__ for cap in backend.iter_caps()])
first = True
for key, field in backend.config.iteritems():
value = field.label
if not field.default is None:
value += ' (default: %s)' % field.default
if first:
print '| | '
print '| Configuration | %s: %s' % (key, value)
first = False
else:
print '| | %s: %s' % (key, value)
print '| Version | %s' % minfo.version
print '| Maintainer | %s' % minfo.maintainer
print '| License | %s' % minfo.license
print '| Description | %s' % minfo.description
print '| Capabilities | %s' % ', '.join(minfo.capabilities)
print '| Installed | %s%s' % (('yes' if module else 'no'), ' (new version available)' if self.weboob.repositories.versions.get(minfo.name) > minfo.version else '')
print '| Location | %s' % (minfo.url or os.path.join(minfo.path, minfo.name))
if module:
first = True
for key, field in module.config.iteritems():
value = field.label
if not field.default is None:
value += ' (default: %s)' % field.default
if first:
print '| | '
print '| Configuration | %s: %s' % (key, value)
first = False
else:
print '| | %s: %s' % (key, value)
print "'-----------------'"
def do_applications(self, line):
@ -254,3 +256,23 @@ class WeboobCfg(ReplApplication):
if m and '__init__.py' in files:
applications.add(m.group(1))
print ' '.join(sorted(applications)).encode('utf-8')
def do_update(self, line):
"""
update
Update weboob.
"""
class Progress(IProgress):
def progress(self, percent, message):
print '=== [%3.0f%%] %s' % (percent*100, message)
self.weboob.repositories.update(Progress())
def do_install(self, line):
"""
install MODULE
Install a module.
"""
self.install_module(line)

View file

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2012 Romain Bignon
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .weboobrepos import WeboobRepos
__all__ = ['WeboobRepos']

View file

@ -0,0 +1,125 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2012 Romain Bignon
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
import tarfile
import os
import shutil
import sys
from copy import copy
from weboob.core.repositories import Repository
from weboob.tools.application.repl import ReplApplication
__all__ = ['WeboobRepos']
class WeboobRepos(ReplApplication):
APPNAME = 'weboob-repos'
VERSION = '0.a'
COPYRIGHT = 'Copyright(C) 2012 Romain Bignon'
DESCRIPTION = "Weboob-repos is a console application to manage a Weboob Repository."
COMMANDS_FORMATTERS = {'backends': 'table',
'list': 'table',
}
DISABLE_REPL = True
weboob_commands = copy(ReplApplication.weboob_commands)
weboob_commands.remove('backends')
def load_default_backends(self):
pass
def do_create(self, line):
"""
create NAME [PATH]
Create a new repository. If PATH is missing, create repository
on the current directory.
"""
name, path = self.parse_command_args(line, 2, 1)
if not path:
path = os.getcwd()
else:
path = os.path.realpath(path)
if not os.path.exists(path):
os.mkdir(path)
elif not os.path.isdir(path):
print u'"%s" is not a directory' % path
return 1
r = Repository('http://')
r.name = name
r.maintainer = self.ask('Enter maintainer of the repository')
r.save(os.path.join(path, r.INDEX))
print u'Repository "%s" created.' % path
def do_build(self, line):
"""
build SOURCE REPOSITORY
Build backends contained in SOURCE to REPOSITORY.
Example:
$ weboob-repos build $HOME/src/weboob/modules /var/www/updates.weboob.org/0.a/
"""
source_path, repo_path = self.parse_command_args(line, 2, 2)
index_file = os.path.join(repo_path, Repository.INDEX)
r = Repository('http://')
try:
with open(index_file, 'r') as fp:
r.parse_index(fp)
except IOError, e:
print >>sys.stderr, 'Unable to open repository: %s' % e
print >>sys.stderr, 'Use the "create" command before.'
return 1
r.build_index(source_path, index_file)
for name, module in r.modules.iteritems():
tarname = os.path.join(repo_path, '%s.tar.gz' % name)
module_path = os.path.join(source_path, name)
if os.path.exists(tarname):
tar_mtime = int(datetime.fromtimestamp(os.path.getmtime(tarname)).strftime('%Y%m%d%H%M'))
if tar_mtime >= module.version:
continue
print 'Create archive for %s' % name
with tarfile.open(tarname, 'w:gz') as tar:
tar.add(module_path, arcname=name, filter=self._archive_filter)
# Copy icon.
icon_path = os.path.join(module_path, 'favicon.png')
if os.path.exists(icon_path):
shutil.copy(icon_path, os.path.join(repo_path, '%s.png' % name))
def _archive_filter(self, tarinfo):
# Skip *.pyc files in tarballs.
if tarinfo.name.endswith('.pyc'):
return None
# Don't include *.png files in tarball
if tarinfo.name.endswith('.png'):
return None
return tarinfo