1 # -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
3 # Copyright (c) 2015, Thibault Saunier <thibault.saunier@collabora.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this program; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 # Boston, MA 02110-1301, USA.
26 from urllib.request import urlretrieve
27 from urllib.parse import quote
30 from launcher.config import GST_VALIDATE_TESTSUITE_VERSION
32 GST_VALIDATE_TESTSUITE_VERSION = "master"
35 last_message_length = 0
37 os.environ["GST_VALIDATE_CONFIG"] = os.path.abspath(
39 os.path.dirname(__file__), "..", "integration-testsuites.config")) + os.pathsep + os.environ.get("GST_VALIDATE_CONFIG", "")
43 if sys.stdout.isatty():
44 global last_message_length
45 print('\r' + string + ' ' * max(0, last_message_length - len(string)), end='')
46 last_message_length = len(string)
51 def sizeof_fmt(num, suffix='B'):
52 for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
54 return "%3.1f%s%s" % (num, unit, suffix)
56 return "%.1f%s%s" % (num, 'Yi', suffix)
62 def reporthook(blocknum, blocksize, totalsize):
64 readsofar = blocknum * blocksize
66 percent = readsofar * 1e2 / totalsize
67 s = "\r%s —%5.1f%% %s / %s" % (URL,
68 percent, sizeof_fmt(readsofar), sizeof_fmt(totalsize)) \
71 else: # total size is unknown
72 message("read %d" % (readsofar,))
75 def download_files(assets_dir):
76 print("Downloading %s" % assets_dir if assets_dir else "all assets")
77 fdir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
80 with open(os.path.join(fdir, 'files.json'), 'r') as f:
83 for f, ref_filesize in files:
84 if assets_dir and not f.startswith(assets_dir):
87 fname = os.path.join(fdir, f)
88 if os.path.exists(fname) and os.path.getsize(fname) == ref_filesize:
89 message('%s... OK' % fname)
92 os.makedirs(os.path.dirname(fname), exist_ok=True)
93 rpath = fname[len(fdir) + 1:]
95 URL = 'https://gstreamer.freedesktop.org/data/media/gst-integration-testsuite/' + \
97 if sys.stdout.isatty():
98 message("\rDownloading %s" % URL)
101 message("Downloading %s" % URL)
104 urlretrieve(URL, fname, hook)
105 except BaseException:
106 print("\nCould not retieved %s" % URL)
109 if os.path.getsize(fname) != ref_filesize:
110 print("ERROR: File %s expected size %s != %s, this should never happen!",
111 fname, os.path.getsize(fname), ref_filesize)
116 def update_assets(options, assets_dir):
118 if options.sync_version is not None:
119 sync_version = options.sync_version
121 sync_version = GST_VALIDATE_TESTSUITE_VERSION
122 CHECKOUT_BRANCH_COMMAND = "git fetch origin && (git checkout origin/%s || git checkout tags/%s)" % (
123 sync_version, sync_version)
124 if options.force_sync:
125 subprocess.check_call(["git", "reset", "--hard"], cwd=assets_dir)
126 print("Checking out %s" % sync_version)
127 subprocess.check_call(CHECKOUT_BRANCH_COMMAND, shell=True, cwd=assets_dir)
128 download_files(os.path.basename(os.path.join(assets_dir)))
129 except Exception as e:
130 print("\nERROR: Could not update assets \n\n: %s" % e)