Skip to content

Commit

Permalink
Merge pull request #103 from thiagofigueiro/issue-97-replace-docopt-w…
Browse files Browse the repository at this point in the history
…ith-click

Issue 97 replace docopt with click
  • Loading branch information
thiagofigueiro authored Feb 17, 2020
2 parents 69508b3 + b094795 commit d74a9cf
Show file tree
Hide file tree
Showing 33 changed files with 1,116 additions and 1,027 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ env:
services:
- docker
before_install:
- sudo apt-get install -y expect
- docker pull sonatype/nexus3:$NEXUS_VERSION
- docker run -d --rm -p 127.0.0.1:8081:8081 --name nexus sonatype/nexus3:$NEXUS_VERSION
- cp -f tests/fixtures/dot-nexus-cli ~/.nexus-cli
Expand All @@ -22,7 +21,7 @@ script:
- flake8 *.py src tests --format=pylint
- pytest -m 'not integration'
- ./tests/wait-for-nexus.sh || exit 1
- ./tests/nexus-login $(docker exec nexus cat /nexus-data/admin.password)
- nexus3 login -U http://localhost:8081 --no-x509_verify -u admin -p $(docker exec nexus cat /nexus-data/admin.password)
- pytest -m integration
after_success:
- codecov
Expand Down
10 changes: 7 additions & 3 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Command-line Interface
======================

Logging level can be configured by setting an environment variable named
``LOG_LEVEL``.
Valid values are: ``DEBUG``, ``INFO``, ``WARNING`` (default), ``ERROR``,
``CRITICAL``.
``LOG_LEVEL``. Valid values are: ``DEBUG``, ``INFO``, ``WARNING`` (default),
``ERROR``, ``CRITICAL``.


.. click:: nexuscli.cli:nexus_cli
:prog: nexus3
:show-nested:
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def setup(_):
'sphinxcontrib.napoleon',
'sphinx.ext.intersphinx',
'sphinx.ext.coverage',
'sphinx_click.ext',
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
9 changes: 2 additions & 7 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
.. nexus3-cli documentation master file, created by
sphinx-quickstart on Sat Jul 21 11:25:02 2018.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
nexus3-cli: a Sonatype Nexus 3 client
=====================================
nexus3-cli: client for Sonatype's Nexus OSS 3
=============================================

.. toctree::
:maxdepth: 2
Expand Down
2 changes: 2 additions & 0 deletions docs/requirements.in
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
sphinx-click
sphinxcontrib-napoleon
sphinx_rtd_theme
33 changes: 31 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,37 @@
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements.txt requirements.in
# pip-compile --no-emit-trusted-host --no-index --output-file=requirements.txt requirements.in
#
alabaster==0.7.12 # via sphinx
babel==2.8.0 # via sphinx
certifi==2019.11.28 # via requests
chardet==3.0.4 # via requests
docutils==0.16 # via sphinx
idna==2.8 # via requests
imagesize==1.2.0 # via sphinx
jinja2==2.11.1 # via sphinx
markupsafe==1.1.1 # via jinja2
packaging==20.1 # via sphinx
pbr==5.4.4 # via sphinx-click
pockets==0.6.2 # via sphinxcontrib-napoleon
six==1.13.0 # via pockets, sphinxcontrib-napoleon
pygments==2.5.2 # via sphinx
pyparsing==2.4.6 # via packaging
pytz==2019.3 # via babel
requests==2.22.0 # via sphinx
six==1.13.0 # via packaging, pockets, sphinxcontrib-napoleon
snowballstemmer==2.0.0 # via sphinx
sphinx-click==2.3.1
sphinx-rtd-theme==0.4.3
sphinx==2.4.1 # via sphinx-click, sphinx-rtd-theme
sphinxcontrib-applehelp==1.0.1 # via sphinx
sphinxcontrib-devhelp==1.0.1 # via sphinx
sphinxcontrib-htmlhelp==1.0.2 # via sphinx
sphinxcontrib-jsmath==1.0.1 # via sphinx
sphinxcontrib-napoleon==0.7
sphinxcontrib-qthelp==1.0.2 # via sphinx
sphinxcontrib-serializinghtml==1.1.3 # via sphinx
urllib3==1.25.8 # via requests

# The following packages are considered to be unsafe in a requirements file:
# setuptools
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
from setuptools import find_packages, setup

package_name = 'nexus3-cli'
package_version = '2.3.1'
package_version = '3.0.0'

requires = [
'click>=7.0.0,<8',
'clint',
'docopt',
'future',
'faker',
'inflect',
'future',
'requests[security]>=2.14.2',
'semver',
'six',
'texttable'
]

Expand Down Expand Up @@ -44,7 +43,7 @@
tests_require=test_requires,
license='MIT',
classifiers=[
'Development Status :: 4 - Beta',
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Topic :: System :: Systems Administration',
Expand All @@ -64,7 +63,7 @@
include_package_data=True,
entry_points={
'console_scripts': [
'nexus3=nexuscli.cli:main',
'nexus3=nexuscli.cli:nexus_cli',
],
},
extras_require={'test': test_requires},
Expand Down
4 changes: 4 additions & 0 deletions src/nexuscli/api/cleanup_policy/collection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import json
import logging

from nexuscli import exception, nexus_util
from nexuscli.api.cleanup_policy import CleanupPolicy

LOG = logging.getLogger(__name__)


class CleanupPolicyCollection(object):
"""
Expand Down Expand Up @@ -40,6 +43,7 @@ def create_or_update(self, cleanup_policy):

script_args = json.dumps(cleanup_policy.configuration)
try:
LOG.debug('Create/update cleanup policy: %s', script_args)
response = self._client.scripts.run(
self.GROOVY_SCRIPT_NAME, data=script_args)
except exception.NexusClientAPIError:
Expand Down
51 changes: 22 additions & 29 deletions src/nexuscli/api/cleanup_policy/model.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
from nexuscli.api.cleanup_policy import validations


class CleanupPolicy(object):
"""
Represents a Nexus Cleanup Policy.
Example structure and attributes common to all repositories:
>>> kwargs = {
>>> 'name': 'my-policy',
>>> 'format': 'bower',
>>> 'notes': 'Some comment',
>>> 'criteria': {
>>> 'lastDownloaded': 172800,
>>> 'lastBlobUpdated': 86400,
>>> 'regex': 'matchthis'
>>> }
>>> }
Args:
client (nexuscli.nexus_client.NexusClient): the client instance that
will be used to perform operations against the Nexus 3 service. You
must provide this at instantiation or set it before calling any
methods that require connectivity to Nexus.
name (str): name of the new policy.
format (str): 'all' or the name of the repository format this policy
format (str): 'all' or the format of the repository this policy
applies to.
mode (str): 'delete'
criteria (dict): the deletion criteria for the policy. Supports one or
more of the following attributes:
- ``lastDownloaded`` (int): days since artefact last
downloaded;
- ``lastBlobUpdated`` (int): days since last update to
artefact;
lastDownloaded (int): deletion criterion: days since artefact last
downloaded
lastBlobUpdated (int): deletion criterion: days since last update to
artefact
regex (str): deletion criterion: only delete artefacts that match this
regular expression
"""
def __init__(self, client, **kwargs):
self._client = client
# TODO: validate kwargs
self._raw = kwargs

@property
Expand All @@ -35,25 +46,7 @@ def configuration(self):
:py:class:`~nexuscli.api.cleanup_policy.collection.CleanupPolicyCollection`
methods.
Example structure and attributes common to all repositories:
>>> cleanup_policy = {
>>> 'name': 'my-policy',
>>> 'format': 'bower',
>>> 'mode': 'delete',
>>> 'criteria': {
>>> 'lastDownloaded': 172800,
>>> 'lastBlobUpdated': 86400
>>> }
>>> }
Depending on the repository type and format (recipe), other attributes
will be present.
:return: cleanup policy as a dict
:rtype: dict
"""
# TODO: validate format, mode
validations.policy_criteria(self._raw)
validations.policy_name(self._raw)
return self._raw
36 changes: 0 additions & 36 deletions src/nexuscli/api/cleanup_policy/validations.py

This file was deleted.

7 changes: 4 additions & 3 deletions src/nexuscli/api/repository/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ def _add_yum_kwargs(kwargs, attributes):
def _add_apt_kwargs(kwargs, attributes):
if 'aptSigning' in attributes:
kwargs['passphrase'] = attributes['aptSigning']['passphrase']
kwargs['keypair'] = attributes['aptSigning']['keypair']
kwargs['gpg_keypair'] = attributes['aptSigning']['keypair']
if 'apt' in attributes:
kwargs['passphrase'] = attributes['apt']['distribution']
kwargs['flat'] = attributes['apt']['flat']
kwargs['distribution'] = attributes['apt']['distribution']
if attributes['apt'].get('flat') is not None:
kwargs['flat'] = attributes['apt']['flat']


def _add_hosted_kwargs(kwargs, attributes):
Expand Down
29 changes: 15 additions & 14 deletions src/nexuscli/api/repository/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class Repository:
'pypi',
'raw',
'rubygems',
'docker',
'apt',
)
TYPE = None

Expand Down Expand Up @@ -606,7 +604,7 @@ class DockerProxyRepository(ProxyRepository, DockerRepository):
def __init__(self, name,
index_type='REGISTRY',
use_trust_store_for_index_access=False,
index_url="https://index.docker.io/",
index_url='https://index.docker.io/',
**kwargs):
self.index_type = index_type

Expand Down Expand Up @@ -683,23 +681,22 @@ def configuration(self):

class AptHostedRepository(AptRepository, HostedRepository):
def __init__(self, name,
gpg='public.gpg.key',
gpg_keypair: str = None,
passphrase=None,
**kwargs):
self.gpg = gpg
self.gpg_keypair = gpg_keypair
self.passphrase = passphrase
super().__init__(name, **kwargs)

@property
def configuration(self):
repo_config = super().configuration
with open(self.gpg, 'r') as gpg_file:
repo_config['attributes'].update({
'aptSigning': {
'keypair': gpg_file.read(),
'passphrase': self.passphrase
}
})
repo_config['attributes'].update({
'aptSigning': {
'keypair': self.gpg_keypair,
'passphrase': self.passphrase
}
})

return repo_config

Expand All @@ -720,16 +717,20 @@ def configuration(self):
return repo_config


# FIXME: these are supposed to be strings
__all__ = [
Repository, HostedRepository, ProxyRepository,
AptHostedRepository, AptProxyRepository,
BowerHostedRepository, BowerProxyRepository,
DockerHostedRepository, DockerProxyRepository,
MavenHostedRepository, MavenProxyRepository,
NpmHostedRepository, NpmProxyRepository,
NugetHostedRepository, NugetProxyRepository,
PypiHostedRepository, PypiProxyRepository,
RawHostedRepository, RawProxyRepository,
RubygemsHostedRepository, RubygemsProxyRepository,
YumHostedRepository, YumProxyRepository,
DockerHostedRepository, DockerProxyRepository,
AptHostedRepository, AptProxyRepository
]

SUPPORTED_FORMATS = sorted(
set([recipe for cls in __all__ for recipe in cls.RECIPES]))
Loading

0 comments on commit d74a9cf

Please sign in to comment.