class Top(easycli.SubCommand): __command__ = 'top' __aliases__ = ['t'] __arguments__ = [ easycli.Argument('-c', '--count', type=int, default=250, help='Maximum number of movies to be shown'), easycli.Argument('-y', '--year', type=int, action='append', help='Production year of the movies'), easycli.Argument('-g', '--genre', type=str, action='append', help='Genre of the movies'), easycli.Argument('-d', '--director', type=str, action='store', help='Director of the movies'), easycli.Argument('-s', '--star', type=str, action='append', help='The star who have acted in the movie') ] def __call__(self, args): movies = explorer.topmovies() if args.year: movies = explorer.filter(movies, 'year', args.year) if args.genre: movies = explorer.filter(movies, 'genre', args.genre) if args.director: movies = explorer.filter(movies, 'director', args.director) if args.star: movies = explorer.filter(movies, 'star', args.star) movies = movies[:min(args.count, len(movies))] for movie in movies: movie.print()
class DownloadSpacyDatabase(easycli.SubCommand): __command__ = 'getdb' __arguments__ = [ easycli.Argument('-language', help='Language that you want',), easycli.Argument( '-list', action='store_true', help='List of language that you can choose', ), ] def __call__(self, args): from spacy.cli import download if args.language: try: download(languages[args.language]) except: print('We dont find your choice in our database') if args.list: print('You can choose the language that is in list') print(', '.join(list(languages.keys())))
class Explorer(easycli.Root): __help__ = 'Easy imdb explorer' __completion__ = True __arguments__ = [ easycli.Argument('-v', '--version', action='store_true', help='Show version'), Top ] def __call__(self, args): if args.version: print(__version__) return return super().__call__(args)
class DownloadSpacyDatabase(easycli.SubCommand): __command__ = 'getdb' __arguments__ = [ # FIXME: Add an argument to print the list of available languages easycli.Argument( 'language', default='english', help='Language that you want', ), ] def __call__(self, args): from spacy.cli import download # FIXME: Print appropriate error message if language not found language = languages[args.language] download(language)
class TextBot(easycli.Root): __completion__ = True __help__ = 'A simple text assistant' __arguments__ = [ easycli.Argument('-v', '--version', action='store_true', help='Show version'), DownloadSpacyDatabase, ] def __call__(self, args): if args.version: from textbot import __version__ print(__version__) return return super().__call__(args)
class SimpleMockupServerSubCommand(easycli.Root): default_bind = '8080' application = None args = None __help__ = 'Restfulpy js client mockup server' __command__ = sys.argv[0] __arguments__ = [ easycli.Argument( '-c', '--config-file', metavar="FILE", help='List of configuration files separated by space. Default: ""' ), easycli.Argument( '-b', '--bind', default=default_bind, metavar='{HOST:}PORT', help= f'Bind Address. default is {default_bind}, A free tcp port will be choosed automatically if the ' f'0 (zero) is given'), easycli.Argument('command', nargs=argparse.REMAINDER, default=[], help='The command to run tests.'), easycli.Argument('-v', '--version', action='store_true', help='Show the mockup server\'s version.'), ] def __call__(self, args=None): if args.version: print(__version__) return self.application = MockupApplication() self.application.configure(filename=args.config_file) #if exists(db): # os.remove(db) # makedirs(settings.data_directory, exist_ok=True) self.application.initialize_orm() setup_schema() DBSession.execute('TRUNCATE TABLE resource') DBSession.commit() print(f'DB {DBSession.bind}') self.application.insert_mockup() host, port = args.bind.split(':') if ':' in args.bind else ( 'localhost', args.bind) httpd = make_server(host, int(port), self.application) url = 'http://%s:%d' % httpd.server_address print( f'The server is up!, Get {url} to more info about how to use it!') server_thread = threading.Thread(target=httpd.serve_forever, daemon=True) try: server_thread.start() if not args.command: server_thread.join() exitstatus = 0 else: test_runner_command = ' '.join(args.command).replace( '{url}', url) time.sleep(1) result = run(test_runner_command, shell=True) exitstatus = result.returncode return exitstatus except KeyboardInterrupt: print('CTRL+X is pressed.') return 1 finally: httpd.shutdown() sys.exit(exitstatus)