...
 
Commits (2)
......@@ -74,6 +74,11 @@ To update package version, run `upsert` again.
```
uptr package upsert -m https://pypi.org/project/Django/ -p 2.0.5
```
If you don't want to remember distribution site url for pypi or dockerhub (as it's not just copypasting of url, like in case of github, you can use dedicated commands:
```
uptr package dockerhub -d postgres -p 9.6.8
uptr package pypi -d Django -p 1.11
```
To see packages list, run:
```
......
......@@ -8,7 +8,7 @@ def readme():
setup(
name='uptr',
version='0.0.4',
version='0.0.5',
description='Command line interface for update tracker.',
long_description=readme(),
long_description_content_type="text/markdown",
......
......@@ -15,6 +15,7 @@ class ClientConfiguration(Configuration):
token = None
address = 'http://10.11.0.211/'
# address = 'https://uptr.teonite.net/'
project_id = 0
......
from urllib.parse import urlsplit
import click
import sys
from click import MissingParameter
from .main import settings, session
from .utils import DistUrl
from .utils import URL
@click.group()
......@@ -26,19 +28,18 @@ def package(ctx, project_id):
@package.command()
@click.option('--distname', '-d', required=False,
help='the name of distribution. Optional for pypi, github, dockerhub.')
@click.option('--master-site', '-m', required=True, type=DistUrl(),
@click.option('--distname', '-d', required=True,
help='the name of distribution.')
@click.option('--master-site', '-m', required=True, type=URL(),
help='URL of a web-site, where there is a link to distribution files')
@click.option('--package-version', '-p', required=True,
help='your local version number, e.g. the one you have installed on your machine')
@click.pass_context
def upsert(ctx, distname, master_site, package_version, is_generic):
"""Add or update package."""
if is_generic and not distname:
raise click.MissingParameter(message='Distribution name is required for generic sites.',
param_hint=['--distname', '-d'], param_type='option')
def upsert(ctx, distname, master_site, package_version):
"""Add or update package.\n
If you are interested in pypi or dockerhub packages - you can use respective commands.
to omit writing a site.
"""
url = settings.address + '/api/projects/%s/packages/' % ctx.obj['project_id']
resp = session.post(url, data={
'distname': distname,
......@@ -55,6 +56,44 @@ def upsert(ctx, distname, master_site, package_version, is_generic):
sys.exit(1)
@package.command()
@click.option('--distname', '-d', required=True,
help='the name of distribution.')
@click.option('--package-version', '-p', required=True,
help='your local version number, e.g. the one you have installed on your machine')
@click.pass_context
def pypi(ctx, distname, package_version):
"""upsert version for pypi"""
master_site = 'https://pypi.org/project/%s' % distname
ctx.invoke(upsert, distname=distname, package_version=package_version,
master_site=master_site)
@package.command()
@click.option('--distname', '-d', required=True,
help='the name of distribution.')
@click.option('--package-version', '-p', required=True,
help='your local version number, e.g. the one you have installed on your machine')
@click.pass_context
def dockerhub(ctx, distname, package_version):
"""upsert version for dockerhub"""
master_site = 'https://hub.docker.com/_/%s/' % distname
ctx.invoke(upsert, distname=distname, package_version=package_version,
master_site=master_site)
@click.option('--master-site', '-m', required=True, type=URL(),
help='URL of a web-site, where there is a link to distribution files')
@click.option('--package-version', '-p', required=True,
help='your local version number, e.g. the one you have installed on your machine')
@click.pass_context
def github(ctx, master_site, package_version):
"""upsert version for github - no need to imagine distname"""
distname = urlsplit(master_site).path
ctx.invoke(upsert, distname=distname, package_version=package_version,
master_site=master_site)
@package.command()
@click.pass_context
def list(ctx):
......
import re
from urllib.parse import urlsplit
import click
......@@ -20,11 +19,3 @@ class URL(click.ParamType):
if not self.regex.search(value):
self.fail('invalid URL', param, ctx)
return value
class DistUrl(URL):
def convert(self, value, param, ctx):
value = super().convert(value, param, ctx)
parsed = urlsplit(value)
ctx.params['is_generic'] = parsed.hostname not in IMPLEMENTED_SITES
return value