def _upload(self, cr, uid, datas, context):
    pool = pooler.get_pool(cr.dbname)
    mod = pool.get('ir.module.module').browse(cr, uid, datas['id'])
    download = datas['form']['url_download'] or ''
    if not download:
        res = module_zip.createzip(cr, uid, datas['id'], context,
                b64enc=False, src=datas['form']['include_src'])
        download = 'http://www.openerp.com/download/modules/'+res['module_filename']
        result = post_multipart('www.openerp.com', '/mtree_upload.php',
            [
                ('login', datas['form']['login']),
                ('password', datas['form']['password']),
                ('module_name', str(mod.name))
            ], [
                ('module', res['module_filename'], res['module_file'])
            ])
        if result and result[0] == "1":
            raise wizard.except_wizard(_('Error'), _('Login failed!'))
        elif result and result[0] == "2":
            raise wizard.except_wizard(_('Error'),
                    _('This version of the module is already exist on the server'))
        elif result and result[0] != "0":
            raise wizard.except_wizard(_('Error'), _('Failed to upload the file'))

    updata = {
        'link_name': mod.shortdesc or '',
        'new_cat_id': datas['form']['category'],
        'link_desc': (mod.description or '').replace('\n','<br/>\n'),
        'website': mod.website or '',
        'price': '0.0',
        'email': datas['form']['email'] or '',
        'cust_1': download,
        'cust_2': datas['form']['demourl'] or '',   # Put here the download url
        'cust_3': mod.url or '/',
        'cust_4': datas['form']['docurl'] or '',
        'cust_5': datas['form']['license'] or '',
        'cust_6': mod.installed_version or '0',
        'cust_7': mod.name,
        'option': 'com_mtree',
        'task': 'savelisting',
        'Itemid': '99999999',
        'cat_id': '0',
        'adminForm': '',
        'auto_login': datas['form']['login'],
        'auto_password': datas['form']['password']
    }
    name = mod.name
    a = urllib.urlopen('http://www.openerp.com/mtree_interface.php?module=%s' % (name,))
    aa = a.read()
    if aa[0]<>'0':
        updata['link_id']=aa.split('\n')[0]
        updata['option'] = 'mtree'

    files = []
    if datas['form']['image']:
        files.append(('link_image', 'link_image.png',
            base64.decodestring(datas['form']['image'])))
    result = post_multipart('www.openerp.com', '/index.php', updata.items(), files)
    return {'result': result}
def _upload(self, cr, uid, datas, context):
    pool = pooler.get_pool(cr.dbname)
    modules = pool.get('ir.module.module').browse(cr, uid, datas['ids'])
    log = [[], [], []] # [update, already, error]
    for mod in modules: # whoooouuuuffff update
        if mod.state != 'installed':
            result[2].append(mod.name)
            continue
        res = module_zip.createzip(cr, uid, mod.id, context, b64enc=False,
                src=(mod.license in ('GPL-2')))
        download = 'http://www.openerp.com/download/modules/'+res['module_filename']
        result = post_multipart('www.openerp.com', '/mtree_upload.php',
                [('login', datas['form']['login']),
                    ('password', datas['form']['password']),
                    ('module_name', mod.name)
                ], [('module', res['module_filename'],
                    res['module_file'])
                ])
        if result[0] == "1":
            raise wizard.except_wizard(_('Error'), _('Login failed!'))
        elif result[0] == "0":
            log[0].append(mod.name)
        elif result[0] == "2":
            log[1].append(mod.name)
        else:
            log[2].append(mod.name)
        updata = {
            'link_name': mod.shortdesc or '',
            'link_desc': (mod.description or '').replace('\n','<br/>\n'),
            'website': mod.website or '',
            'email': datas['form']['email'] or '',
            'cust_1': download,
            'cust_3': mod.url or '/',
            'cust_6': mod.installed_version or '0',
            'cust_7': mod.name,
            'option': 'com_mtree',
            'task': 'savelisting',
            'Itemid': '99999999',
            'cat_id': '0',
            'adminForm': '',
            'auto_login': datas['form']['login'],
            'auto_password': datas['form']['password']
        }
        a = urlopen('http://www.openerp.com/mtree_interface.php?module=%s' % (mod.name,))
        aa = a.read()
        if aa[0]<>'0':
            updata['link_id']=aa.split('\n')[0]
            updata['cat_id']=aa.split('\n')[1]
            updata['option'] = 'mtree'
        result = post_multipart('www.openerp.com', '/index.php', updata.items(), [])
    return {'update': '\n'.join(log[0]), 'already': '\n'.join(log[1]), 'error': '\n'.join(log[2])}
 def createzip(self, cr, uid, data, context):
     return module_zip.createzip(cr, uid, data["id"], context, src=data["form"]["include_src"])