Browse Source

copy "classifiers" and "license" command to "shut" command group

shut
Niklas Rosenstein 10 months ago
parent
commit
777732b254
No known key found for this signature in database GPG Key ID: 6D269B33D25F6C6
3 changed files with 107 additions and 1 deletions
  1. + 5
    - 1
      src/shore/commands/__init__.py
  2. + 51
    - 0
      src/shore/commands/classifiers.py
  3. + 51
    - 0
      src/shore/commands/license.py

+ 5
- 1
src/shore/commands/__init__.py

@ -46,7 +46,7 @@ def shut(verbose, quiet):
ctx = click.get_current_context()
ctx.ensure_object(dict)
ctx['quiet'] = quiet
context['quiet'] = quiet
if quiet:
level = logging.CRITICAL
@ -61,3 +61,7 @@ def shut(verbose, quiet):
format='[%(levelname)s|%(asctime)s|%(name)s]: %(message)s',
level=level,
)
from . import classifiers
from . import license

+ 51
- 0
src/shore/commands/classifiers.py

@ -0,0 +1,51 @@
# -*- coding: utf8 -*-
# Copyright (c) 2020 Niklas Rosenstein
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
"""
List or search package classifiers on PyPI.
"""
from . import shut
from shore.util.classifiers import get_classifiers
import click
@shut.group(help=__doc__)
def classifiers():
pass
@classifiers.command()
def ls():
" List all classifiers. "
for classifier in get_classifiers():
print(classifier)
@classifiers.command()
@click.option('-q', '--term', help='The substring that will be used to filter classifiers.')
def search(term):
" Search for package classifiers. "
for classifier in get_classifiers():
if not term or term.strip().lower() in classifier.lower():
print(classifier)

+ 51
- 0
src/shore/commands/license.py

@ -0,0 +1,51 @@
# -*- coding: utf8 -*-
# Copyright (c) 2020 Niklas Rosenstein
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
"""
Get license information from DejaCode.
"""
from . import shut
from shore.util.license import get_license_metadata, wrap_license_text
import click
import json
@shut.group(help=__doc__)
def license():
pass
@license.command()
@click.option('--name', help='The name of the license to retrieve.')
@click.option('--long', 'format_', flag_value='long', default=True)
@click.option('--short', 'format_', flag_value='short')
@click.option('--json', 'format_', flag_value='json')
def get(name, format_):
" Retrieve the license text or a JSON description of the license. "
data = get_license_metadata(name)
if format_ == 'json':
print(json.dumps(data, sort_keys=True))
elif format_ == 'long':
print(wrap_license_text(data['license_text']))
elif format_ == 'short':
print(wrap_license_text(data['standard_notice'] or data['license_text']))

Loading…
Cancel
Save