├── requirements.txt ├── MANIFEST.in ├── .coveragerc ├── .editorconfig ├── setup.py ├── .travis.yml ├── .gitignore ├── CHANGES.rst ├── README.rst ├── Makefile ├── tests.py ├── vanity.py └── LICENSE.txt /requirements.txt: -------------------------------------------------------------------------------- 1 | -e . 2 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include *.py *.rst *.txt Makefile 2 | recursive-include docs *.txt 3 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | # .coveragerc to control coverage.py 2 | 3 | [report] 4 | # Regexes for lines to exclude from consideration 5 | exclude_lines = 6 | # Have to re-enable the standard pragma: 7 | pragma: no cover 8 | 9 | # Don't complain if non-runnable code isn't run: 10 | if 0: 11 | if __name__ == .__main__.: 12 | # Don't complain about debug code 13 | if DEBUG: 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Top-most EditorConfig file 2 | root = true 3 | 4 | [*] 5 | # Unix-style newlines with a newline ending every file 6 | end_of_line = lf 7 | insert_final_newline = true 8 | charset = utf-8 9 | 10 | # Four-space indentation 11 | indent_size = 4 12 | indent_style = space 13 | 14 | trim_trailing_whitespace = true 15 | 16 | [*.yml] 17 | # Two-space indentation 18 | indent_size = 2 19 | indent_style = space 20 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | import os 3 | 4 | VERSION = '2.2.2' 5 | 6 | setup(author='Alex Clark', 7 | author_email='aclark@aclark.net', 8 | classifiers=[ 9 | 'Programming Language :: Python :: 2', 10 | 'Programming Language :: Python :: 2.7', 11 | 'Programming Language :: Python :: 3', 12 | 'Programming Language :: Python :: 3.3', 13 | 'Programming Language :: Python :: 3.4', 14 | 'Programming Language :: Python :: 3.5', 15 | 'Programming Language :: Python :: 3.6', 16 | ], 17 | description='Get package download statistics from PyPI', 18 | entry_points={ 19 | 'console_scripts': 'vanity=vanity:vanity', 20 | }, 21 | include_package_data=True, 22 | install_requires=['requests'], 23 | keywords='analytics python package index statistics', 24 | license='GPL', 25 | long_description=(open('README.rst').read() + '\n' + open(os.path.join( 26 | 'CHANGES.rst')).read()), 27 | name='vanity', 28 | py_modules=[ 29 | 'vanity', 30 | ], 31 | test_suite='tests.TestSuite', 32 | url='https://github.com/aclark4life/vanity', 33 | version=VERSION, 34 | zip_safe=True, ) 35 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: 4 | - pypy 5 | - pypy3 6 | - 2.7 7 | - 2.7_with_system_site_packages 8 | - 3.4 9 | - 3.5 10 | - 3.6 11 | 12 | install: 13 | - python setup.py install 14 | - pip install coverage 15 | - coverage erase 16 | 17 | script: 18 | # Simple tests: just run some example commands with options 19 | - coverage run --append --include=vanity.py vanity.py -h 20 | - coverage run --append --include=vanity.py vanity.py --help 21 | - coverage run --append --include=vanity.py vanity.py vanity pillow 22 | - coverage run --append --include=vanity.py vanity.py vanity pillow -q 23 | - coverage run --append --include=vanity.py vanity.py --quiet vanity pillow 24 | - coverage run --append --include=vanity.py vanity.py pil 25 | - coverage run --append --include=vanity.py vanity.py vanity==0.0.0 26 | - coverage run --append --include=vanity.py vanity.py vanity==1.0 27 | - coverage run --append --include=vanity.py vanity.py pillow --pattern "Pillow-3.0.0.*win32.*py3.2|Pillow-3.0.0.*cp32.*win32" 28 | # run unit tests 29 | - coverage run --append --include=vanity.py tests.py 30 | 31 | after_success: 32 | - coverage report 33 | - travis_retry pip install coveralls 34 | - coveralls 35 | 36 | - travis_retry pip install pycodestyle pyflakes 37 | - pyflakes *.py | tee >(wc -l) 38 | - pycodestyle --statistics --count *.py 39 | 40 | matrix: 41 | fast_finish: true 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | .venv/ 83 | venv/ 84 | ENV/ 85 | 86 | # Spyder project settings 87 | .spyderproject 88 | 89 | # Rope project settings 90 | .ropeproject 91 | -------------------------------------------------------------------------------- /CHANGES.rst: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | 2.2.2 (2016-08-21) 5 | ------------------ 6 | 7 | - Fix Python 3 JSON issue 8 | [mattjegan] 9 | 10 | 2.2.1 (2016-04-27) 11 | ------------------ 12 | 13 | - Add message *** Note: PyPI stats are broken again; we're now waiting for warehouse. https://github.com/aclark4life/vanity/issues/22 *** 14 | 15 | 2.2.0 (2016-01-06) 16 | ------------------ 17 | 18 | - Add ``--pattern`` option 19 | [hugovk] 20 | 21 | 2.1.0 (2015-07-03) 22 | ------------------ 23 | 24 | - Use PyPI JSON API via ``--json`` 25 | - Replace print with logging 26 | 27 | 2.0.4 (2014-09-02) 28 | ------------------ 29 | 30 | - Query /pypi/ instead of /simple/, fixes https://github.com/aclark4life/vanity/issues/12 31 | 32 | 2.0.3 (2013-05-27) 33 | ------------------ 34 | 35 | - New life: http://mail.python.org/pipermail/distutils-sig/2013-June/021344.html 36 | 37 | 2.0.2 (2013-05-27) 38 | ------------------ 39 | 40 | - Fix typo 41 | 42 | 2.0.1 (2013-05-27) 43 | ------------------ 44 | 45 | - End of life: http://mail.python.org/pipermail/distutils-sig/2013-May/020855.html 46 | 47 | 2.0.0 (2013-05-26) 48 | ------------------ 49 | 50 | - Revert removal of ``--quiet`` option 51 | - Support multi-package entry e.g. ``$ vanity setuptools distribute`` 52 | 53 | 1.2.5 (2013-03-17) 54 | ------------------ 55 | 56 | - Switch to argparse 57 | - Support query by version spec e.g. ``$ vanity pillow==2.0.0`` 58 | - Remove ``--quiet`` option 59 | - Officially add Python 3 support 60 | 61 | 1.2.4 (2013-02-19) 62 | ------------------ 63 | 64 | - Query PyPI via https 65 | - Return usage statement when no args passed 66 | 67 | 1.2.3 (2012-08-08) 68 | ------------------ 69 | 70 | - Use optparse for option and argument parsing 71 | [JNRowe] 72 | - Don't fail when the en_US locale isn't available 73 | [JNRowe] 74 | - Python 3 compatibility 75 | [JNRowe] 76 | 77 | 1.2.2 (2012-07-31) 78 | ------------------ 79 | 80 | - Remove blessings integration which breaks on Windows 81 | 82 | 1.2.1 (2012-02-15) 83 | ------------------ 84 | 85 | - Make verbose the default 86 | - Add blessings support to make output pretty 87 | - install_requires requests for future refactor 88 | - Enforce available command line options better 89 | 90 | 1.2.0 (2012-01-30) 91 | ------------------ 92 | 93 | - Add verbose option to display file name, upload date, and download count per release 94 | - Add locale to format downloads e.g. ``700,232 times`` instead of ``700232 times`` 95 | 96 | 1.1.2 (2011-10-28) 97 | ------------------ 98 | 99 | - Fix regression: Re-fix download counts 100 | [JNRowe] 101 | 102 | 1.1.1 (2011-10-27) 103 | ------------------ 104 | 105 | - Refactor: create ``downloads_total`` function to make external use simpler 106 | [kennethreitz] 107 | 108 | 1.1.0 (2011-10-25) 109 | ------------------ 110 | 111 | - Bug fixes: support for case insensitive project names and support for counting all release files (e.g. binaries in addition to sdist) and correct number of release files 112 | [JNRowe] 113 | 114 | 1.0 (04-13-2011) 115 | ---------------- 116 | 117 | - Initial release based on code from `Products.PloneSoftwareCenter`_ by `David Glick`_ 118 | 119 | .. _`Products.PloneSoftwareCenter`: https://pypi.python.org/pypi/Products.PloneSoftwareCenter 120 | .. _`David Glick`: http://glicksoftware.com 121 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Vanity 2 | ====== 3 | 4 | Get package download statistics from PyPI [1]_ 5 | 6 | .. image:: https://travis-ci.org/aclark4life/vanity.svg 7 | :target: https://travis-ci.org/aclark4life/vanity 8 | :alt: Travis CI build status 9 | 10 | .. image:: https://img.shields.io/pypi/v/vanity.svg 11 | :target: https://pypi.python.org/pypi/vanity/ 12 | :alt: PyPI version 13 | 14 | .. image:: https://img.shields.io/coveralls/aclark4life/vanity/master.svg 15 | :target: https://coveralls.io/r/aclark4life/vanity?branch=master 16 | :alt: Code coverage 17 | 18 | .. image:: https://landscape.io/github/aclark4life/vanity/master/landscape.png 19 | :target: https://landscape.io/github/aclark4life/vanity/master 20 | :alt: Code health 21 | 22 | Installation 23 | ------------ 24 | 25 | :: 26 | 27 | $ pip install vanity 28 | 29 | Usage 30 | ----- 31 | 32 | Enter package name:: 33 | 34 | $ vanity django 35 | Django-1.1.3.tar.gz 2010-12-23 4,938 36 | Django-1.1.4.tar.gz 2011-02-09 10,259 37 | Django-1.2.tar.gz 2010-05-17 24,011 38 | Django-1.2.1.tar.gz 2010-05-24 71,479 39 | Django-1.2.2.tar.gz 2010-09-09 4,388 40 | Django-1.2.3.tar.gz 2010-09-11 82,629 41 | Django-1.2.4.tar.gz 2010-12-23 66,223 42 | Django-1.2.5.tar.gz 2011-02-09 82,325 43 | Django-1.2.6.tar.gz 2011-09-10 2,559 44 | Django-1.2.7.tar.gz 2011-09-11 31,833 45 | Django-1.3.tar.gz 2011-03-23 363,202 46 | Django-1.3.1.tar.gz 2011-09-10 585,745 47 | Django-1.3.2.tar.gz 2012-07-30 7,649 48 | Django-1.3.3.tar.gz 2012-08-01 31,375 49 | Django-1.3.4.tar.gz 2013-03-05 1,974 50 | Django-1.3.5.tar.gz 2012-12-10 16,880 51 | Django-1.3.6.tar.gz 2013-02-19 2,292 52 | Django-1.3.7.tar.gz 2013-02-20 14,756 53 | Django-1.4.tar.gz 2012-03-23 437,635 54 | Django-1.4.1.tar.gz 2012-07-30 328,418 55 | Django-1.4.2.tar.gz 2012-10-17 326,088 56 | Django-1.4.3.tar.gz 2012-12-10 280,915 57 | Django-1.4.4.tar.gz 2013-02-19 12,453 58 | Django-1.4.5.tar.gz 2013-02-20 117,366 59 | Django-1.5.tar.gz 2013-02-26 124,429 60 | Django-1.5.1.tar.gz 2013-03-28 150,413 61 | ---------------------------------------------- 62 | Django has been downloaded 3,182,234 times! 63 | 64 | Enter package name with version:: 65 | 66 | $ vanity pillow==2.0.0 67 | Pillow-2.0.0.zip 2013-03-15 61,022 68 | Pillow-2.0.0.win32-py3.3.exe 2013-03-15 593 69 | Pillow-2.0.0.win32-py3.2.exe 2013-03-15 379 70 | Pillow-2.0.0.win32-py2.7.exe 2013-03-15 703 71 | Pillow-2.0.0.win32-py2.6.exe 2013-03-15 308 72 | Pillow-2.0.0.win-amd64-py3.3.exe 2013-03-15 487 73 | Pillow-2.0.0.win-amd64-py3.2.exe 2013-03-15 328 74 | Pillow-2.0.0.win-amd64-py2.7.exe 2013-03-15 500 75 | Pillow-2.0.0.win-amd64-py2.6.exe 2013-03-15 311 76 | Pillow-2.0.0-py3.3-win32.egg 2013-03-15 421 77 | Pillow-2.0.0-py3.3-win-amd64.egg 2013-03-15 431 78 | Pillow-2.0.0-py3.2-win32.egg 2013-03-15 353 79 | Pillow-2.0.0-py3.2-win-amd64.egg 2013-03-15 357 80 | Pillow-2.0.0-py2.7-win32.egg 2013-03-15 1,160 81 | Pillow-2.0.0-py2.7-win-amd64.egg 2013-03-15 620 82 | Pillow-2.0.0-py2.6-win32.egg 2013-03-15 730 83 | Pillow-2.0.0-py2.6-win-amd64.egg 2013-03-15 395 84 | ----------------------------------------------------------- 85 | Pillow 2.0.0 has been downloaded 69,098 times! 86 | 87 | Enter multiple package names:: 88 | 89 | $ bin/vanity --quiet setuptools distribute 90 | setuptools has been downloaded 34,601,114 times! 91 | distribute has been downloaded 29,661,287 times! 92 | setuptools and distribute have been downloaded 64,262,401 times! 93 | 94 | Enter search pattern:: 95 | 96 | C:\>vanity pillow -p "Pillow-3.0.0.*win32.*py3.2|Pillow-3.0.0.*cp32.*win32" 97 | Pillow-3.0.0.win32-py3.2.exe 2015-10-01 582 98 | Pillow-3.0.0-cp32-none-win32.whl 2015-10-01 591 99 | ----------------------------------------------------------- 100 | Pillow has been downloaded 1173 times! 101 | 102 | .. [1] Based on https://github.com/collective/Products.PloneSoftwareCenter/commit/601558870175e35cfa4d05fb309859e580271a1f 103 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # https://github.com/aclark4life/project-makefile 2 | # 3 | # The MIT License (MIT) 4 | # 5 | # Copyright (c) 2016 Alex Clark 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | .DEFAULT_GOAL=git-commit-auto-push 26 | 27 | APP=app 28 | MESSAGE="Update" 29 | PROJECT=project 30 | PROJECT_EDITOR="Sublime Text" 31 | TMP:=$(shell echo `tmp`) 32 | 33 | commit: git-commit-auto-push 34 | co: git-checkout-branches 35 | db: django-migrate django-su 36 | db-init: django-db-init-postgres 37 | django-start: django-init 38 | fe-init: npm-init npm-install grunt-init grunt-serve 39 | fe: npm-install grunt-serve 40 | freeze: python-pip-freeze 41 | heroku: heroku-push 42 | install: python-virtualenv python-pip-install 43 | lint: python-flake python-yapf python-wc 44 | migrate: django-migrate 45 | push: git-push 46 | package-init: python-package-init 47 | package-lint: python-package-lint 48 | package-test: python-package-test 49 | plone-start: plone-init 50 | python-test: python-package-test 51 | readme-test: python-package-readme-test 52 | release: python-package-release 53 | release-test: python-package-release-test 54 | serve: python-serve 55 | sphinx-start: sphinx-init 56 | static: django-static 57 | test: python-test 58 | vm: vagrant-up 59 | vm-down: vagrant-suspend 60 | 61 | # ABlog 62 | ablog-init: 63 | ablog start 64 | ablog-build: 65 | ablog build 66 | ablog-serve: 67 | ablog serve 68 | 69 | # Django 70 | django-db-init-postgres: 71 | -dropdb $(PROJECT)-$(APP) 72 | -createdb $(PROJECT)-$(APP) 73 | django-db-init-sqlite: 74 | -rm -f $(PROJECT)-$(APP).sqlite3 75 | django-init: 76 | -mkdir -p $(PROJECT)/$(APP) 77 | -django-admin startproject $(PROJECT) . 78 | -django-admin startapp $(APP) $(PROJECT)/$(APP) 79 | django-install: 80 | $(MAKE) python-virtualenv 81 | bin/pip install Django 82 | django-migrate: 83 | python manage.py migrate 84 | django-migrations: 85 | python manage.py makemigrations $(APP) 86 | django-migrations-init: 87 | rm -rf $(PROJECT)/$(APP)/migrations 88 | $(MAKE) django-migrations 89 | django-serve: 90 | python manage.py runserver 91 | django-test: 92 | python manage.py test 93 | django-shell: 94 | python manage.py shell 95 | django-static: 96 | python manage.py collectstatic --noinput 97 | django-su: 98 | python manage.py createsuperuser 99 | 100 | # Git 101 | REMOTE_BRANCHES=`git branch -a |\ 102 | grep remote |\ 103 | grep -v HEAD |\ 104 | grep -v master` 105 | git-checkout-branches: 106 | -for i in $(REMOTE_BRANCHES) ; do \ 107 | git checkout -t $$i ; done 108 | git-commit-auto-push: 109 | git commit -a -m $(MESSAGE) 110 | $(MAKE) git-push 111 | git-commit-edit-push: 112 | git commit -a 113 | $(MAKE) git-push 114 | git-push: 115 | git push 116 | 117 | # Heroku 118 | heroku-debug-on: 119 | heroku config:set DEBUG=1 120 | heroku-debug-off: 121 | heroku config:unset DEBUG 122 | heroku-push: 123 | git push heroku 124 | heroku-shell: 125 | heroku run bash 126 | 127 | # Misc 128 | help: 129 | @echo "\nPlease run \`make\` with one of these targets:\n" 130 | @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F:\ 131 | '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}'\ 132 | | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs | tr ' ' '\n' | awk\ 133 | '{print " - "$$0}' 134 | @echo "\n" 135 | 136 | uname := $(shell uname) 137 | review: 138 | 139 | ifeq ($(uname), Darwin) 140 | @open -a $(PROJECT_EDITOR) `find $(PROJECT) -name \*.py | grep -v __init__.py`\ 141 | `find $(PROJECT) -name \*.html` 142 | else 143 | @echo "Unsupported" 144 | endif 145 | 146 | # Node 147 | npm-init: 148 | npm init 149 | npm-install: 150 | npm install 151 | grunt-init: 152 | npm install grunt 153 | grunt-init Gruntfile 154 | grunt-serve: 155 | grunt serve 156 | 157 | # Plone 158 | plone-heroku: 159 | -@createuser -s plone > /dev/null 2>&1 160 | -@createdb -U plone plone > /dev/null 2>&1 161 | @export PORT=8080 && \ 162 | export USERNAME=admin && \ 163 | export PASSWORD=admin && \ 164 | bin/buildout -c heroku.cfg 165 | plone-init: 166 | plock --force --no-cache --no-virtualenv . 167 | plone-install: 168 | $(MAKE) install 169 | bin/buildout 170 | plone-db-sync: 171 | bin/buildout -c database.cfg 172 | plone-serve: 173 | @echo "Zope about to handle requests here:\n\n\thttp://localhost:8080\n" 174 | @bin/plone fg 175 | 176 | # Python 177 | python-clean-pyc: 178 | find . -name \*.pyc | xargs rm -v 179 | python-flake: 180 | -flake8 *.py 181 | -flake8 $(PROJECT)/*.py 182 | -flake8 $(PROJECT)/$(APP)/*.py 183 | python-package-init: 184 | mkdir -p $(PROJECT)/$(APP) 185 | touch $(PROJECT)/$(APP)/__init__.py 186 | touch $(PROJECT)/__init__.py 187 | python-package-lint: 188 | check-manifest 189 | pyroma . 190 | python-package-readme-test: 191 | rst2html.py README.rst > readme.html; open readme.html 192 | python-package-release: 193 | python setup.py sdist --format=gztar,zip upload 194 | python-package-release-test: 195 | python setup.py sdist --format=gztar,zip upload -r test 196 | python-package-test: 197 | python setup.py test 198 | python-pip-freeze: 199 | bin/pip freeze | sort > $(TMP)/requirements.txt 200 | mv -f $(TMP)/requirements.txt . 201 | python-pip-install: 202 | bin/pip install -r requirements.txt 203 | python-serve: 204 | @echo "\n\tServing HTTP on http://0.0.0.0:8000\n" 205 | python -m SimpleHTTPServer 206 | python-virtualenv: 207 | virtualenv . 208 | python-yapf: 209 | -yapf -i *.py 210 | -yapf -i -e $(PROJECT)/urls.py $(PROJECT)/*.py 211 | -yapf -i $(PROJECT)/$(APP)/*.py 212 | python-wc: 213 | -wc -l *.py 214 | -wc -l $(PROJECT)/*.py 215 | -wc -l $(PROJECT)/$(APP)/*.py 216 | 217 | # Sphinx 218 | sphinx-init: 219 | sphinx-quickstart -q -p "Python Project" -a "Alex Clark" -v 0.0.1 doc 220 | sphinx-serve: 221 | @echo "\nServing HTTP on http://0.0.0.0:8085 ...\n" 222 | pushd _build/html; python -m SimpleHTTPServer 8085; popd 223 | 224 | # Vagrant 225 | vagrant-box-update: 226 | vagrant box update 227 | vagrant-down: 228 | vagrant suspend 229 | vagrant-init: 230 | vagrant destroy 231 | vagrant init ubuntu/trusty64 232 | vagrant up --provider virtualbox 233 | vagrant-up: 234 | vagrant up --provision 235 | -------------------------------------------------------------------------------- /tests.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import mock 3 | import datetime 4 | 5 | import vanity 6 | 7 | 8 | # mocks 9 | def mock_single_release(url): 10 | return {'releases': {'1.0': ''}} 11 | 12 | 13 | def mock_multi_release(url): 14 | return {'releases': {'2.0': '1', '1.0': 'a', '3.1': 'a', '1.5': ''}} 15 | 16 | 17 | def mock_json_data(url): 18 | return {'releases': 19 | {'1.0': [{'filename': 'fake-package', 20 | 'downloads': 1, 21 | 'upload_time': '2016-10-12T03:00:42'}], 22 | '1.9': [{'filename': 'fake-package', 23 | 'downloads': 3, 24 | 'upload_time': '2016-10-13T09:01:00'}], 25 | '1.2': [{'filename': 'fake-package', 26 | 'downloads': 2, 27 | 'upload_time': '2016-10-13T02:10:08'}] 28 | }, 29 | 'info': {'version': '1.0'}} 30 | 31 | 32 | def empty_release_info(package, json): 33 | return iter(()) 34 | 35 | 36 | def single_release_info(package, json): 37 | url = {'filename': 'fake-package', 38 | 'downloads': 1, 39 | 'upload_time': datetime.date(2016, 10, 13)} 40 | data = {'version': '1.0'} 41 | 42 | yield [url], data 43 | 44 | 45 | def two_url_release_info(package, json): 46 | first_url = {'filename': 'fake-package', 47 | 'downloads': 1, 48 | 'upload_time': datetime.date(2016, 10, 13)} 49 | 50 | second_url = {'filename': 'fake-package two', 51 | 'downloads': 2, 52 | 'upload_time': datetime.date(2016, 10, 13)} 53 | 54 | data = {'version': '1.0'} 55 | 56 | yield [first_url, second_url], data 57 | 58 | 59 | def mock_normalize(package): 60 | return package 61 | 62 | 63 | # http://stackoverflow.com/q/21611559 64 | def Any(object_type): 65 | class Any(object_type): 66 | def __eq__(self, other): 67 | return True 68 | return Any() 69 | 70 | 71 | class TestGetJsonParsedData(unittest.TestCase): 72 | """ 73 | A test class for the get_jsonparsed_data method. 74 | """ 75 | 76 | def test_none(self): 77 | self.assertRaises(AttributeError, 78 | vanity.get_jsonparsed_data, 79 | None) 80 | 81 | def test_empty_string(self): 82 | self.assertRaises(ValueError, 83 | vanity.get_jsonparsed_data, 84 | '') 85 | 86 | @mock.patch('vanity.get_json_from_url', side_effect=mock_single_release) 87 | def test_single_release(self, mock_json_func): 88 | expected = {'1.0': ''} 89 | response = vanity.get_jsonparsed_data('fake url') 90 | 91 | mock_json_func.assert_called_with('fake url') 92 | self.assertEqual(response['releases'], expected) 93 | 94 | @mock.patch('vanity.get_json_from_url', side_effect=mock_multi_release) 95 | def test_multi_release_sorts(self, mock_json_func): 96 | expected = {'1.0': 'a', '1.5': '', '2.0': '1', '3.1': 'a'} 97 | response = vanity.get_jsonparsed_data('fake url') 98 | 99 | mock_json_func.assert_called_with('fake url') 100 | self.assertEqual(response['releases'], expected) 101 | 102 | 103 | class TestCountDownloads(unittest.TestCase): 104 | """ 105 | A test class for the count_downloads method. 106 | """ 107 | 108 | mock_logger = mock.Mock() 109 | 110 | def setUp(self): 111 | self.old_logger = vanity.logger 112 | vanity.logger = self.mock_logger 113 | 114 | def tearDown(self): 115 | vanity.logger = self.old_logger 116 | 117 | @mock.patch('vanity.get_release_info', side_effect=empty_release_info) 118 | def test_count_empty(self, get_release_func): 119 | count = vanity.count_downloads(None) 120 | 121 | self.assertEqual(count, 0) 122 | 123 | @mock.patch('vanity.get_release_info', side_effect=single_release_info) 124 | def test_count_single(self, get_release_func): 125 | count = vanity.count_downloads('fake-package') 126 | 127 | self.assertEqual(count, 1) 128 | 129 | @mock.patch('vanity.get_release_info', side_effect=two_url_release_info) 130 | def test_count_multiple(self, get_release_func): 131 | count = vanity.count_downloads('fake-package') 132 | 133 | self.assertEqual(count, 3) 134 | 135 | @mock.patch('vanity.get_json_from_url', side_effect=mock_json_data) 136 | def test_count_json(self, get_json_func): 137 | expected_url = 'https://pypi.python.org/pypi/fake-package/json' 138 | count = vanity.count_downloads('fake-package', 139 | json=True) 140 | 141 | get_json_func.assert_called_with(expected_url) 142 | self.assertEqual(count, 6) 143 | 144 | @mock.patch('vanity.get_release_info', side_effect=single_release_info) 145 | def test_count_version(self, get_release_func): 146 | count = vanity.count_downloads('fake-package', 147 | version='1.1') 148 | 149 | self.assertEqual(count, 0) 150 | 151 | @mock.patch('vanity.get_release_info', side_effect=single_release_info) 152 | def test_bad_pattern(self, get_release_func): 153 | count = vanity.count_downloads('fake-package', 154 | pattern='real') 155 | 156 | self.assertEqual(count, 0) 157 | 158 | @mock.patch('vanity.get_release_info', side_effect=single_release_info) 159 | def test_good_pattern(self, get_release_func): 160 | count = vanity.count_downloads('fake-package', 161 | pattern='[Ff]ake') 162 | 163 | self.assertEqual(count, 1) 164 | 165 | @mock.patch('vanity.get_release_info', side_effect=single_release_info) 166 | def test_verbose_calls_debug(self, get_release_func): 167 | 168 | count = vanity.count_downloads('fake-package') 169 | 170 | self.assertEqual(count, 1) 171 | self.mock_logger.debug.assert_any_call(Any(str)) 172 | 173 | @mock.patch('vanity.get_release_info', side_effect=single_release_info) 174 | def test_not_verbose_no_debug(self, get_release_func): 175 | self.mock_logger = mock.Mock() 176 | 177 | count = vanity.count_downloads('fake-package', 178 | verbose=False) 179 | 180 | self.assertEqual(count, 1) 181 | self.mock_logger.debug.assert_not_called() 182 | 183 | 184 | class TestByTwo(unittest.TestCase): 185 | """ 186 | A test class for the by_two method. 187 | """ 188 | 189 | def test_none(self): 190 | input = iter(()) 191 | 192 | result = {url: data for (url, data) in vanity.by_two(input)} 193 | 194 | self.assertEqual(result, {}) 195 | 196 | def test_pairs_url_and_data(self): 197 | input = iter(['test.com', 'test data', 198 | 'foo.org', 'foo data', 199 | 'bar.net', 'bar data']) 200 | 201 | result = {url: data for (url, data) in vanity.by_two(input)} 202 | 203 | self.assertEqual(result['test.com'], 'test data') 204 | self.assertEqual(result['foo.org'], 'foo data') 205 | self.assertEqual(result['bar.net'], 'bar data') 206 | 207 | def test_odd_input(self): 208 | input = iter(['test.com', 'test data', 209 | 'foo.org', 'foo data', 210 | 'bar.net']) 211 | 212 | result = {url: data for (url, data) in vanity.by_two(input)} 213 | 214 | self.assertEqual(result['test.com'], 'test data') 215 | self.assertEqual(result['foo.org'], 'foo data') 216 | self.assertIsNone(result.get('bar.net')) 217 | 218 | 219 | class TestNormalize(unittest.TestCase): 220 | """ 221 | A test class for the normalize method. 222 | """ 223 | 224 | def test_fake_package(self): 225 | self.assertRaises(ValueError, 226 | vanity.normalize, 227 | "FAKEPACKAGE1@!") 228 | self.assertRaises(ValueError, 229 | vanity.normalize, 230 | "1337INoscopeyou") 231 | 232 | def test_django(self): 233 | normalized = vanity.normalize("dJaNgO") 234 | self.assertEqual(normalized, "Django") 235 | 236 | def test_none(self): 237 | normalized = vanity.normalize(None) 238 | self.assertEqual(normalized, "none") 239 | 240 | def test_flask(self): 241 | normalized = vanity.normalize("fLaSk") 242 | self.assertEqual(normalized, "Flask") 243 | 244 | def test_space_string(self): 245 | normalized = vanity.normalize(" Flask ") 246 | self.assertEqual(normalized, " Flask ") 247 | 248 | def test_empty(self): 249 | normalized = vanity.normalize("") 250 | self.assertEqual(normalized, "") 251 | 252 | 253 | class TestVanity(unittest.TestCase): 254 | """ 255 | A test class for the vanity method. 256 | """ 257 | 258 | mock_logger = mock.Mock() 259 | 260 | def setUp(self): 261 | self.old_logger = vanity.logger 262 | vanity.logger = self.mock_logger 263 | 264 | def tearDown(self): 265 | vanity.logger = self.old_logger 266 | 267 | @mock.patch('vanity.normalize', side_effect=mock_normalize) 268 | @mock.patch('vanity.get_json_from_url', side_effect=mock_json_data) 269 | def test_vanity_count_downloads(self, mock_json_func, mock_norm_func): 270 | # NB: mocks are passed in reverse order 271 | expected_url = 'https://pypi.python.org/pypi/fake-package/json' 272 | 273 | vanity.vanity(packages=['fake-package'], 274 | verbose=True, 275 | json=True, 276 | pattern=None) 277 | 278 | mock_norm_func.assert_called_with('fake-package') 279 | mock_json_func.assert_called_with(expected_url) 280 | self.mock_logger.debug.assert_any_call( 281 | '%s has been downloaded %s times!', 282 | 'fake-package', 283 | '6') 284 | 285 | @mock.patch('vanity.normalize', side_effect=mock_normalize) 286 | @mock.patch('vanity.get_json_from_url', side_effect=mock_json_data) 287 | def test_vanity_version_downloads(self, mock_json_func, mock_norm_func): 288 | # NB: mocks are passed in reverse order 289 | expected_url = 'https://pypi.python.org/pypi/fake-package/json' 290 | 291 | vanity.vanity(packages=['fake-package==1.0'], 292 | verbose=True, 293 | json=True, 294 | pattern=None) 295 | 296 | mock_norm_func.assert_called_with('fake-package') 297 | mock_json_func.assert_called_with(expected_url) 298 | self.mock_logger.debug.assert_any_call( 299 | '%s %s has been downloaded %s times!', 300 | 'fake-package', 301 | '1.0', 302 | '6') 303 | 304 | if __name__ == '__main__': 305 | unittest.main() 306 | -------------------------------------------------------------------------------- /vanity.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright (C) 2011-2016 Alex Clark 4 | # 5 | # This program is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public License 7 | # as published by the Free Software Foundation; either version 2 8 | # of the License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 18 | # USA. 19 | """Get package download statistics from PyPI.""" 20 | 21 | import argparse 22 | import json 23 | import locale 24 | import logging 25 | import re 26 | import time 27 | 28 | # For sorting XML-RPC results 29 | from collections import OrderedDict, deque, namedtuple 30 | 31 | # HTTPS connection for normalize function 32 | try: 33 | from http.client import HTTPSConnection 34 | except ImportError: 35 | from httplib import HTTPSConnection 36 | 37 | # PyPI's XML-RPC methods 38 | # https://wiki.python.org/moin/PyPIXmlRpc 39 | try: 40 | import xmlrpc.client as xmlrpc 41 | except ImportError: # Python 2 42 | import xmlrpclib as xmlrpc 43 | 44 | PYPI_HOST = 'pypi.python.org' 45 | PYPI_URL = 'https://%s/pypi' % PYPI_HOST 46 | PYPI_JSON = '/'.join([PYPI_URL, '%s/json']) 47 | PYPI_XML = xmlrpc.ServerProxy(PYPI_URL) 48 | 49 | # Print numbers with commas 50 | # http://stackoverflow.com/a/1823101 51 | try: 52 | locale.setlocale(locale.LC_ALL, 'en_US') 53 | except locale.Error: 54 | pass 55 | 56 | # Logger 57 | # https://docs.python.org/3/howto/logging.html 58 | logger = logging.getLogger('vanity') 59 | logger.setLevel(logging.DEBUG) 60 | ch = logging.StreamHandler() 61 | ch.setLevel(logging.DEBUG) 62 | formatter = logging.Formatter('%(message)s') 63 | ch.setFormatter(formatter) 64 | logger.addHandler(ch) 65 | 66 | # PyPI JSON 67 | # http://stackoverflow.com/a/28786650 68 | try: 69 | # For Python 3.0 and later 70 | from urllib.request import urlopen 71 | except ImportError: 72 | # Fall back to Python 2's urllib2 73 | from urllib2 import urlopen 74 | 75 | 76 | def by_two(source): 77 | """Accept XMLRPC Multicall generator, and return items in pairs. 78 | 79 | @param source: Result of XMLRPC Multicall 80 | @type source: generator 81 | @r_param out: Items from generator, as namedtuple(url, data) 82 | @r_type out: namedtuple 83 | """ 84 | release_info = namedtuple('release_info', ['urls', 'data']) 85 | it = iter(source) 86 | for urls in it: 87 | yield release_info(urls=urls, data=next(it)) 88 | 89 | 90 | def count_downloads(package, 91 | verbose=True, 92 | version=None, 93 | json=False, 94 | pattern=None): 95 | """Receive package details, retrieve and return download count. 96 | 97 | Call get_release_info() method to make requests to get package details, 98 | check for verbose and json toggles, debug for discrepancies, 99 | maintain a download count counter and return total number of downloads. 100 | 101 | @param package: Name of package to be retrieved. 102 | @type package: str 103 | @param verbose: Verbose Toggle 104 | @type verbose: bool 105 | @param version: Version number of package 106 | @type version: str 107 | @param json: JSON Toggle 108 | @type json: bool 109 | @param pattern: Regex pattern 110 | @type pattern: str 111 | @r_param count: Download count of package on PyPI 112 | @r_type count: int 113 | """ 114 | count = 0 115 | items = [] 116 | for urls, data in get_release_info([package], json=json): 117 | for url in urls: 118 | filename = url['filename'] 119 | if pattern and not re.search(pattern, filename): 120 | continue 121 | downloads = url['downloads'] 122 | downloads = locale.format("%d", downloads, grouping=True) 123 | if not json: 124 | upload_time = url['upload_time'].timetuple() 125 | upload_time = time.strftime('%Y-%m-%d', upload_time) 126 | else: 127 | # Convert 2011-04-14T02:16:55 to 2011-04-14 128 | upload_time = url['upload_time'].split('T')[0] 129 | if version == data['version'] or not version: 130 | item = '%s %s %9s' % (filename, upload_time, downloads) 131 | items.append(item) 132 | count += url['downloads'] 133 | if verbose and items != []: 134 | items.reverse() 135 | # http://stackoverflow.com/questions/873327/\ 136 | # pythons-most-efficient-way-to-choose-longest-string-in-list 137 | longest = len(max(items, key=len)) 138 | for item in items: 139 | logger.debug(item.rjust(longest)) 140 | logger.debug('-' * longest) 141 | return count 142 | 143 | 144 | def get_json_from_url(url): 145 | """ 146 | Returns content of url as json 147 | """ 148 | response = urlopen(url) 149 | return json.loads(response.read().decode('utf-8')) 150 | 151 | 152 | # http://stackoverflow.com/a/28786650 153 | def get_jsonparsed_data(url): 154 | """Receive content of 'url', parse it as JSON, return the object. 155 | 156 | @param url: URL of package's JSON data 157 | @type url: str 158 | @r_param response: JSON data from the URL 159 | @r_type response: dict 160 | """ 161 | response = get_json_from_url(url) 162 | 163 | sorted_releases = OrderedDict() 164 | for release in sorted(response['releases'].keys())[::-1]: 165 | sorted_releases[release] = response['releases'][release] 166 | response['releases'] = sorted_releases 167 | return response 168 | 169 | 170 | def normalize(name): 171 | """Normalize and return correct package name, if specified incorrectly. 172 | 173 | Accept the package name, send a HTTP request to the relevant 174 | URL, check response for valid PyPI existence, return normalized name. 175 | 176 | @param name: The name of the package to be checked 177 | @type name: str 178 | @r_param normalized_name: Verified package name 179 | @r_type normalized_name: str 180 | """ 181 | if name == "": 182 | return "" 183 | 184 | http = HTTPSConnection(PYPI_HOST) 185 | http.request('HEAD', '/pypi/%s/' % name) 186 | r = http.getresponse() 187 | if r.status not in (200, 301): 188 | raise ValueError(r.reason) 189 | normalized_name = r.getheader('location', name).split('/')[-1] 190 | return normalized_name 191 | 192 | 193 | def get_releases(packages): 194 | """Retrieve and return package data via XMLRPC requests. 195 | 196 | @param packages: List of packages 197 | @type packages: list 198 | @r_param "called_packages.popleft()": Called package ame 199 | @r_type "called_packages.popleft()": str 200 | @r_param releases: Items from Multicall Generator Object 201 | @r_type releases: XMLRPC Proxy Object 202 | """ 203 | mcall = xmlrpc.MultiCall(PYPI_XML) 204 | called_packages = deque() 205 | for package in packages: 206 | mcall.package_releases(package, True) 207 | called_packages.append(package) 208 | if len(called_packages) == 100: 209 | result = mcall() 210 | mcall = xmlrpc.MultiCall(PYPI_XML) 211 | for releases in result: 212 | yield called_packages.popleft(), releases 213 | result = mcall() 214 | for releases in result: 215 | yield called_packages.popleft(), releases 216 | 217 | 218 | def get_release_info(packages, json=False): 219 | """Retrieve statistics for package passed in by calling other methods. 220 | 221 | Based on JSON toggle, retrieve package data as JSON or via XMLRPC requests 222 | and return the data. 223 | 224 | @param packages: List of package names 225 | @type packages: list 226 | @param json: JSON Toggle 227 | @type json: bool 228 | @r_param urls: Details of a particular release 229 | @r_type urls: dict 230 | @r_param data[info]/data: General information about package 231 | @r_type data[info]/data: dict 232 | """ 233 | if json: 234 | for package in packages: 235 | data = get_jsonparsed_data(PYPI_JSON % package) 236 | for release in data['releases']: 237 | urls = data['releases'][release] 238 | yield urls, data['info'] 239 | return 240 | 241 | mcall = xmlrpc.MultiCall(PYPI_XML) 242 | 243 | i = 0 244 | for package, releases in get_releases(packages): 245 | for version in releases: 246 | mcall.release_urls(package, version) 247 | mcall.release_data(package, version) 248 | i += 1 249 | if i % 50 == 49: 250 | result = mcall() 251 | mcall = xmlrpc.MultiCall(PYPI_XML) 252 | for urls, data in by_two(result): 253 | 254 | yield urls, data 255 | 256 | result = mcall() 257 | for urls, data in by_two(result): 258 | yield urls, data 259 | 260 | 261 | def vanity(packages, verbose, json, pattern): 262 | """Parse args, verify package, retrieve details, return download count.""" 263 | version = None 264 | grand_total = 0 265 | package_list = [] 266 | for package in packages: 267 | if package.find('==') >= 0: 268 | package, version = package.split('==') 269 | try: 270 | package = normalize(package) 271 | except ValueError: 272 | logger.debug('No such module or package %r', package) 273 | continue 274 | 275 | # Count downloads 276 | total = count_downloads(package, 277 | json=json, 278 | version=version, 279 | verbose=verbose, 280 | pattern=pattern) 281 | if total != 0: 282 | if version: 283 | logger.debug('%s %s has been downloaded %s times!', 284 | package, version, locale.format("%d", 285 | total, 286 | grouping=True)) 287 | else: 288 | logger.debug('%s has been downloaded %s times!', 289 | package, locale.format("%d", 290 | total, 291 | grouping=True)) 292 | else: 293 | if version: 294 | logger.debug('No downloads for %s %s.', package, version) 295 | else: 296 | logger.debug('No downloads for %s.', package) 297 | grand_total += total 298 | package_list.append(package) 299 | if len(package_list) > 1: 300 | package_string = ( 301 | ', '.join(package_list[:-1]) + " and " + package_list[-1]) 302 | logger.debug("%s have been downloaded %s times!", 303 | package_string, locale.format("%d", 304 | grand_total, 305 | grouping=True)) 306 | 307 | logger.debug("\n\n\t *** Note: PyPI stats are broken again; we're now" 308 | "waiting for warehouse. https://github.com/aclark4life/" 309 | "vanity/issues/22 ***\n\n") 310 | 311 | if __name__ == '__main__': 312 | parser = argparse.ArgumentParser(description=__doc__) 313 | parser.add_argument('package', help='pypi package name', nargs='+') 314 | parser.add_argument('-q', 315 | '--quiet', 316 | help='only show total downloads', 317 | action='store_true') 318 | parser.add_argument('-j', 319 | '--json', 320 | help='use pypi json api instead of xmlrpc', 321 | action='store_true') 322 | parser.add_argument('-p', 323 | '--pattern', 324 | help='only show files matching a regex pattern') 325 | args = parser.parse_args() 326 | 327 | vanity(packages=args.package, 328 | verbose=not (args.quiet), 329 | json=args.json, 330 | pattern=args.pattern) 331 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------