- 
                Notifications
    You must be signed in to change notification settings 
- Fork 79
[REF] util.views: refactor converter code, regroup views helpers #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[REF] util.views: refactor converter code, regroup views helpers #23
Conversation
715851a    to
    80dc045      
    Compare
  
    | upgradeci retry with always all modules in all versions | 
80dc045    to
    905ff99      
    Compare
  
    905ff99    to
    e7d1a8a      
    Compare
  
    | upgradeci skip | 
e7d1a8a    to
    7b004bc      
    Compare
  
    | upgradeci retry with always only base mass_mailing point_of_sale test_themes theme_common theme_treehouse web web_editor website website_blog website_enterprise website_event website_mass_mailing website_sale in all versions | 
a300c58    to
    83c4db4      
    Compare
  
    83c4db4    to
    767a572      
    Compare
  
    | upgradeci retry | 
767a572    to
    9173eb0      
    Compare
  
    | @KangOl I've rebased this on the latest master commit, resolved conflicts, etc.. CI checks seem good. FYI @aj-fuentes | 
Refactored BootstrapConverter code, separating conversion class and operations from bootstrap-specific code. The new EtreeConverter can be used to implement conversions of any kind, reusing the pre-defined ElementOperations by defining an operations list.
Simplified ElementOperation class, removing unnecessary features, such as `.op()` method. Made `xpath` attribute part of the base class, subclasses must honor it to restrict their scope of operation. Reworked EtreeConverter class methods, generalized to work with any kind of converter operations (not just Bootstrap conversions). Also made docstrings private (excluded from online docs).
Move xpath keywords / where clause functions from base/16.0 pre-90-convert-bootstrap5.py script into util.views and add shortcut methods for them in converter class. Also refactored to make them usable with arbitrary converters. Revise converter API, especially simplified classmethods / remove oneshot aliases (it's easier to just instantiate the converter first). Refactor parse/unparse string arch code into separate helper functions, and add a `ArchEditor` context manager to parse-edit-unparse an arch within a context (similar to edit_views). Make sure EtreeConverter is pickle-able for multiprocessing: concurrent.futures ProcessPoolExecutor uses multiprocessing to spawn its subprocess workers. That requires memory data from the main process to be transferred by serializing and deserializing, using the pickle library. To make this work: - the converter function must not be an anonymous "factory" function, e.g. one generated as a nested function, so unaccessible from the outer scope. - instance values in the serialized objects must also be pickleable. Therefore the following changes have been done: - the converter function is now a method of the converter class - to keep @lru_cache decorator on the method, the entire class is made hashable, this is done by computing a hash of the provided arguments to `__init__`, making some attributes "private", and adding read-only properties to access them. - to make the instances pickable, the compiled coversions are first removed from the pickle-able `__dict__`, because `lxml.XPath` objects are not python-native, and they're re-compiled when the instances are de-serialized. Made docstrings for new functions private (excluded from online docs). upgrade PR: odoo/upgrade#5431
Changes: - move `util.views_convert` -> `util.views.convert` - move records-related views helpers into `util.views.records` - move `util.convert_bootstrap` -> `util.views.bootstrap` - move some helpers from `util.records` -> `util.views.records` - add version checks for views/html conversion helpers
Store and return the number of matched and converted record's values that are processed by `convert_html_columns()`. Add a `verbose=False` optional argument in `convert_html_content()` that collects these stats and logs them. Also, do the same in `util.views.records.convert_html_fields()`.
`util.snippets` imports util from `odoo.upgrade` namespace package and that makes it incompatible with odoo versions <= 13.0. Replaced the import with direct package-relative ones.
9173eb0    to
    cef8114      
    Compare
  
    
Overview of changes (see commits for details):
base/16.0/pre-90-convert-bootstrap5.pyso that they can be reused for other similar kind of operations using converters (ie. apply converter to all html fields / templates, etc.) (upgrade PR: odoo/upgrade#5431 )util.views(converter, bootstrap, records)