Reviewers: ,


Please review this at http://codereview.tryton.org/38005/

Affected files:
  M trytond/modules/__init__.py
  M trytond/tests/test_tryton.py
  M trytond/tools/misc.py


Index: trytond/modules/__init__.py
===================================================================
--- a/trytond/modules/__init__.py
+++ b/trytond/modules/__init__.py
@@ -3,8 +3,6 @@
 from __future__ import with_statement
 import os, sys, imp
 import itertools
-import zipfile
-import zipimport
 import traceback
 import logging
 import contextlib
@@ -152,7 +150,7 @@
                 # directory
                 tryton_file = OPJ(ep.dist.location, '__tryton__.py')
                 mod_path = os.path.dirname(ep.dist.location)
- if os.path.isfile(tryton_file) or zipfile.is_zipfile(mod_path+'.zip'):
+        if os.path.isfile(tryton_file):
             with tools.file_open(tryton_file, subdir='') as fp:
                 info = tools.safe_eval(fp.read())
             packages.append((module, info.get('depends', []), info))
@@ -359,11 +357,7 @@
             reload(sys.modules['trytond.modules.' + module])
             continue

-        if os.path.isfile(OPJ(MODULES_PATH, module + '.zip')):
-            mod_path = OPJ(MODULES_PATH, module + '.zip')
-            zimp = zipimport.zipimporter(mod_path)
-            zimp.load_module('trytond.modules.' + module)
-        elif os.path.isdir(OPJ(MODULES_PATH, module)):
+        if os.path.isdir(OPJ(MODULES_PATH, module)):
             mod_file, pathname, description = imp.find_module(module,
                     [MODULES_PATH])
             try:
Index: trytond/tests/test_tryton.py
===================================================================
--- a/trytond/tests/test_tryton.py
+++ b/trytond/tests/test_tryton.py
@@ -23,7 +23,6 @@
 from lxml import etree
 import time
 import imp
-import zipimport

 _MODULES = False
 if __name__ == '__main__':
@@ -210,14 +209,7 @@
     for package in graph:
         module = package.name
         test_module = 'trytond.modules.%s.tests' % module
-        if os.path.isfile(os.path.join(MODULES_PATH, module + '.zip')):
-            mod_path = os.path.join(MODULES_PATH, module + '.zip')
-            zimp = zipimport.zipimporter(mod_path)
-            try:
-                test_mod = zimp.load_module(test_module)
-            except zipimport.ZipImportError:
-                continue
-        elif os.path.isdir(os.path.join(MODULES_PATH, module)) or \
+        if os.path.isdir(os.path.join(MODULES_PATH, module)) or \
                 module in EGG_MODULES:
             try:
                 test_mod = __import__(test_module, fromlist=[''])
Index: trytond/tools/misc.py
===================================================================
--- a/trytond/tools/misc.py
+++ b/trytond/tools/misc.py
@@ -6,7 +6,6 @@
 """
 import os, sys
 import subprocess
-import zipfile
 from threading import local
 import smtplib
 try:
@@ -78,27 +77,27 @@
     from trytond.modules import EGG_MODULES
     root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

-    name3 = False
+    egg_name = False
     if subdir == 'modules':
         module_name = name.split(os.sep)[0]
         if module_name in EGG_MODULES:
             epoint = EGG_MODULES[module_name]
             mod_path = os.path.join(epoint.dist.location,
                     *epoint.module_name.split('.')[:-1])
-            name3 = os.path.join(mod_path, name)
-            if not os.path.isfile(name3):
+            egg_name3 = os.path.join(mod_path, name)
+            if not os.path.isfile(egg_name):
                 # Find module in path
                 for path in sys.path:
                     mod_path = os.path.join(path,
                             *epoint.module_name.split('.')[:-1])
-                    name3 = os.path.join(mod_path, name)
-                    if os.path.isfile(name3):
+                    egg_name = os.path.join(mod_path, name)
+                    if os.path.isfile(egg_name):
                         break
-                if not os.path.isfile(name3):
+                if not os.path.isfile(egg_name):
                     # When testing modules from setuptools location is the
                     # module directory
- name3 = os.path.join(os.path.dirname(epoint.dist.location),
-                            name)
+                    egg_name = os.path.join(
+                        os.path.dirname(epoint.dist.location), name)

     if subdir:
         if subdir == 'modules'\
@@ -113,33 +112,11 @@
     else:
         name = os.path.join(root_path, name)

-    # Check for a zipfile in the path
-    head = name
-    zipname = False
-    name2 = False
-    while True:
-        head, tail = os.path.split(head)
-        if head == root_path:
-            break
-        if not tail:
-            break
-        if zipname:
-            zipname = os.path.join(tail, zipname)
-        else:
-            zipname = tail
-        if zipfile.is_zipfile(head+'.zip'):
-            zfile = zipfile.ZipFile(head+'.zip')
-            try:
-                return StringIO.StringIO(zfile.read(os.path.join(
-                    os.path.basename(head), zipname).replace(
-                        os.sep, '/')))
-            except Exception:
- name2 = os.path.normpath(os.path.join(head + '.zip', zipname))
-    for i in (name2, name, name3):
+    for i in (name, egg_name):
         if i and os.path.isfile(i):
             return open(i, mode)

-    raise IOError, 'File not found : '+str(name)
+    raise IOError('File not found : %s ' % name)

 def get_smtp_server():
     """


--
[email protected] mailing list

Reply via email to