Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def download(self, urlpath, filename, prot='http'):
"""Downloads an AUR tarball (http) to the current directory.
:Arguments: URL, filename for saving, protocol.
:Input: none.
:Output: none.
:Returns: bytes downloaded.
:Exceptions:
PBError, IOError, requests.exceptions.*
:Message codes: ERR3101, ERR3102."""
r = requests.get(self.aururl.format(prot, urlpath))
# Error handling.
if r.status_code != 200:
raise PBError(_('[ERR3102] download: HTTP Error {0}').format(
r.status_code))
elif r.headers['content-length'] == '0':
raise PBError(_('[ERR3101] download: 0 bytes downloaded'))
f = open(filename, 'wb')
f.write(r.content)
f.close()
return r.headers['content-length']
DS.protocol = args.protocol
try:
utils = Utils()
build = Build()
DS.log.info('Arguments parsed.')
if not args.color:
# That's awesome in variables AND 2.x series.
# …and it was moved to PBDS.
DS.colorsoff()
if args.info:
for pkgname in args.pkgs:
pkg = utils.info(pkgname)
if pkg is None:
raise PBError(_('Package {0} not found.').format(
pkgname))
# TRANSLATORS: space it properly. `yes/no' below are
# for `out of date'.
print(_("""Category : {cat}
Name : {nme}
Version : {ver}
URL : {url}
Licenses : {lic}
Votes : {cmv}
Out of Date : {ood}
Maintainer : {mnt}
First Submitted: {fsb}
Last Updated : {upd}
Description : {dsc}
""").format(cat=DS.categories[int(pkg['CategoryID'])],
nme=pkg['Name'],
def jsonreq(self, rtype, arg, prot='http'):
"""Makes a request and returns plain JSON data.
:Arguments: request type, argument (package name), protocol.
:Input: none.
:Output: none.
:Returns: JSON data from the API.
:Exceptions: requests.exceptions.*, PBError.
:Message codes: ERR1001."""
r = requests.get(self.rpc.format(prot, rtype, arg))
if r.status_code != 200:
raise PBError(_('[ERR1001] AUR: HTTP Error {0}').format(
r.status_code))
return r.text
"""Extracts an AUR tarball.
:Arguments: filename.
:Input: none.
:Output: none.
:Returns: file count.
:Exceptions: PBError, IOError.
:Message codes: ERR3151."""
thandle = tarfile.open(filename, 'r:gz')
thandle.extractall()
names = thandle.getnames()
thandle.close()
if names != []:
return len(names)
else:
raise PBError(_('[ERR3151] extract: no files extracted'))
def jsonmultiinfo(self, args, prot='http'):
"""Makes a multiinfo request and returns plain JSON data.
:Arguments: a list of packages, protocol.
:Input: none.
:Output: none.
:Returns: JSON data from the API.
:Exceptions: requests.exceptions.*, PBError.
:Message codes: ERR1001."""
urlargs = '&arg[]=' + '&arg[]='.join(args)
r = requests.get(self.mrpc.format(prot, urlargs))
if r.status_code != 200:
raise PBError(_('[ERR1001] AUR: HTTP Error {0}').format(
r.status_code))
return r.text
localdb = H.get_localdb()
pkg = localdb.get_pkg(pkgname)
aurversion = self.utils.info(pkgname)['Version']
if pkg is None:
fancy_error2(_('[ERR3451] validation: NOT \
installed'))
else:
if pyalpm.vercmp(aurversion, pkg.version) > 0:
fancy_error2(_('[ERR3452] validation: \
outdated {0}').format(pkg.version))
else:
fancy_msg2(_('[INF3450] validation: \
installed {0}').format(pkg.version))
elif build_result[0] >= 0 and build_result[0] <= 15:
os.chdir('../')
raise PBError(_('[ERR3402] Something went wrong. \
EC={0} EM={1}').format(build_result[0], build_result[1]))
elif build_result[0] == 16:
os.chdir('../')
fancy_warning(_('[WRN3401] Building more AUR packages is \
required.'))
for pkgname2 in build_result[1]:
self.auto_build(pkgname2, validate, performdepcheck,
makepkginstall)
self.auto_build(pkgname, validate, performdepcheck,
makepkginstall)
except PBError as inst:
fancy_error(str(inst))
:Arguments: URL, filename for saving, protocol.
:Input: none.
:Output: none.
:Returns: bytes downloaded.
:Exceptions:
PBError, IOError, requests.exceptions.*
:Message codes: ERR3101, ERR3102."""
r = requests.get(self.aururl.format(prot, urlpath))
# Error handling.
if r.status_code != 200:
raise PBError(_('[ERR3102] download: HTTP Error {0}').format(
r.status_code))
elif r.headers['content-length'] == '0':
raise PBError(_('[ERR3101] download: 0 bytes downloaded'))
f = open(filename, 'wb')
f.write(r.content)
f.close()
return r.headers['content-length']