diff --git a/.gitignore b/.gitignore index c2e41a3cfe2185666b8847f9a3b3a0805e470228..55a0adf56194a5da123e12518420d1316c05ede2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ build/ dist/ *.egg-info/ __pycache__/ +*.log +.tox diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000000000000000000000000000000000000..72b22fcab51e09f62fe83490023924f2e950b214 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include eb-prune diff --git a/README.rst b/README.rst index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..86bb7196ac05c2e166a24c2c7cb791588a2d9845 100644 --- a/README.rst +++ b/README.rst @@ -0,0 +1,13 @@ +eb-prune +######## + +Must specify AWS_DEFAULT_REGION environment variable. + +TODO +---- + +- License. +- Changelog. +- README, +- Testing with different Python versions with tox and flake8. +- Specify number of versions to keep. diff --git a/eb-prune/__init__.py b/eb_prune/__init__.py similarity index 73% rename from eb-prune/__init__.py rename to eb_prune/__init__.py index f9f3485e6059ff9e64a7b2bce902833c957e56fb..8d8d7f55493b9b985f925ec4dc12255bc7ca3c96 100644 --- a/eb-prune/__init__.py +++ b/eb_prune/__init__.py @@ -5,10 +5,10 @@ from __future__ import (absolute_import, division, from botocore import session -if __name__ == '__main__': +def main(): print('Pruning Elastic Beanstalk versions.') - session = session.get_session() - beanstalk_client = session.create_client('elasticbeanstalk') + aws_session = session.get_session() + beanstalk_client = aws_session.create_client('elasticbeanstalk') response = beanstalk_client.describe_application_versions() if response['ResponseMetadata']['HTTPStatusCode'] != 200: raise RuntimeError('Failed to describe application versions.') @@ -18,19 +18,23 @@ if __name__ == '__main__': raise RuntimeError('Failed to describe environments.') active_versions = [env['VersionLabel'] for env in response['Environments']] previous_versions = filter( - lambda x: (not x['VersionLabel'] in active_versions) and - x['Status'] == 'UNPROCESSED', versions) + lambda x: (not x['VersionLabel'] in active_versions) and + x['Status'] == 'UNPROCESSED', versions) old_versions = sorted(previous_versions, key=lambda x: x.get('DateCreated'))[:-400] for version in old_versions: response = beanstalk_client.delete_application_version( - ApplicationName=version['ApplicationName'], - VersionLabel=version['VersionLabel'], - DeleteSourceBundle=True) + ApplicationName=version['ApplicationName'], + VersionLabel=version['VersionLabel'], + DeleteSourceBundle=True) if response['ResponseMetadata']['HTTPStatusCode'] != 200: raise RuntimeError( - 'Failed to delete version {0}.'.format( - version['VersionLabel'])) + 'Failed to delete version {0}.'.format( + version['VersionLabel'])) print('Deleted version {0} of {1}.'.format(version['VersionLabel'], version['ApplicationName'])) print('Deleted {0} versions.'.format(len(old_versions))) + + +if __name__ == '__main__': + main() diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000000000000000000000000000000000..79bc67848fff34a6645702d4173e425bc2ccbc96 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[bdist_wheel] +# This flag says that the code is written to work on both Python 2 and Python +# 3. If at all possible, it is good practice to do this. If you cannot, you +# will need to generate wheels for each Python version that you support. +universal=1 diff --git a/setup.py b/setup.py index 04c47fb005dde5ea2156e8772d23c9c835a06e9a..a1a3209e12e92813200e654c1a15a00c8d73ce1e 100644 --- a/setup.py +++ b/setup.py @@ -6,20 +6,24 @@ setup( version='0.2.0', description='Pruning of Elastic Beanstalk versions.', long_description=open('README.rst', 'r').read(), - url='https://www.shore.co.il/cgit/eb-prune', + url='https://www.shore.co.il/git/eb-prune', author='Nimrod Adar', author_email='nimrod@shore.co.il', license='MIT', classifiers=[ 'Development status :: 4 - Beta', 'Intended Audience :: Developers', - 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 2.6', 'Intended Audience :: System Administrators', 'Topic :: Utilities', ], keywords='beanstalk AWS', packages=find_packages(), - + install_requires=['botocore'], + extras_require={ + 'dev': ['tox', 'flake8'], }, + entry_points={ + 'console_scripts': [ + 'eb-prune=eb_prune:main'], }, ) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000000000000000000000000000000000000..8c6509512489c4679a298d8a5f07e587b0254894 --- /dev/null +++ b/tox.ini @@ -0,0 +1,32 @@ + +# this file is *not* meant to cover or endorse the use of tox or pytest or +# testing in general, +# +# It's meant to show the use of: +# +# - check-manifest +# confirm items checked into vcs are in your sdist +# - python setup.py check (using the readme_renderer extension) +# confirms your long_description will render correctly on pypi +# +# and also to help confirm pull requests to this project. + +[tox] +envlist = py{27,35} + +[testenv] +basepython = + py27: python2.7 + py35: python3.5 +deps = + check-manifest + {py27,py35}: readme_renderer + flake8 +commands = + check-manifest --ignore tox.ini,tests* + # py26 doesn't have "setup.py check" + {py27,py35}: python setup.py check -m -r -s + flake8 . +[flake8] +exclude = .tox,*.egg,build,data +select = E,W,F