Mercurial > public > weighmail
changeset 12:b63cce680bd3
First attempt at a setup.py for distribution.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 20 May 2012 16:39:55 -0500 |
parents | 330b4c283a09 |
children | 7d1ca1fc2f01 |
files | CHANGES.txt COPYING LICENSE.txt MANIFEST.in README.rst README.txt setup.py weighmail/__init__.py weighmail/main.py weighmail/observers/console.py |
diffstat | 10 files changed, 235 insertions(+), 178 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CHANGES.txt Sun May 20 16:39:55 2012 -0500 @@ -0,0 +1,1 @@ +v0.1.0 - May 20, 2012 - Initial release.
--- a/COPYING Sun May 20 13:16:24 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -Copyright (c) 2012, Brian Neal -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * 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. - * Neither the name of the project 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.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE.txt Sun May 20 16:39:55 2012 -0500 @@ -0,0 +1,24 @@ +Copyright (c) 2012, Brian Neal +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * 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. + * Neither the name of the project 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.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MANIFEST.in Sun May 20 16:39:55 2012 -0500 @@ -0,0 +1,2 @@ +include *.txt +include *.ini
--- a/README.rst Sun May 20 13:16:24 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,149 +0,0 @@ -========= -weighmail -========= -An application to label your Gmail messages according to size -------------------------------------------------------------- - -:Author: Brian Neal <bgneal@gmail.com> -:Version: 0.1.0 -:Date: May 19, 2012 -:Home Page: https://bitbucket.org/bgneal/weighmail/ -:Download: TODO -:License: New BSD License (see COPYING) -:Support: https://bitbucket.org/bgneal/weighmail/issues - - -Overview --------- - -``weighmail`` is a program that analyzes your Gmail and applies labels to your -messages according to their size. This is useful if you are close to reaching -your quota as it allows you to quickly identify large messages. You have -complete control over the rules used to create the labels. - - -Installation ------------- - -``weighmail`` can be installed using Pip_:: - - $ pip install weighmail # TODO: get up on PyPI - -Alternatively you can download a tarball and install with:: - - $ python setup.py install - -``weighmail`` depends on the IMAPClient_ library. This library is automatically -installed if you use Pip_. - -Gmail Notes ------------ - -In case it isn't clear, ``weighmail`` works with Gmail_. You must have a Gmail -account with `IMAP support turned on`_. Please go into your settings and verify -IMAP support is turned on before proceeding. - -If you are using `two-step verification`_ on your Gmail account (**and you -really should be**), you `need to generate an application specific password`_ -for ``weighmail`` to use. In this case you will use an application specific -password instead of your normal password when running ``weighmail``. - - -Usage ------ - -``weighmail`` can accept options from a configuration file and/or the -command-line. Command-line arguments always take precedence over options found -in the configuration file. - -Command-Line Arguments -~~~~~~~~~~~~~~~~~~~~~~ - -``weighmail`` takes a fair number of arguments on the command-line. Most of -these can be omitted however, as they all have sensible defaults. In fact, the -simplest way to run ``weighmail`` is as follows:: - - $ weighmail --labels big:1MB-5MB huge:5MB-10MB enormous:10MB- - -This example demonstrates: - -* A *big* label will be applied to messages between 1 and 5 Megabytes -* A *huge* label will be applied to messages between 5 and 10 Megabytes -* An *enormous* label will be applied to messages 10 MB and bigger -* Since no ``user`` or ``password`` options were supplied on the command-line, - ``weighmail`` will interactively prompt for them. Neither will be echoed out - for privacy reasons. - -To see a list of all command-line options:: - - $ weighmail --help - -Some notes on the options follows. - -* The ``--config`` option is used to specify a configuration file that - ``weighmail`` will read for options. Any options supplied on the command-line - will override any options from this file. In particular, if you specify any - label rules on the command-line, all label rules in the configuration file - will be ignored. -* The ``--folder`` option can be used to specify which Gmail label to search for - messages. This defaults to your *All Mail* label. -* The ``--user`` and ``--password`` options are used to specify which Gmail - account to log into. If these are not supplied, and also omitted from a config - file (or if no config file is being used), ``weighmail`` will prompt you for - these options. -* The ``--labels`` argument is how you specify the rules for labeling your - messages. See the sub-section below for more detail on this syntax. -* The ``--host``, ``--port``, and ``--nossl`` arguments are for advanced use - only, and may in fact not work. The defaults should work for most people, and - will connect you to ``imap.gmail.com`` port 993 using SSL. - -The --labels argument syntax -++++++++++++++++++++++++++++ - -To specify label rules on the command-line, use the following syntax:: - - $ weighmail --labels name:min-max [name:min-max] ... - -Where: - -* *name* is the name of the label. Note that Gmail labels cannot have spaces in - them. -* *min* and *max* specify the message size range in bytes. Either one, but not - both, may be omitted (but the dash must remain). You may use the suffixes - ``KB``, ``MB``, or ``GB`` to indicate kilobytes, Megabytes, or Gigabytes, - respectively. - -Another example:: - - $ weighmail --labels normal:-2MB big:2MB-7MB huge:7MB- - -In all these examples the label ranges do not overlap. This does not have to be -the case; overlapping ranges may be defined if desired. - - -Configuration File -~~~~~~~~~~~~~~~~~~ - -If you specify the ``--config=filename`` option on the command-line, -``weighmail`` will parse this file for options. Please see the included -`sample-weighmail.ini` file for the syntax and option descriptions. - -Again, note that command-line arguments take precedence over options found in -the configuration file. If you specify *any* label rules on the command-line, -*all* label rules in the configuration file are ignored. - - -Thanks -~~~~~~ - -A big thank-you to Menno Smits, the author of the IMAPClient_ library. This -application would have been considerably more complicated if the awesome -IMAPClient library did not exist. - - -.. _Pip: http://pypi.python.org/pypi/pip -.. _Gmail: http://mail.google.com/ -.. _IMAP support turned on: http://support.google.com/mail/bin/answer.py?hl=en&answer=77695 -.. _two-step verification: http://support.google.com/accounts/bin/answer.py?hl=en&answer=180744 -.. _need to generate an application specific password: http://support.google.com/accounts/bin/answer.py?hl=en&answer=185833&topic=1056283&ctx=topic -.. _IMAPClient: http://pypi.python.org/pypi/IMAPClient/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Sun May 20 16:39:55 2012 -0500 @@ -0,0 +1,149 @@ +========= +weighmail +========= +An application to label your Gmail messages according to size +------------------------------------------------------------- + +:Author: Brian Neal <bgneal@gmail.com> +:Version: 0.1.0 +:Date: May 20, 2012 +:Home Page: https://bitbucket.org/bgneal/weighmail/ +:Download: TODO +:License: New BSD License (see LICENSE.txt) +:Support: https://bitbucket.org/bgneal/weighmail/issues + + +Overview +-------- + +``weighmail`` is a program that analyzes your Gmail and applies labels to your +messages according to their size. This is useful if you are close to reaching +your quota as it allows you to quickly identify large messages. You have +complete control over the rules used to create the labels. + + +Installation +------------ + +``weighmail`` can be installed using Pip_:: + + $ pip install weighmail # TODO: get up on PyPI + +Alternatively you can download a tarball and install with:: + + $ python setup.py install + +``weighmail`` depends on the IMAPClient_ library. This library is automatically +installed if you use Pip_. + +Gmail Notes +----------- + +In case it isn't clear, ``weighmail`` works with Gmail_. You must have a Gmail +account with `IMAP support turned on`_. Please go into your settings and verify +IMAP support is turned on before proceeding. + +If you are using `two-step verification`_ on your Gmail account (**and you +really should be**), you `need to generate an application specific password`_ +for ``weighmail`` to use. In this case you will use an application specific +password instead of your normal password when running ``weighmail``. + + +Usage +----- + +``weighmail`` can accept options from a configuration file and/or the +command-line. Command-line arguments always take precedence over options found +in the configuration file. + +Command-Line Arguments +~~~~~~~~~~~~~~~~~~~~~~ + +``weighmail`` takes a fair number of arguments on the command-line. Most of +these can be omitted however, as they all have sensible defaults. In fact, the +simplest way to run ``weighmail`` is as follows:: + + $ weighmail --labels big:1MB-5MB huge:5MB-10MB enormous:10MB- + +This example demonstrates: + +* A *big* label will be applied to messages between 1 and 5 Megabytes +* A *huge* label will be applied to messages between 5 and 10 Megabytes +* An *enormous* label will be applied to messages 10 MB and bigger +* Since no ``user`` or ``password`` options were supplied on the command-line, + ``weighmail`` will interactively prompt for them. Neither will be echoed out + for privacy reasons. + +To see a list of all command-line options:: + + $ weighmail --help + +Some notes on the options follows. + +* The ``--config`` option is used to specify a configuration file that + ``weighmail`` will read for options. Any options supplied on the command-line + will override any options from this file. In particular, if you specify any + label rules on the command-line, all label rules in the configuration file + will be ignored. +* The ``--folder`` option can be used to specify which Gmail label to search for + messages. This defaults to your *All Mail* label. +* The ``--user`` and ``--password`` options are used to specify which Gmail + account to log into. If these are not supplied, and also omitted from a config + file (or if no config file is being used), ``weighmail`` will prompt you for + these options. +* The ``--labels`` argument is how you specify the rules for labeling your + messages. See the sub-section below for more detail on this syntax. +* The ``--host``, ``--port``, and ``--nossl`` arguments are for advanced use + only, and may in fact not work. The defaults should work for most people, and + will connect you to ``imap.gmail.com`` port 993 using SSL. + +The --labels argument syntax +++++++++++++++++++++++++++++ + +To specify label rules on the command-line, use the following syntax:: + + $ weighmail --labels name:min-max [name:min-max] ... + +Where: + +* *name* is the name of the label. Note that Gmail labels cannot have spaces in + them. +* *min* and *max* specify the message size range in bytes. Either one, but not + both, may be omitted (but the dash must remain). You may use the suffixes + ``KB``, ``MB``, or ``GB`` to indicate kilobytes, Megabytes, or Gigabytes, + respectively. + +Another example:: + + $ weighmail --labels normal:-2MB big:2MB-7MB huge:7MB- + +In all these examples the label ranges do not overlap. This does not have to be +the case; overlapping ranges may be defined if desired. + + +Configuration File +~~~~~~~~~~~~~~~~~~ + +If you specify the ``--config=filename`` option on the command-line, +``weighmail`` will parse this file for options. Please see the included +`sample-weighmail.ini` file for the syntax and option descriptions. + +Again, note that command-line arguments take precedence over options found in +the configuration file. If you specify *any* label rules on the command-line, +*all* label rules in the configuration file are ignored. + + +Thanks +~~~~~~ + +A big thank-you to Menno Smits, the author of the IMAPClient_ library. This +application would have been considerably more complicated if the awesome +IMAPClient library did not exist. + + +.. _Pip: http://pypi.python.org/pypi/pip +.. _Gmail: http://mail.google.com/ +.. _IMAP support turned on: http://support.google.com/mail/bin/answer.py?hl=en&answer=77695 +.. _two-step verification: http://support.google.com/accounts/bin/answer.py?hl=en&answer=180744 +.. _need to generate an application specific password: http://support.google.com/accounts/bin/answer.py?hl=en&answer=185833&topic=1056283&ctx=topic +.. _IMAPClient: http://pypi.python.org/pypi/IMAPClient/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Sun May 20 16:39:55 2012 -0500 @@ -0,0 +1,41 @@ +"""weighmail - Copyright (C) 2012 by Brian Neal + +Released under the New BSD license, see LICENSE.txt. + +""" +from setuptools import setup, find_packages +from os.path import join, dirname + +import weighmail + +setup( + name='weighmail', + version=weighmail.__version__, + author='Brian Neal', + author_email='bgneal@gmail.com', + packages=find_packages(), + url='https://bitbucket.org/bgneal/weighmail/', + license='BSD', + description='Labels your Gmail messages according to size.', + long_description=open(join(dirname(__file__), 'README.txt')).read(), + entry_points={ + 'console_scripts': ['weighmail = weighmail.main:console_main'], + }, + install_requires=[ + 'IMAPClient >= 0.9', + ], + classifiers = [ + 'Development Status :: 3 - Alpha', + 'Environment :: Console', + 'Intended Audience :: End Users/Desktop', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Natural Language :: English', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Topic :: Internet', + 'Topic :: Utilities', + 'Topic :: Communications :: Email', + 'Topic :: Communications :: Email :: Post-Office :: IMAP', + ], +)
--- a/weighmail/__init__.py Sun May 20 13:16:24 2012 -0500 +++ b/weighmail/__init__.py Sun May 20 16:39:55 2012 -0500 @@ -0,0 +1,8 @@ +"""weighmail - Copyright (C) 2012 by Brian Neal. + +An application to label Gmail messages based on size. + +See the file LICENSE.txt for the license. + +""" +__version__ = '0.1.0'
--- a/weighmail/main.py Sun May 20 13:16:24 2012 -0500 +++ b/weighmail/main.py Sun May 20 16:39:55 2012 -0500 @@ -100,14 +100,15 @@ if no_ssl: opts['ssl'] = False + # Check for label rules + if 'labels' not in opts or not opts['labels']: + raise AppError("Please specify some label definitions") + # If the user or password is not specified, prompt for them now for opt in ('user', 'password'): if opt not in opts or opts[opt] is None: opts[opt] = getpass.getpass(opt + ': ') - if 'labels' not in opts or not opts['labels']: - raise AppError("Please specify some label definitions") - imap_args = opts.copy() del imap_args['folder'] del imap_args['labels'] @@ -119,7 +120,7 @@ client.logout() -if __name__ == '__main__': +def console_main(): try: main() except (IOError, AppError), ex: @@ -128,3 +129,7 @@ sys.stderr.write("IMAP Error: %s\n" % ex) except KeyboardInterrupt: sys.stderr.write('Interrupted\n') + + +if __name__ == '__main__': + console_main()
--- a/weighmail/observers/console.py Sun May 20 13:16:24 2012 -0500 +++ b/weighmail/observers/console.py Sun May 20 16:39:55 2012 -0500 @@ -1,6 +1,6 @@ import datetime -from observers import BaseObserver +from . import BaseObserver class ConsoleObserver(BaseObserver): """Console observer class; outputs status to the console."""