/usr/bin/weboob is in python-weboob 1.1-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | #! /usr/bin/python
# -*- coding: utf-8 -*-
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
# Copyright(C) 2009-2011 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/>.
import re
import os
import sys
import inspect
from datetime import datetime, timedelta
import weboob.applications
from weboob.tools.ordereddict import OrderedDict
from weboob.tools.application.console import ConsoleApplication
class Weboob(ConsoleApplication):
UPDATE_DAYS_DELAY = 20
def __init__(self):
super(Weboob, self).__init__()
self.update()
capApplicationDict = self.init_CapApplicationDict()
if len(sys.argv) >= 2:
cap = sys.argv.pop(1)
if cap not in capApplicationDict:
print('Unknown capability, please choose one in the following list')
cap = self.choose_capability(capApplicationDict)
else:
cap = self.choose_capability(capApplicationDict)
applications = capApplicationDict[cap]
application = applications[0] if len(applications) == 1 else self.choose_application(applications)
application.run()
def update(self):
for repository in self.weboob.repositories.repositories:
update_date = datetime.strptime(str(repository.update), '%Y%m%d%H%M')
if (datetime.now() - timedelta(days=self.UPDATE_DAYS_DELAY)) > update_date:
update = self.ask('The repositories have not been updated for %s days, do you want to update them ? (y/n)'
% self.UPDATE_DAYS_DELAY,
default='n')
if update.upper() == 'Y':
self.weboob.repositories.update()
break
def choose_application(self, applications):
application = None
while not application:
for app in applications:
print(' %s%2d)%s %s: %s' % (self.BOLD,
applications.index(app) + 1,
self.NC,
app.APPNAME,
app.DESCRIPTION))
r = self.ask(' Select an application', regexp='(\d+|)', default='')
if not r.isdigit():
continue
r = int(r)
if r <= 0 or r > len(applications):
continue
application = applications[r - 1]
return application
def choose_capability(self, capApplicationDict):
cap = None
while cap not in capApplicationDict.keys():
for _cap in capApplicationDict.keys():
print(' %s%2d)%s %s' % (self.BOLD,
capApplicationDict.keys().index(_cap) + 1,
self.NC,
_cap))
r = self.ask(' Select a capability', regexp='(\d+|)', default='')
if not r.isdigit():
continue
r = int(r)
if r <= 0 or r > len(capApplicationDict.keys()):
continue
cap = capApplicationDict.keys()[r - 1]
return cap
def init_CapApplicationDict(self):
capApplicationDict = {}
for path in weboob.applications.__path__:
regexp = re.compile('^%s/([\w\d_]+)$' % path)
for root, dirs, files in os.walk(path):
m = regexp.match(root)
if not (m and '__init__.py' in files):
continue
application = self.get_applicaction_from_filename(m.group(1))
if not application:
continue
capabilities = self.get_application_capabilities(application)
if not capabilities:
continue
for capability in capabilities:
if capability in capApplicationDict:
capApplicationDict[capability].append(application)
else:
capApplicationDict[capability] = [application]
return OrderedDict([(k, v) for k, v in sorted(capApplicationDict.iteritems())])
def get_application_capabilities(self, application):
if hasattr(application, 'CAPS') and application.CAPS:
_capabilities = list(application.CAPS) if isinstance(application.CAPS, tuple) else [application.CAPS]
return [os.path.splitext(os.path.basename(inspect.getfile(x)))[0] for x in _capabilities]
def get_applicaction_from_filename(self, name):
module = 'weboob.applications.%s.%s' % (name, name)
try:
_module = __import__(module, fromlist=['*'])
except ImportError:
return
_application = [x for x in dir(_module) if x.lower() == name]
if _application:
return getattr(_module, _application[0])
if __name__ == '__main__':
try:
Weboob()
except KeyboardInterrupt:
print('')
|