Exemplo n.º 1
0
 def _zippy(archive, path, src=True):
     path = os.path.abspath(path)
     base = os.path.basename(path)
     for f in osutil.listdir(path, True):
         bf = os.path.basename(f)
         if not RE_exclude.search(bf) and (src or bf in ('__openerp__.py', '__terp__.py') or not bf.endswith('.py')):
             archive.write(os.path.join(path, f), os.path.join(base, f))
Exemplo n.º 2
0
def get_module_filetree(module, dir='.'):
    path = get_module_path(module)
    if not path:
        return False

    dir = os.path.normpath(dir)
    if dir == '.':
        dir = ''
    if dir.startswith('..') or (dir and dir[0] == '/'):
        raise Exception('Cannot access file outside the module')

    if not os.path.isdir(path):
        # zipmodule
        zip = zipfile.ZipFile(path + ".zip")
        files = ['/'.join(f.split('/')[1:]) for f in zip.namelist()]
    else:
        files = osutil.listdir(path, True)

    tree = {}
    for f in files:
        if not f.startswith(dir):
            continue

        if dir:
            f = f[len(dir)+int(not dir.endswith('/')):]
        lst = f.split(os.sep)
        current = tree
        while len(lst) != 1:
            current = current.setdefault(lst.pop(0), {})
        current[lst.pop(0)] = None

    return tree
Exemplo n.º 3
0
def get_module_filetree(module, dir='.'):
    path = get_module_path(module)
    if not path:
        return False

    dir = os.path.normpath(dir)
    if dir == '.':
        dir = ''
    if dir.startswith('..') or (dir and dir[0] == '/'):
        raise Exception('Cannot access file outside the module')

    if not os.path.isdir(path):
        # zipmodule
        zip = zipfile.ZipFile(path + ".zip")
        files = ['/'.join(f.split('/')[1:]) for f in zip.namelist()]
    else:
        files = osutil.listdir(path, True)

    tree = {}
    for f in files:
        if not f.startswith(dir):
            continue

        if dir:
            f = f[len(dir)+int(not dir.endswith('/')):]
        lst = f.split(os.sep)
        current = tree
        while len(lst) != 1:
            current = current.setdefault(lst.pop(0), {})
        current[lst.pop(0)] = None

    return tree
Exemplo n.º 4
0
 def _zippy(archive, path, src=True):
     path = os.path.abspath(path)
     base = os.path.basename(path)
     for f in osutil.listdir(path, True):
         bf = os.path.basename(f)
         if not RE_exclude.search(bf) and (src or bf in ('__openerp__.py', '__terp__.py') or not bf.endswith('.py')):
             archive.write(os.path.join(path, f), os.path.join(base, f))
 def xml_import_report(self, cr, uid, ids, context=None):
     """
      To get the module and extract the xml report definition 
      @param self: The object pointer.
      @param cr: A database cursor
      @param uid: ID of the user currently logged in
      @param context: A standard dictionary
      @return : retrun report
     """
     if context is None:
         context = {}
     list_report = []    
     values =  self.read(cr, uid, ids, context=context)[0]
     module_id = values['module_id'][0]
     if module_id:
         module = self.pool.get('ir.module.module').browse(cr,uid, module_id)
         pathname = CD_ODOO_ADDONS + module.name + "/Report_def/"
         print 'PathName : ',pathname
         list_report = listdir(pathname)
         
         print 'liste des rapports à importer ', list_report 
    
         for filename in list_report:
             open_file = pathname + filename
             fp = tools.file_open(open_file)
             obj_xml_odoo =  odoo_xml(fp)
             my_models = obj_xml_odoo.get_xml_all_models()
             print my_models 
             # Completion of  external models
             new_list_models = list(my_models)
             for name_model in new_list_models:
                 print 'name model ', name_model
                 my_models = self.external_models(cr,uid,name_model,my_models)
             
             print 'export des Id', my_models   
             pool_ir_data = self.pool.get('ir.model.data')
             for rec_model in my_models:
                 print 'model exporte ',rec_model
                 pool_ir_data.export_external_ids(cr,uid,rec_model,module_id)
             fp.close()
         
         print 'conversion des fichiers XML'
         for filename in list_report:
             open_file = pathname + filename
             print ' open_file ',open_file
             fp = tools.file_open(open_file)
             try:
                 print 'XML to report',module.name
                 tools.convert_xml_import(cr, module.name,
                                          fp, 
                                          None, 
                                          'init', 
                                          True, 
                                          None)
             finally:
                 fp.close()