mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-04-20 04:12:42 +00:00
Download to tmp file then move to dst.
This commit is contained in:
parent
8f0df03e30
commit
dfe2e4f217
19
stackage.py
19
stackage.py
@ -6,6 +6,7 @@
|
|||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import requests
|
import requests
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
@ -23,22 +24,20 @@ class StackageSession(object):
|
|||||||
print('{} exists, skipping'.format(file_path), flush=True)
|
print('{} exists, skipping'.format(file_path), flush=True)
|
||||||
else:
|
else:
|
||||||
args = [
|
args = [
|
||||||
'aria2c', url, '--dir={}'.format(dir_path),
|
'aria2c', url, '--dir={}'.format(dir_path), '--out={}.tmp'.format(url.split('/')[-1]),
|
||||||
'--file-allocation=none', '--quiet=true',
|
'--file-allocation=none', '--quiet=true'
|
||||||
]
|
]
|
||||||
if sha1:
|
if sha1:
|
||||||
args.append('--checksum=sha-1={}'.format(sha1))
|
args.append('--checksum=sha-1={}'.format(sha1))
|
||||||
if subprocess.run(args).returncode != 0 and file_path.is_file():
|
subprocess.run(args, check=True)
|
||||||
file_path.unlink()
|
shutil.move('{}.tmp'.format(file_path), file_path)
|
||||||
raise OSError('Download failed for {}'.format(url))
|
print('Downloaded {} to {}'.format(url, file_path), flush=True)
|
||||||
else:
|
|
||||||
print('Downloaded {} to {}'.format(url, file_path), flush=True)
|
|
||||||
|
|
||||||
def load_stack_setup(self):
|
def load_stack_setup(self):
|
||||||
d = yaml.load(
|
d = yaml.load(
|
||||||
requests
|
requests
|
||||||
.get('https://raw.githubusercontent.com/fpco/stackage-content/master/stack/stack-setup-2.yaml')
|
.get('https://raw.githubusercontent.com/fpco/stackage-content/master/stack/stack-setup-2.yaml')
|
||||||
.content
|
.content
|
||||||
)
|
)
|
||||||
for platform in d['ghc']:
|
for platform in d['ghc']:
|
||||||
for ver in d['ghc'][platform]:
|
for ver in d['ghc'][platform]:
|
||||||
@ -49,7 +48,7 @@ class StackageSession(object):
|
|||||||
)
|
)
|
||||||
d['ghc'][platform][ver]['url'] = (
|
d['ghc'][platform][ver]['url'] = (
|
||||||
'http://mirrors.tuna.tsinghua.edu.cn/stackage/ghc/{}'
|
'http://mirrors.tuna.tsinghua.edu.cn/stackage/ghc/{}'
|
||||||
.format(d['ghc'][platform][ver]['url'].split('/')[-1])
|
.format(d['ghc'][platform][ver]['url'].split('/')[-1])
|
||||||
)
|
)
|
||||||
|
|
||||||
d['msys2'] = {
|
d['msys2'] = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user