diff --git a/.gitignore b/.gitignore index b0918a0..ec9de94 100644 --- a/.gitignore +++ b/.gitignore @@ -49,7 +49,7 @@ build/config/buildinfo.properties env # Packages -*.egg +*.egg[s] *.egg-info dist build diff --git a/AUTHORS.txt b/AUTHORS.txt new file mode 100644 index 0000000..707dd16 --- /dev/null +++ b/AUTHORS.txt @@ -0,0 +1,3 @@ +Mauro De Giorgi (mdgart) +Julian Perelli (jperelli) +Peter Bittner (bittner) diff --git a/CHANGES.txt b/CHANGES.txt index 9b14cc6..de134cb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,4 +6,6 @@ v0.0.5, 12/05/2012 -- Django settings eliminated v0.0.6, 12/05/2012 -- Nginx default error log path fixed v0.0.7, 12/10/2012 -- Documentation bug fix v0.0.8, 01/16/2013 -- README.md addded to manifest -v0.0.9, 02/18/2013 -- Patch for invalid Nginx errors \ No newline at end of file +v0.0.9, 02/18/2013 -- Patch for invalid Nginx errors +v1.0.0, ??/??/???? -- (non-versioned release) +v1.1.0, 06/07/2016 -- Add static code analysis (flake8, pylint) diff --git a/LICENSE.txt b/LICENSE.txt index e69de29..4c17262 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -0,0 +1,12 @@ +Copyright (c) 2012-2016 Mauro De Giorgi (mdgart) and individual contributors. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. Neither the name of the Sentry nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/MANIFEST.in b/MANIFEST.in index d779771..443aedf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ include *.txt -include *.md +include *.rst recursive-include docs *.txt recursive-include sentrylogs/conf *.py prune sentrylogs/env diff --git a/README.md b/README.rst similarity index 55% rename from README.md rename to README.rst index 149be88..5d26e72 100644 --- a/README.md +++ b/README.rst @@ -2,9 +2,9 @@ Sentry Logs =========== -Sentry Logs allows you to send Logs to Sentry, only Nginx error log is currently supported, -but I'm planning to extend the library to support more logs file. - +Sentry Logs allows you to send Logs to Sentry, only Nginx error log is +currently supported, but extending the library to support more log files +is planned. How it works ============ @@ -17,10 +17,9 @@ or:: easy_install sentrylogs -This will install the module and you will have a new command line available:: - - sentrylogs -h +This will install the module and will provide a new console command:: + $ sentrylogs -h usage: sentrylogs [-h] [--follow FOLLOW] [--sentrydsn SENTRYDSN] [--daemonize] [--nginxerrorpath NGINXERRORPATH] @@ -37,24 +36,19 @@ This will install the module and you will have a new command line available:: --nginxerrorpath NGINXERRORPATH, -n NGINXERRORPATH Nginx error log path +You must provide a Sentry DSN to make it work; you have 2 possibilities: -you must provide a Sentry DSN to make it works; at this moment you have 2 possibilities: - -set up an environment variable: - -$ export SENTRY_DSN="protocol://public:secret@example.com/#" -$ sentrylogs - -or use the --sentrydsn argument: - -$ sentrylogs --sentrydsn "protocol://public:secret@example.com/#" - -By defauld it will seach for nginx log at /var/log/nginx/error.log, but you can change it using --nginxerrorpath - -If you use --daemonize the command will daemonize itself and will run in background. - +Provide an environment variable:: + $ export SENTRY_DSN="protocol://public:secret@example.com/#" + $ sentrylogs +or use the ``--sentrydsn`` command line argument:: + $ sentrylogs --sentrydsn "protocol://public:secret@example.com/#" +By default *sentrylogs* will assume the nginx log at ``/var/log/nginx/error.log``, +but you can change this using the ``--nginxerrorpath`` argument. +If you use ``--daemonize`` the command will daemonize itself and run in +background. diff --git a/contributors.txt b/contributors.txt deleted file mode 100644 index 841ee5d..0000000 --- a/contributors.txt +++ /dev/null @@ -1,2 +0,0 @@ -Mauro De Giorgi (mdgart) -Julian Perelli (jperelli) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ae5b3d6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +raven>=2.0.10 +tailer>=0.3 diff --git a/sentrylogs/__init__.py b/sentrylogs/__init__.py index 8b13789..2b58be7 100644 --- a/sentrylogs/__init__.py +++ b/sentrylogs/__init__.py @@ -1 +1,8 @@ - +""" +Send logs to Django Sentry. +""" +__author__ = 'Mauro De Giorgi' +__author_email__ = 'mauro.degiorgi@gmail.com' +__license__ = 'BSD' +__url__ = 'https://github.com/mdgart/sentrylogs' +__version__ = '1.1.0.dev' diff --git a/setup.py b/setup.py index ff0775d..b2796be 100644 --- a/setup.py +++ b/setup.py @@ -1,18 +1,103 @@ +from glob import glob from setuptools import setup +from setuptools.command.test import test as TestCommand # noqa N812 +from shlex import split +from shutil import rmtree +from os import remove +from os.path import abspath, dirname, join + +import sentrylogs as package + + +class Tox(TestCommand): + user_options = [('tox-args=', 'a', "Arguments to pass to tox")] + + def initialize_options(self): + TestCommand.initialize_options(self) + self.tox_args = None + + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + + def run_tests(self): + from tox import cmdline + args = self.tox_args + if args: + args = split(self.tox_args) + errno = cmdline(args=args) + exit(errno) + + +class Clean(TestCommand): + def run(self): + delete_in_root = [ + 'build', + 'dist', + '.eggs', + '*.egg-info', + '.tox', + ] + delete_everywhere = [ + '__pycache__', + '*.pyc', + ] + for candidate in delete_in_root: + rmtree_glob(candidate) + for visible_dir in glob('[A-Za-z0-9]*'): + for candidate in delete_everywhere: + rmtree_glob(join(visible_dir, candidate)) + rmtree_glob(join(visible_dir, '*', candidate)) + rmtree_glob(join(visible_dir, '*', '*', candidate)) + + +def rmtree_glob(file_glob): + for fobj in glob(file_glob): + try: + rmtree(fobj) + print('%s/ removed ...' % fobj) + except OSError: + try: + remove(fobj) + print('%s removed ...' % fobj) + except OSError as err: + print(err) + + +def read_file(filename): + with open(join(abspath(dirname(__file__)), filename)) as f: + return f.read() + setup( name='SentryLogs', - version='0.0.9', - author='Mauro De Giorgi', - author_email='mauro.degiorgi@gmail.com', - scripts=['bin/sentrylogs',], + version=package.__version__, + author=package.__author__, + author_email=package.__author_email__, + classifiers=[ + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + ], + description=package.__doc__.strip(), + long_description=read_file('README.rst'), + license=package.__license__, + url=package.__url__, + install_requires=read_file('requirements.txt'), + scripts=['bin/sentrylogs'], packages=['sentrylogs', 'sentrylogs.conf', 'sentrylogs.parsers'], - url='http://pypi.python.org/pypi/SentryLogs/', - license='LICENSE.txt', - description='Send logs to Django Sentry.', - long_description=open('README.md').read(), - install_requires=[ - "raven >= 2.0.10", - "tailer >= 0.3", - ], -) \ No newline at end of file + test_suite='tests', + tests_require=['tox'], + cmdclass={ + 'clean': Clean, + 'test': Tox, + }, +) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..917e7bd --- /dev/null +++ b/tox.ini @@ -0,0 +1,32 @@ +[flake8] +max-line-length = 90 +exclude = build,dist,reports,*.egg-info + +[pylint] +;disable = invalid-name,missing-docstring +;ignore = migrations +;ignore-docstrings = yes +output-format = colorized +reports = no + +[tox] +envlist = + flake8 + pylint +; py{26,27} +; py{32,33,34,35} + +[testenv] +basepython = python3.4 +;deps = pytest +commands = + python setup.py -q install + py.test + +[testenv:flake8] +deps = flake8 +commands = flake8 + +[testenv:pylint] +deps = pylint +commands = pylint --rcfile=tox.ini sentrylogs