Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import asyncio
import os.path as _path
from pkg_resources import parse_version
import structlog
from . import conf_cacheable_with_name
logger = structlog.get_logger(logger_name=__name__)
_self_path = _path.dirname(_path.abspath(__file__))
_cmd_prefix = ['/bin/bash', _path.join(_self_path, 'vcs.sh')]
PROT_VER = 1
get_cacheable_conf = conf_cacheable_with_name('vcs')
def _parse_oldver(oldver):
if oldver is None:
return PROT_VER, 0, ''
try:
prot_ver, count, ver = oldver.split('.', maxsplit=2)
prot_ver = int(prot_ver)
count = int(count)
except:
return PROT_VER, 0, ''
if prot_ver != PROT_VER:
return PROT_VER, 0, ver
return PROT_VER, count, ver
async def get_version(name, conf, **kwargs):
vcs = conf['vcs'] or ''
# MIT licensed
# Copyright (c) 2013-2017 lilydjwg , et al.
from . import cmd, conf_cacheable_with_name
get_cacheable_conf = conf_cacheable_with_name('pacman')
async def get_version(name, conf, **kwargs):
referree = conf.get('pacman') or name
c = "LANG=C pacman -Si %s | grep -F Version | awk '{print $3}' | head -n 1" % referree
conf['cmd'] = c
strip_release = conf.getboolean('strip-release', False)
version = await cmd.get_version(name, conf)
if strip_release and '-' in version:
version = version.rsplit('-', 1)[0]
return version
# MIT licensed
# Copyright (c) 2017 Felix Yan , et al.
import structlog
from . import session, conf_cacheable_with_name
logger = structlog.get_logger(logger_name=__name__)
URL = 'https://sources.debian.org/api/src/%(pkgname)s/?suite=%(suite)s'
get_cacheable_conf = conf_cacheable_with_name('debianpkg')
async def get_version(name, conf, **kwargs):
pkg = conf.get('debianpkg') or name
strip_release = conf.getboolean('strip-release', False)
suite = conf.get('suite') or "sid"
url = URL % {"pkgname": pkg, "suite": suite}
async with session.get(url) as res:
data = await res.json()
if not data.get('versions'):
logger.error('Debian package not found', name=name)
return
r = data['versions'][0]
if strip_release:
version = r['version'].split("-")[0]
# MIT licensed
# Copyright (c) 2013-2017 lilydjwg , et al.
import structlog
from . import session, conf_cacheable_with_name
logger = structlog.get_logger(logger_name=__name__)
URL = 'https://www.archlinux.org/packages/search/json/'
get_cacheable_conf = conf_cacheable_with_name('archpkg')
async def get_version(name, conf, **kwargs):
pkg = conf.get('archpkg') or name
strip_release = conf.getboolean('strip-release', False)
provided = conf.get('provided')
async with session.get(URL, params={"name": pkg}) as res:
data = await res.json()
if not data['results']:
logger.error('Arch package not found', name=name)
return
r = [r for r in data['results'] if r['repo'] != 'testing'][0]
if provided:
def simple_json(urlpat, confkey, version_from_json):
async def get_version(name, conf, **kwargs):
repo = conf.get(confkey) or name
url = urlpat % repo
kwargs = {}
if conf.get('proxy'):
kwargs["proxy"] = conf.get('proxy')
async with session.get(url, **kwargs) as res:
data = await res.json(content_type=None)
version = version_from_json(data)
return version
get_cacheable_conf = conf_cacheable_with_name(confkey)
return get_version, get_cacheable_conf
# MIT licensed
# Copyright (c) 2017 Felix Yan , et al.
import structlog
from . import session, conf_cacheable_with_name
logger = structlog.get_logger(logger_name=__name__)
URL = 'https://api.launchpad.net/1.0/ubuntu/+archive/primary?ws.op=getPublishedSources&source_name=%s&exact_match=true'
get_cacheable_conf = conf_cacheable_with_name('ubuntupkg')
async def get_version(name, conf, **kwargs):
pkg = conf.get('ubuntupkg') or name
strip_release = conf.getboolean('strip-release', False)
suite = conf.get('suite')
url = URL % pkg
if suite:
suite = "https://api.launchpad.net/1.0/ubuntu/" + suite
releases = []
while not releases:
async with session.get(url) as res:
data = await res.json()
# MIT licensed
# Copyright (c) 2013-2018 lilydjwg , et al.
from . import session, conf_cacheable_with_name
API_URL = 'https://crates.io/api/v1/crates/%s'
get_cacheable_conf = conf_cacheable_with_name('cratesio')
async def get_version(name, conf, **kwargs):
name = conf.get('cratesio') or name
async with session.get(API_URL % name) as res:
data = await res.json()
version = [v['num'] for v in data['versions'] if not v['yanked']][0]
return version
# MIT licensed
# Copyright (c) 2013-2017 lilydjwg , et al.
import structlog
from datetime import datetime
from . import session, conf_cacheable_with_name
logger = structlog.get_logger(logger_name=__name__)
AUR_URL = 'https://aur.archlinux.org/rpc/?v=5&type=info&arg[]='
get_cacheable_conf = conf_cacheable_with_name('aur')
async def get_version(name, conf, **kwargs):
aurname = conf.get('aur') or name
use_last_modified = conf.getboolean('use_last_modified', False)
strip_release = conf.getboolean('strip-release', False)
async with session.get(AUR_URL, params={"v": 5, "type": "info", "arg[]": aurname}) as res:
data = await res.json()
if not data['results']:
logger.error('AUR upstream not found', name=name)
return
version = data['results'][0]['Version']
if use_last_modified:
version += '-' + datetime.utcfromtimestamp(data['results'][0]['LastModified']).strftime('%Y%m%d%H%M%S')
if strip_release and '-' in version:
# MIT licensed
# Copyright (c) 2013-2017 lilydjwg , et al.
from pkg_resources import parse_version
from . import conf_cacheable_with_name, session
get_cacheable_conf = conf_cacheable_with_name('pypi')
async def get_version(name, conf, **kwargs):
package = conf.get('pypi') or name
use_pre_release = conf.getboolean('use_pre_release', False)
url = 'https://pypi.org/pypi/{}/json'.format(package)
async with session.get(url) as res:
data = await res.json()
if use_pre_release:
version = sorted(
data['releases'].keys(),
key = parse_version,
)[-1]
else: