├── .gitignore ├── LICENSE ├── README.md ├── README.rst ├── docker-compose-search └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # general things to ignore 2 | build/ 3 | dist/ 4 | *.egg-info/ 5 | *.egg 6 | *.py[cod] 7 | __pycache__/ 8 | *.so 9 | *~ 10 | 11 | # due to using tox and pytest 12 | .tox 13 | .cache 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Francesco Uliana 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-compose-search 2 | 3 | command line utility to search docker-compose projects on [composeregistry.com](https://www.composeregistry.com/) 4 | 5 | ![example](http://i.imgur.com/EbEKQlW.gif) 6 | 7 | ## Installation with [pip](https://pip.pypa.io/en/stable/installing/) 8 | 9 | pip2 install docker-compose-search 10 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | docker-compose-search 2 | ======================= 3 | 4 | command line utility to search docker-compose projects -------------------------------------------------------------------------------- /docker-compose-search: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | 3 | ''' 4 | composeregistry.com CLI 5 | ''' 6 | 7 | import re 8 | import sys 9 | import logging 10 | import requests 11 | from git import Repo 12 | from termcolor import colored 13 | 14 | logging.basicConfig(level=logging.WARN) 15 | 16 | PATTERN = re.compile("^[1-8]$") 17 | 18 | def print_resultset(items): 19 | """ 20 | output resultset to console 21 | """ 22 | for i, item in enumerate(items): 23 | print colored(str(i+1), 'yellow') + ' ' + \ 24 | colored(item['owner'], 'magenta') + ' ' + item['name'] + ' ' + \ 25 | colored('(' + str(item['stars']) + ')', 'red') 26 | 27 | def clone(repo): 28 | """ 29 | git clone repository from github 30 | """ 31 | git_url = 'git@github.com:%s/%s.git' % (repo['owner'], repo['name']) 32 | print 'git clone ' + git_url 33 | Repo.clone_from(git_url, repo['name']) 34 | 35 | def search(query): 36 | ''' 37 | search for docker compose files on www.composeregistry.com 38 | ''' 39 | response = requests.get('https://www.composeregistry.com/api/v1/search', \ 40 | params={'query': query}, headers={'x-key': 'default'}) 41 | 42 | if response.status_code == 200: 43 | data = response.json() 44 | logging.debug(data) 45 | items = data['items'] 46 | print_resultset(items) 47 | 48 | if len(items) == 0: 49 | print 'no results found' 50 | else: 51 | choice = raw_input("\nselect an item: ") 52 | if PATTERN.match(choice): 53 | repo = items[int(choice)-1] 54 | clone(repo) 55 | else: 56 | logging.error('invalid choice: %s', choice) 57 | else: 58 | message = response.json()['error'] 59 | raise RuntimeError('unable to process request: ' + message \ 60 | + ', status code = ' + str(response.status_code)) 61 | 62 | def main(): 63 | """ 64 | main method, validates user input and query www.composeregistry.com/ 65 | """ 66 | if len(sys.argv) > 1: 67 | querystring = ' '.join(sys.argv[1:]) 68 | logging.info('searching for %s', querystring) 69 | search(querystring) 70 | else: 71 | logging.error('usage: %s QUERY', sys.argv[0]) 72 | 73 | if __name__ == '__main__': 74 | main() 75 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """docker-compose-search 2 | command line utility to search docker-compose projects 3 | """ 4 | 5 | # Always prefer setuptools over distutils 6 | from setuptools import setup, find_packages 7 | # To use a consistent encoding 8 | from codecs import open 9 | from os import path 10 | 11 | here = path.abspath(path.dirname(__file__)) 12 | 13 | # Get the long description from the README file 14 | with open(path.join(here, 'README.rst'), encoding='utf-8') as f: 15 | long_description = f.read() 16 | 17 | setup( 18 | name='docker-compose-search', 19 | 20 | version='1.0.1', 21 | 22 | description='search docker-compose projects', 23 | long_description=long_description, 24 | 25 | url='https://github.com/francescou/docker-compose-search', 26 | 27 | author='Francesco Uliana', 28 | author_email='francesco@uliana.it', 29 | 30 | license='MIT', 31 | 32 | classifiers=[ 33 | 'Development Status :: 3 - Alpha', 34 | 35 | 'Intended Audience :: Developers', 36 | 'Topic :: Software Development :: Build Tools', 37 | 38 | 'License :: OSI Approved :: MIT License', 39 | 40 | 'Programming Language :: Python :: 2', 41 | 'Programming Language :: Python :: 2.6', 42 | 'Programming Language :: Python :: 2.7', 43 | 'Programming Language :: Python :: 3', 44 | 'Programming Language :: Python :: 3.2', 45 | 'Programming Language :: Python :: 3.3', 46 | 'Programming Language :: Python :: 3.4', 47 | ], 48 | 49 | keywords='docker compose search', 50 | 51 | install_requires=['requests', 'gitpython', 'termcolor'], 52 | 53 | scripts=['docker-compose-search'] 54 | ) 55 | --------------------------------------------------------------------------------