Skip to content

Instantly share code, notes, and snippets.

View guewen's full-sized avatar

Guewen Baconnier guewen

View GitHub Profile
# -*- coding: utf-8 -*-
from __future__ import print_function
import pickle
import os
from collections import Counter, defaultdict
from lxml import etree
old_path = '/home/gbaconnier/code/odoo/l10n-switzerland/l10n_ch_zip/l10n_ch_better_zip.xml'
new_path = '/home/gbaconnier/code/instances/dev/parts/l10n-switzerland/l10n_ch_zip/l10n_ch_better_zip.xml'
@guewen
guewen / magentoerpconnect.feature
Created April 8, 2014 05:51
migrating magentoerpconnect using oerpscenario (5→7)
@migration @connector
Feature: install and configure the modules related to the magento connector
Scenario: install addons
Given I install the required modules with dependencies:
| name |
| magentoerpconnect |
Then my modules should have been installed and models reloaded
@guewen
guewen / benchmark.py
Last active January 2, 2016 16:39
Timing context manager, with indentation for nested timings (http://dabeaz.blogspot.ch/2010/02/context-manager-for-timing-benchmarks.html modified to indent by nested level).
import threading
import time
bench = threading.local()
class benchmark(object):
def __init__(self, name):
self.name = name
def __enter__(self):
@guewen
guewen / pg_on_ram.sh
Last active January 24, 2020 08:37
Create a PostgreSQL cluster in a ramfs and start the server on this cluster.
#!/bin/bash
PORT=6432
# Create a ramfs
if [ -f /tmp/pg_on_ram ]
then
echo "/tmp/pg_on_ram already exists"
exit 1
fi
@guewen
guewen / behave_optional_argument
Last active May 21, 2020 13:16
Use an optional argument in a behave phrase.
from behave.matchers import register_type
def parse_optional(text):
return text.strip()
# https://pypi.python.org/pypi/parse#custom-type-conversions
parse_optional.pattern = r'\s?\w*\s?'
register_type(optional=parse_optional)
import logging
from contextlib import contextmanager
class HoldingHandler(logging.Handler):
""" Does never flush the logs if not explicitely asked.
Keep them all in memory
"""

Magentoerpconnect Redesign

Task queue

The actual batches synchronizations have to be replaced by a queue system with tasks. It means that each action on OpenERP that would require to interact with Magento would become a task pushed in a queue and one or more worker would execute the tasks.

A very basic and naive queue could be implemented using the OpenERP's crons, either each task being a cron itself either one cron running tasks from a table.

@guewen
guewen / magento_api.rb
Last active February 23, 2016 13:59
Magento API simple client in Ruby
# Copyright Camptocamp SA 2012
# License: AGPL (GNU Affero General Public License)[http://www.gnu.org/licenses/agpl-3.0.txt]
# Author Guewen Baconnier
require "xmlrpc/client"
require 'pp'
XMLRPC::Config::ENABLE_NIL_PARSER = true
XMLRPC::Config::ENABLE_NIL_CREATE = true
class MagentoAPI