Add auto-updater
This commit is contained in:
parent
c4152fbce8
commit
4d2f711c9a
|
@ -1,5 +1,5 @@
|
|||
*.pyc
|
||||
validate_email/lib
|
||||
validate_email/data
|
||||
build
|
||||
dist
|
||||
MANIFEST
|
||||
|
|
|
@ -4,6 +4,7 @@ include README.rst
|
|||
include CHANGELOG.txt
|
||||
recursive-include validate_email *
|
||||
prune tests
|
||||
prune validate_email/data
|
||||
recursive-exclude tests *
|
||||
recursive-exclude * __pycache__
|
||||
recursive-exclude * *.pyc
|
||||
|
|
24
setup.py
24
setup.py
|
@ -1,9 +1,22 @@
|
|||
from setuptools import find_packages, setup
|
||||
from setuptools.command.build_py import build_py
|
||||
from setuptools.command.develop import develop
|
||||
from setuptools.command.install import install
|
||||
|
||||
|
||||
class PostBuildPyCommand(build_py):
|
||||
'Post-installation for build_py'
|
||||
class PostInstallCommand(install):
|
||||
'Post-installation command.'
|
||||
|
||||
def run(self):
|
||||
if self.dry_run:
|
||||
return super().run()
|
||||
from validate_email.updater import BlacklistUpdater
|
||||
blacklist_updater = BlacklistUpdater()
|
||||
blacklist_updater.process(force=True)
|
||||
super().run()
|
||||
|
||||
|
||||
class PostDevelopCommand(develop):
|
||||
'Post-installation command.'
|
||||
|
||||
def run(self):
|
||||
if self.dry_run:
|
||||
|
@ -21,11 +34,12 @@ setup(
|
|||
install_requires=['dnspython>=1.16.0', 'idna>=2.8'],
|
||||
author='László Károlyi',
|
||||
author_email='laszlo@karolyi.hu',
|
||||
description='Email validator with regex and SMTP checking.',
|
||||
description=(
|
||||
'Email validator with regex, blacklisted domains and SMTP checking.'),
|
||||
long_description=open('README.rst').read(),
|
||||
long_description_content_type='text/x-rst',
|
||||
keywords='email validation verification mx verify',
|
||||
url='http://github.com/karolyi/py3-validate-email',
|
||||
cmdclass=dict(build_py=PostBuildPyCommand),
|
||||
cmdclass=dict(install=PostInstallCommand, develop=PostDevelopCommand),
|
||||
license='LGPL',
|
||||
)
|
||||
|
|
|
@ -1,44 +1,18 @@
|
|||
from os import makedirs
|
||||
from os.path import dirname, join
|
||||
from unittest.case import TestCase
|
||||
from urllib.request import urlopen
|
||||
|
||||
from validate_email import validate_email
|
||||
from validate_email.domainlist_check import domainlist_check
|
||||
|
||||
BLACKLIST_URL = (
|
||||
'https://raw.githubusercontent.com/martenson/disposable-email-domains/'
|
||||
'master/disposable_email_blocklist.conf')
|
||||
|
||||
|
||||
class DlBlacklist(object):
|
||||
'Emulating downloading of blacklists on post-build command.'
|
||||
|
||||
def __init__(self):
|
||||
from validate_email import domainlist_check
|
||||
self.build_lib = dirname(dirname(domainlist_check.__file__))
|
||||
|
||||
def mkpath(self, name: str):
|
||||
'Emulate mkpath.'
|
||||
makedirs(name=name, exist_ok=True)
|
||||
|
||||
def run(self):
|
||||
'Deploy function identical to the one in setup.py.'
|
||||
with urlopen(url=BLACKLIST_URL) as fd:
|
||||
content = fd.read().decode('utf-8')
|
||||
target_dir = join(self.build_lib, 'validate_email/lib')
|
||||
self.mkpath(name=target_dir)
|
||||
with open(join(target_dir, 'blacklist.txt'), 'w') as fd:
|
||||
fd.write(content)
|
||||
from validate_email.domainlist_check import BlacklistUpdater, domainlist_check
|
||||
|
||||
|
||||
class BlacklistCheckTestCase(TestCase):
|
||||
'Testing if the included blacklist filtering works.'
|
||||
|
||||
def setUpClass():
|
||||
blacklist_updater = BlacklistUpdater()
|
||||
blacklist_updater.process()
|
||||
|
||||
def test_blacklist_positive(self):
|
||||
'Disallows blacklist item: mailinator.com.'
|
||||
dl = DlBlacklist()
|
||||
dl.run()
|
||||
domainlist_check._load_builtin_blacklist()
|
||||
self.assertFalse(expr=domainlist_check(
|
||||
user_part='pa2', domain_part='mailinator.com'))
|
||||
|
|
|
@ -10,7 +10,7 @@ from urllib.request import Request, urlopen
|
|||
BLACKLIST_URL = (
|
||||
'https://raw.githubusercontent.com/martenson/disposable-email-domains/'
|
||||
'master/disposable_email_blocklist.conf')
|
||||
LIB_PATH_DEFAULT = Path(__file__).resolve().parent.joinpath('lib')
|
||||
LIB_PATH_DEFAULT = Path(__file__).resolve().parent.joinpath('data')
|
||||
BLACKLIST_FILE_PATH = LIB_PATH_DEFAULT.joinpath('blacklist.txt')
|
||||
|
||||
|
||||
|
@ -77,7 +77,6 @@ class BlacklistUpdater(object):
|
|||
self._write_new_file(response=response)
|
||||
except HTTPError as exc:
|
||||
if exc.code == 304:
|
||||
print('not modified')
|
||||
# Not modified, update date on the etag file
|
||||
BLACKLIST_FILE_PATH.touch()
|
||||
|
||||
|
|
Loading…
Reference in New Issue