Commit 74a67674 authored by hydrargyrum's avatar hydrargyrum
Browse files

stable_backport: support manual backport files for complicated cases

Some weboob core modules should not simply be copied just to backport
one symbol. It causes every class to be redefined even if they did not
change.

Instead, use some manual code backports for some of them.

Should close:
https://git.weboob.org/weboob/devel/issues/111
https://git.weboob.org/weboob/devel/issues/100
parent ea2e16fc
Pipeline #278635629 failed with stages
in 62 minutes and 2 seconds
......@@ -9,6 +9,7 @@
from os import system, path, makedirs
from subprocess import check_output, STDOUT, CalledProcessError
from collections import defaultdict
import shutil
from termcolor import colored
......@@ -41,6 +42,17 @@ def create_compat_dir(name):
pass
MANUAL_PORTS = [
'weboob.capabilities.bank',
'weboob.browser.pages',
'weboob.browser.exceptions',
'weboob.exceptions',
'weboob.browser.filters.html',
]
MANUAL_PORT_DIR = path.join(path.dirname(__file__), 'stable_backport_data')
class Error(object):
def __init__(self, filename, linenum, message):
self.filename = filename
......@@ -48,6 +60,9 @@ def __init__(self, filename, linenum, message):
self.message = message
self.compat_dir = path.join(path.dirname(filename), 'compat')
def __repr__(self):
return '<%s filename=%r linenum=%s message=%r>' % (type(self).__name__, self.filename, self.linenum, self.message)
def reimport_module(self, module):
# not a weboob module, probably a false positive.
if not module.startswith('weboob'):
......@@ -65,27 +80,30 @@ def reimport_module(self, module):
# this file does not exist, perhaps a directory.
return
# Copy module from devel to a compat/ sub-module
with open(target, 'w') as fp:
for line in r.split('\n'):
# Replace relative imports to absolute ones
m = re.match(r'^from (\.\.?)([\w_\.]+) import (.*)', line)
if m:
if m.group(1) == '..':
base_module = '.'.join(base_module.split('.')[:-1])
fp.write('from %s.%s import %s\n' % (base_module, m.group(2), m.group(3)))
continue
# Inherit all classes by previous ones, if they already existed.
m = re.match(r'^class (\w+)\(([\w,\s]+)\):(.*)', line)
if m and path.exists(filename) and system('grep "^class %s" %s >/dev/null' % (m.group(1), filename)) == 0:
symbol = m.group(1)
trailing = m.group(3)
fp.write('from %s import %s as _%s\n' % (module, symbol, symbol))
fp.write('class %s(_%s):%s\n' % (symbol, symbol, trailing))
continue
fp.write('%s\n' % line)
if module in MANUAL_PORTS:
shutil.copyfile(path.join(MANUAL_PORT_DIR, path.basename(target)), target)
else:
# Copy module from devel to a compat/ sub-module
with open(target, 'w') as fp:
for line in r.split('\n'):
# Replace relative imports to absolute ones
m = re.match(r'^from (\.\.?)([\w_\.]+) import (.*)', line)
if m:
if m.group(1) == '..':
base_module = '.'.join(base_module.split('.')[:-1])
fp.write('from %s.%s import %s\n' % (base_module, m.group(2), m.group(3)))
continue
# Inherit all classes by previous ones, if they already existed.
m = re.match(r'^class (\w+)\(([\w,\s]+)\):(.*)', line)
if m and path.exists(filename) and system('grep "^class %s" %s >/dev/null' % (m.group(1), filename)) == 0:
symbol = m.group(1)
trailing = m.group(3)
fp.write('from %s import %s as _%s\n' % (module, symbol, symbol))
fp.write('class %s(_%s):%s\n' % (symbol, symbol, trailing))
continue
fp.write('%s\n' % line)
# Particular case, in devel some imports have been added to
# weboob/browser/__init__.py
......@@ -189,14 +207,7 @@ def main(self):
system('git add %s' % compat_dirname)
with log('Custom fixups'):
replace_all("""super(Attr, self).__init__(selector, default=default)""", """super(Attr, self).__init__(selector, attr, default=default)""")
replace_all("""super(Link, self).__init__(selector, 'href', default=default)""", """super(Link, self).__init__(selector, default=default)""")
replace_all("""from weboob.browser.exceptions import LoggedOut""", """from .exceptions import LoggedOut""")
for line in output_lines('git grep -n iter_resources -- "modules/*/compat/bank.py"'):
filename, linenum, _ = line.split(':', maxsplit=2)
linenum = int(linenum)
remove_block(filename, linenum)
replace_all("from weboob.browser.exceptions import LoggedOut", "from .weboob_browser_exceptions import LoggedOut")
system('git add -u')
......
from weboob.browser.exceptions import *
class LoggedOut(Exception):
pass
from weboob.browser.filters.html import *
from weboob.browser.filters.standard import ColumnNotFound
from weboob.browser.pages import *
from .weboob_browser_exceptions import LoggedOut
class LoginPage(object):
def on_load(self):
if not self.browser.logging_in:
raise LoggedOut()
super(LoginPage, self).on_load()
import weboob.capabilities.bank as OLD
# can't import *, __all__ is incomplete...
for attr in dir(OLD):
globals()[attr] = getattr(OLD, attr)
__all__ = OLD.__all__
class CapBankWealth(CapBank):
pass
class CapBankPockets(CapBank):
pass
Account.TYPE_MORTGAGE = 17
Account.TYPE_CONSUMER_CREDIT = 18
Account.TYPE_REVOLVING_CREDIT = 19
from weboob.capabilities.housing import *
ENERGY_CLASS = enum(A=u'A', B=u'B', C=u'C', D=u'D', E=u'E', F=u'F', G=u'G')
POSTS_TYPES = enum(RENT=u'RENT',
SALE=u'SALE',
SHARING=u'SHARING',
FURNISHED_RENT=u'FURNISHED_RENT',
VIAGER=u'VIAGER')
ADVERT_TYPES = enum(PROFESSIONAL=u'Professional', PERSONAL=u'Personal')
HOUSE_TYPES = enum(APART=u'Apartment',
HOUSE=u'House',
PARKING=u'Parking',
LAND=u'Land',
OTHER=u'Other',
UNKNOWN=u'Unknown')
from weboob.exceptions import *
class AuthMethodNotImplemented(Exception):
pass
class CaptchaQuestion(Exception):
pass
  • Woob Import @woob-import

    Mentioned in commit 219b6aba

    By ntome on 2018-09-16T12:11:56 (imported from GitLab)

    ·

    Mentioned in commit 219b6aba

    By ntome on 2018-09-16T12:11:56 (imported from GitLab)

    Toggle commit list
  • Woob Import @woob-import

    Mentioned in commit 49cbd220

    By ntome on 2018-09-16T17:42:25 (imported from GitLab)

    ·

    Mentioned in commit 49cbd220

    By ntome on 2018-09-16T17:42:25 (imported from GitLab)

    Toggle commit list
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment