summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-06-28 00:00:27 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2020-06-28 03:31:52 +0530
commitb6d2e150385b277e573417e4e33f3326869be417 (patch)
treeff03bfbb34d33980ddda0112c8f5f18a9724928c
parent631fc185fbebd1c3bef33e3e40809f4e0f07910b (diff)
cerbero: Define a custom user agent while downloading
Some places block urllib, and others block wget / curl. Set our own agent to workaround that, and so that people can contact us in case we're doing something they don't like while downloading things.
-rw-r--r--cerbero/enums.py3
-rw-r--r--cerbero/utils/shell.py11
-rw-r--r--setup.py3
3 files changed, 12 insertions, 5 deletions
diff --git a/cerbero/enums.py b/cerbero/enums.py
index 514c02be..aba12c1a 100644
--- a/cerbero/enums.py
+++ b/cerbero/enums.py
@@ -17,6 +17,9 @@
# Boston, MA 02111-1307, USA.
+# Safest place to define this since this file imports very few modules
+CERBERO_VERSION = '1.14.5'
+
class Platform:
''' Enumeration of supported platforms '''
LINUX = 'linux'
diff --git a/cerbero/utils/shell.py b/cerbero/utils/shell.py
index 2751b7bc..e965672a 100644
--- a/cerbero/utils/shell.py
+++ b/cerbero/utils/shell.py
@@ -32,12 +32,13 @@ import hashlib
import urllib2
from distutils.version import StrictVersion
-from cerbero.enums import Platform
+from cerbero.enums import CERBERO_VERSION, Platform
from cerbero.utils import _, system_info, to_unixpath
from cerbero.utils import messages as m
from cerbero.errors import FatalError
+USER_AGENT = 'GStreamer Cerbero/' + CERBERO_VERSION
PATCH = 'patch'
TAR = 'tar'
@@ -222,7 +223,7 @@ def download_wget(url, destination=None, recursive=False, check_cert=True, overw
@param destination: destination where the file will be saved
@type destination: str
'''
- cmd = "wget %s " % url
+ cmd = "wget --user-agent '{}' {} ".format(USER_AGENT, url)
path = None
if recursive:
cmd += "-r "
@@ -291,7 +292,9 @@ def download_urllib2(url, destination=None, recursive=False, check_cert=True, ov
try:
logging.info(destination)
with open(destination, 'wb') as d:
- f = urllib2.urlopen(url, context=ctx)
+ req = urllib2.Request(url)
+ req.add_header('User-Agent', USER_AGENT)
+ f = urllib2.urlopen(req, context=ctx)
d.write(f.read())
except urllib2.HTTPError, e:
if os.path.exists(destination):
@@ -312,7 +315,7 @@ def download_curl(url, destination=None, recursive=False, check_cert=True, overw
if recursive:
raise FatalError(_("cURL doesn't support recursive downloads"))
- cmd = "curl -L --fail "
+ cmd = "curl -L --fail --retry 2 --user-agent '{}' ".format(USER_AGENT)
if not check_cert:
cmd += " -k "
if destination is not None:
diff --git a/setup.py b/setup.py
index 162b13ff..cd661d28 100644
--- a/setup.py
+++ b/setup.py
@@ -4,6 +4,7 @@ import shutil
from setuptools import setup, find_packages
from setuptools.command import sdist as setuptools_sdist
from cerbero.utils import shell
+from cerbero.enums import CERBERO_VERSION
from distutils.dir_util import copy_tree
import distutils.log
@@ -127,7 +128,7 @@ class extended_sdist(setuptools_sdist.sdist):
setup(
name = "cerbero",
- version = '1.14.5',
+ version = CERBERO_VERSION,
author = "Andoni Morales",
author_email = "amorales@fluendo.com",
description = ("Multi platform build system for Open Source projects"),