skia2/bin/fetch-clang-format
Kevin Lubick add9e135dd Reland "[infra] Remove old python scripts and urllib2 references"
This is a reland of commit 167e608bb3

Original change's description:
> [infra] Remove old python scripts and urllib2 references
>
> I was searching for urllib2 while resolving issues with
> https://skia-review.googlesource.com/c/skia/+/538636
> when I found several old, apparently unused scripts.
>
> Rather than fix them, let's get rid of them. If they
> are still in use, the conversion to urllib.request is
> pretty easy.
>
> Change-Id: I27d419601e81c93a3d53e280188a379dfab927c4
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/538936
> Auto-Submit: Kevin Lubick <kjlubick@google.com>
> Commit-Queue: Kevin Lubick <kjlubick@google.com>
> Commit-Queue: Ravi Mistry <rmistry@google.com>
> Reviewed-by: Ravi Mistry <rmistry@google.com>

Change-Id: I656b45cbcbde61c45d6d9daa0d6b97324d738631
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541077
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Ravi Mistry <rmistry@google.com>
Reviewed-by: Ravi Mistry <rmistry@google.com>
Auto-Submit: Kevin Lubick <kjlubick@google.com>
2022-05-16 20:15:49 +00:00

53 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright 2017 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import hashlib
import os
import shutil
import stat
import sys
if sys.version_info[0] < 3:
from urllib2 import urlopen
else:
from urllib.request import urlopen
os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
def fetch(target):
target_path = 'buildtools/linux64/' + target if 'linux' in sys.platform else \
'buildtools/mac/' + target if 'darwin' in sys.platform else \
'buildtools/win/'+ target + '.exe'
sha1_path = target_path + '.sha1'
if not os.path.exists(sha1_path):
print(sha1_path, 'is missing. Did you run `tools/git-sync-deps`?')
exit(1)
sha1 = open(sha1_path).read().strip()
def sha1_of_file(path):
h = hashlib.sha1()
if os.path.isfile(path):
with open(path, 'rb') as f:
h.update(f.read())
return h.hexdigest()
if sha1_of_file(target_path) != sha1:
with open(target_path, 'wb') as f:
url = 'https://chromium-%s.storage-download.googleapis.com/%s' % (target, sha1)
f.write(urlopen(url).read())
os.chmod(target_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
stat.S_IRGRP | stat.S_IXGRP |
stat.S_IROTH | stat.S_IXOTH )
target_copy_path = os.path.join('bin', os.path.basename(target_path))
if sha1_of_file(target_copy_path) != sha1:
shutil.copy(target_path, target_copy_path)
fetch('clang-format')