Remove support of zipped modules

This commit is contained in:
Cédric Krier
2011-05-26 15:21:15 +02:00
parent 830ceb9f2e
commit 1655c56c82
4 changed files with 15 additions and 50 deletions
+2
View File
@@ -1,3 +1,5 @@
* Remove support of zipped modules
Version 2.0.0 - 2011-04-26
* Bug fixes (see mercurial logs for details)
* Use md5 hash for indexing translation
+2 -8
View File
@@ -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 @@ def create_graph(module_list, force=None):
# 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 @@ def register_classes(reload_p=False):
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:
+1 -9
View File
@@ -23,7 +23,6 @@ import doctest
from lxml import etree
import time
import imp
import zipimport
_MODULES = False
if __name__ == '__main__':
@@ -210,14 +209,7 @@ def modules_suite():
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=[''])
+10 -33
View File
@@ -6,7 +6,6 @@ Miscelleanous tools used by tryton
"""
import os, sys
import subprocess
import zipfile
from threading import local
import smtplib
try:
@@ -78,27 +77,27 @@ def file_open(name, mode="r", subdir='modules'):
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_name = 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 @@ def file_open(name, mode="r", subdir='modules'):
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():
"""