Commit d10f0e39 authored by David Douard's avatar David Douard
Browse files

[mboximport] rename the script to bin/cw-mboximport

also update the setup.py file and make bin/cw-mboximport managed by setup.py.
We still provide this as a biin/ script instead of an entry_point since we
still build our deb packages without setuptools...
parent 856d9249f6d2
......@@ -23,6 +23,7 @@ classifiers = [
__depends__ = {'cubicweb': '>= 3.20.0',
'cubicweb-file': '>= 1.9.0',
'logilab-common': '>= 0.58.3',
'cwclientlib': '>= 0.3.1',
}
__recommends__ = {'cubicweb-comment': None}
......@@ -51,3 +52,6 @@ for dirname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data', 'i18
data_files.append([join(THIS_CUBE_DIR, dirname), listdir(dirname)])
# Note: here, you'll need to add subdirectories if you want
# them to be included in the debian package
scripts = ['bin/cw-mboximport']
packages = ['cwemail']
#!/usr/bin/python
from cwemail.mboximport import main
main()
#!/usr/bin/env python
# pylint: disable-msg=W0404,W0622,W0704,W0613,W0152
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# pylint: disable=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611
#
# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of the CubicWeb email cube.
#
# CubicWeb is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""Generic Setup script, takes package info from __pkginfo__.py file
"""
__docformat__ = "restructuredtext en"
import os
import sys
import shutil
from os.path import isdir, exists, join, walk
from os.path import isdir, exists, join, walk, dirname
try:
if os.environ.get('NO_SETUPTOOLS'):
......@@ -21,38 +38,49 @@ except ImportError:
from distutils.command import install_lib
USE_SETUPTOOLS = 0
# load metadata from the __pkginfo__.py file so there is no risk of conflict
# see https://packaging.python.org/en/latest/single_source_version.html
base_dir = dirname(__file__)
pkginfo = {}
with open(join(base_dir, "__pkginfo__.py")) as f:
exec(f.read(), pkginfo)
# get required metadatas
modname = pkginfo['modname']
version = pkginfo['version']
license = pkginfo['license']
description = pkginfo['description']
web = pkginfo['web']
author = pkginfo['author']
author_email = pkginfo['author_email']
classifiers = pkginfo['classifiers']
with open(join(base_dir, 'README')) as f:
long_description = f.read()
# get optional metadatas
distname = pkginfo.get('distname', modname)
scripts = pkginfo.get('scripts', ())
include_dirs = pkginfo.get('include_dirs', ())
data_files = pkginfo.get('data_files', None)
ext_modules = pkginfo.get('ext_modules', None)
dependency_links = pkginfo.get('dependency_links', ())
packages = pkginfo.get('packages', ())
sys.modules.pop('__pkginfo__', None)
# import required features
from __pkginfo__ import modname, version, license, description, \
web, author, author_email, classifiers
# import optional features
import __pkginfo__
distname = getattr(__pkginfo__, 'distname', modname)
scripts = getattr(__pkginfo__, 'scripts', [])
data_files = getattr(__pkginfo__, 'data_files', None)
include_dirs = getattr(__pkginfo__, 'include_dirs', [])
ext_modules = getattr(__pkginfo__, 'ext_modules', None)
dependency_links = getattr(__pkginfo__, 'dependency_links', [])
STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build')
IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
if exists('README'):
long_description = file('README').read()
else:
long_description = ''
if USE_SETUPTOOLS:
requires = {}
for entry in ("__depends__", "__recommends__"):
requires.update(getattr(__pkginfo__, entry, {}))
install_requires = [("%s %s" % (d, v and v or "")).strip()
requires = {}
for entry in ("__depends__",): # "__recommends__"):
requires.update(pkginfo.get(entry, {}))
install_requires = [("%s %s" % (d, v and v or "")).strip()
for d, v in requires.iteritems()]
else:
install_requires = []
install_requires = []
BASE_BLACKLIST = ('CVS', '.svn', '.hg', '.git', 'debian', 'dist', 'build')
IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
def ensure_scripts(linux_scripts):
"""Creates the proper script names required for each platform
(taken from 4Suite)
......@@ -80,7 +108,7 @@ def get_packages(directory, prefix):
return result
def export(from_dir, to_dir,
blacklist=STD_BLACKLIST,
blacklist=BASE_BLACKLIST,
ignore_ext=IGNORED_EXTENSIONS,
verbose=True):
"""make a mirror of from_dir in to_dir, omitting directories and files
......@@ -139,9 +167,6 @@ def install(**kwargs):
if USE_SETUPTOOLS:
if '--force-manifest' in sys.argv:
sys.argv.remove('--force-manifest')
# install-layout option was introduced in 2.5.3-1~exp1
elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv:
sys.argv.remove('--install-layout=deb')
if USE_SETUPTOOLS and install_requires:
kwargs['install_requires'] = install_requires
kwargs['dependency_links'] = dependency_links
......@@ -156,8 +181,8 @@ def install(**kwargs):
scripts = ensure_scripts(scripts),
data_files = data_files,
ext_modules = ext_modules,
packages = packages,
cmdclass = {'install_lib': MyInstallLib},
classifiers = classifiers,
**kwargs
)
......
# -*- coding: iso-8859-1 -*-
import sys
from os.path import join, dirname, abspath
from socket import gethostname
from StringIO import StringIO
from os.path import join
from logilab.common.testlib import unittest_main
from cwclientlib import cwproxy
......@@ -10,6 +12,13 @@ from cubicweb.devtools.testlib import CubicWebTC
from cubicweb.devtools.httptest import CubicWebServerTC
from cubicweb.mail import construct_message_id
try:
from cwemail.mboximport import Importer
except ImportError:
sys.path.append(dirname(dirname(abspath(__file__))))
from cwemail.mboximport import Importer
MSG = u'''From sthenault@free.fr Tue Jan 23 15:21:10 2007
Return-Path: <sthenault@free.fr>
X-Original-To: Sylvain.Thenault@logilab.fr
......@@ -148,24 +157,31 @@ hop
hop
'''
from cubes.email.mboximportclient import Importer
class ReplyCommentHooksTC(CubicWebServerTC):
token_id = u'mboximport'
def setup_database(self):
with self.admin_access.client_cnx() as cnx:
self.b = cnx.create_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau").eid
e = cnx.create_entity('EmailAddress', address=u'sylvain.thenault@logilab.fr', alias=u'syt')
cnx.execute('SET X use_email E WHERE X login "anon", E eid %(e)s', {'e': e.eid})
cnx.create_entity('AuthToken', enabled=True, id=self.token_id, token_for_user=cnx.user)
self.b = cnx.create_entity('BlogEntry', title=u"une news !",
content=u"cubicweb c'est beau").eid
e = cnx.create_entity('EmailAddress',
address=u'sylvain.thenault@logilab.fr',
alias=u'syt')
cnx.execute('SET X use_email E WHERE X login "anon", E eid %(e)s',
{'e': e.eid})
cnx.create_entity('AuthToken', enabled=True, id=self.token_id,
token_for_user=cnx.user)
cnx.commit()
self.secret = cnx.execute('String X WHERE T token X')[0][0]
self.secret = cnx.execute('String X WHERE T token X, T id %(id)s',
{'id': self.token_id})[0][0]
def test_comment_created(self):
msg = open(join(self.datadir, 'reply.mbox'), 'rb').read() % \
construct_message_id(self.vreg.config.appid, self.b, False)
mi = Importer(cwproxy.CWProxy(self.config['base-url'], auth=cwproxy.SignedRequestAuth(self.token_id, self.secret)))
mi = Importer(cwproxy.CWProxy(self.config['base-url'],
auth=cwproxy.SignedRequestAuth(self.token_id,
self.secret)))
mi.import_mbox_stream(StringIO(msg))
with self.admin_access.client_cnx() as cnx:
self.assertTrue(cnx.execute('Email X'))
......
"""unit tests for email mbox import functionnality"""
import os
import sys
from os import mkdir
from os.path import join, dirname, exists, abspath
from StringIO import StringIO
......@@ -9,7 +11,11 @@ from cwclientlib import cwproxy
from cubicweb.devtools.httptest import CubicWebServerTC
from cubes.email.mboximportclient import Importer
try:
from cwemail.mboximport import Importer
except ImportError:
sys.path.append(dirname(dirname(abspath(__file__))))
from cwemail.mboximport import Importer
class MBOXImporterTC(CubicWebServerTC):
......@@ -31,9 +37,9 @@ class MBOXImporterTC(CubicWebServerTC):
def test_maildir_format(self):
mi = Importer(cwproxy.CWProxy(self.config['base-url'], auth=cwproxy.SignedRequestAuth(self.token_id, self.secret)))
maildirpath = self.datapath('maildir')
newpath = os.path.join(maildirpath, 'new')
if not os.path.exists(newpath):
os.mkdir(newpath)
newpath = join(maildirpath, 'new')
if not exists(newpath):
mkdir(newpath)
mi.import_maildir(maildirpath)
with self.admin_access.client_cnx() as cnx:
self._test_base(cnx)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment