summaryrefslogtreecommitdiffstats
path: root/build/scripts/fetch_from.py
diff options
context:
space:
mode:
authoriaz1607 <[email protected]>2023-11-30 12:16:39 +0300
committeriaz1607 <[email protected]>2023-11-30 12:56:46 +0300
commit8951ddf780e02616cdb2ec54a02bc354e8507c0f (patch)
tree478097488957d3b554e25868c972a959bb40d78e /build/scripts/fetch_from.py
parenta5acb7aa4ca5a4603215e878eb0cad786793262b (diff)
`build/scripts` ya style --py
Diffstat (limited to 'build/scripts/fetch_from.py')
-rwxr-xr-xbuild/scripts/fetch_from.py69
1 files changed, 37 insertions, 32 deletions
diff --git a/build/scripts/fetch_from.py b/build/scripts/fetch_from.py
index b6ea7cefa15..2ebe6f0e515 100755
--- a/build/scripts/fetch_from.py
+++ b/build/scripts/fetch_from.py
@@ -25,10 +25,18 @@ def add_common_arguments(parser):
parser.add_argument('--rename-to') # used by test_node in inject_mds_resource_to_graph
parser.add_argument('--copy-to-dir')
parser.add_argument('--untar-to')
- parser.add_argument('--rename', action='append', default=[], metavar='FILE', help='rename FILE to the corresponding output')
+ parser.add_argument(
+ '--rename', action='append', default=[], metavar='FILE', help='rename FILE to the corresponding output'
+ )
parser.add_argument('--executable', action='store_true', help='make outputs executable')
parser.add_argument('--log-path')
- parser.add_argument('-v', '--verbose', action='store_true', default=os.environ.get('YA_VERBOSE_FETCHER'), help='increase stderr verbosity')
+ parser.add_argument(
+ '-v',
+ '--verbose',
+ action='store_true',
+ default=os.environ.get('YA_VERBOSE_FETCHER'),
+ help='increase stderr verbosity',
+ )
parser.add_argument('outputs', nargs='*', default=[])
@@ -50,7 +58,9 @@ def hardlink_or_copy(src, dst):
if e.errno == errno.EEXIST:
return
elif e.errno in (errno.EXDEV, errno.EMLINK, errno.EINVAL, errno.EACCES):
- sys.stderr.write("Can't make hardlink (errno={}) - fallback to copy: {} -> {}\n".format(e.errno, src, dst))
+ sys.stderr.write(
+ "Can't make hardlink (errno={}) - fallback to copy: {} -> {}\n".format(e.errno, src, dst)
+ )
shutil.copy(src, dst)
else:
sys.stderr.write("src: {} dst: {}\n".format(src, dst))
@@ -111,7 +121,6 @@ def setup_logging(args, base_name):
def is_temporary(e):
-
def is_broken(e):
return isinstance(e, urllib2.HTTPError) and e.code in (410, 404)
@@ -140,7 +149,11 @@ def report_to_snowden(value):
urllib2.urlopen(
'https://back-snowden.qloud.yandex-team.ru/report/add',
- json.dumps([body, ]),
+ json.dumps(
+ [
+ body,
+ ]
+ ),
timeout=5,
)
@@ -151,7 +164,7 @@ def report_to_snowden(value):
def copy_stream(read, *writers, **kwargs):
- chunk_size = kwargs.get('size', 1024*1024)
+ chunk_size = kwargs.get('size', 1024 * 1024)
while True:
data = read(chunk_size)
if not data:
@@ -177,7 +190,7 @@ def git_like_hash_with_size(filepath):
with open(filepath, 'rb') as f:
while True:
- block = f.read(2 ** 16)
+ block = f.read(2**16)
if not block:
break
@@ -200,7 +213,9 @@ def size_printer(display_name, size):
now = dt.datetime.now()
if last_stamp[0] + dt.timedelta(seconds=10) < now:
if size:
- print >>sys.stderr, "##status##{} - [[imp]]{:.1f}%[[rst]]".format(display_name, 100.0 * sz[0] / size if size else 0)
+ print >> sys.stderr, "##status##{} - [[imp]]{:.1f}%[[rst]]".format(
+ display_name, 100.0 * sz[0] / size if size else 0
+ )
last_stamp[0] = now
return printer
@@ -247,13 +262,7 @@ def fetch_url(url, unpack, resource_file_name, expected_md5=None, expected_sha1=
logging.info('File sha1 %s (expected %s)', real_sha1, expected_sha1)
if expected_md5 and real_md5 != expected_md5:
- report_to_snowden(
- {
- 'headers': req.headers.headers,
- 'expected_md5': expected_md5,
- 'real_md5': real_md5
- }
- )
+ report_to_snowden({'headers': req.headers.headers, 'expected_md5': expected_md5, 'real_md5': real_md5})
raise BadChecksumFetchError(
'Downloaded {}, but expected {} for {}'.format(
@@ -264,13 +273,7 @@ def fetch_url(url, unpack, resource_file_name, expected_md5=None, expected_sha1=
)
if expected_sha1 and real_sha1 != expected_sha1:
- report_to_snowden(
- {
- 'headers': req.headers.headers,
- 'expected_sha1': expected_sha1,
- 'real_sha1': real_sha1
- }
- )
+ report_to_snowden({'headers': req.headers.headers, 'expected_sha1': expected_sha1, 'real_sha1': real_sha1})
raise BadChecksumFetchError(
'Downloaded {}, but expected {} for {}'.format(
@@ -305,13 +308,15 @@ def chmod(filename, mode):
os.chmod(filename, mode)
except OSError:
import pwd
- sys.stderr.write("{} st_mode: {} pwuid: {}\n".format(filename, stat.st_mode, pwd.getpwuid(os.stat(filename).st_uid)))
+
+ sys.stderr.write(
+ "{} st_mode: {} pwuid: {}\n".format(filename, stat.st_mode, pwd.getpwuid(os.stat(filename).st_uid))
+ )
raise
def process(fetched_file, file_name, args, remove=True):
- assert len(args.rename) <= len(args.outputs), (
- 'too few outputs to rename', args.rename, 'into', args.outputs)
+ assert len(args.rename) <= len(args.outputs), ('too few outputs to rename', args.rename, 'into', args.outputs)
fetched_file_is_dir = os.path.isdir(fetched_file)
if fetched_file_is_dir and not args.untar_to:
@@ -325,7 +330,6 @@ def process(fetched_file, file_name, args, remove=True):
else:
chmod(fetched_file, 0o444)
-
if args.copy_to:
hardlink_or_copy(fetched_file, args.copy_to)
if not args.outputs:
@@ -341,7 +345,7 @@ def process(fetched_file, file_name, args, remove=True):
if args.untar_to:
ensure_dir(args.untar_to)
- inputs = set(map(os.path.normpath, args.rename + args.outputs[len(args.rename):]))
+ inputs = set(map(os.path.normpath, args.rename + args.outputs[len(args.rename) :]))
if fetched_file_is_dir:
for member in inputs:
base, name = member.split('/', 1)
@@ -349,10 +353,12 @@ def process(fetched_file, file_name, args, remove=True):
dst = os.path.normpath(os.path.join(args.untar_to, member))
hardlink_or_copy(src, dst)
else:
- # Extract only requested files
+ # Extract only requested files
try:
with tarfile.open(fetched_file, mode='r:*') as tar:
- members = [entry for entry in tar if os.path.normpath(os.path.join(args.untar_to, entry.name)) in inputs]
+ members = [
+ entry for entry in tar if os.path.normpath(os.path.join(args.untar_to, entry.name)) in inputs
+ ]
tar.extractall(args.untar_to, members=members)
except tarfile.ReadError as e:
logging.exception(e)
@@ -360,9 +366,8 @@ def process(fetched_file, file_name, args, remove=True):
# Forbid changes to the loaded resource data
for root, _, files in os.walk(args.untar_to):
- for filename in files:
- chmod(os.path.join(root, filename), 0o444)
-
+ for filename in files:
+ chmod(os.path.join(root, filename), 0o444)
for src, dst in zip(args.rename, args.outputs):
if src == 'RESOURCE':