/
io.py
60 lines (44 loc) · 1.35 KB
/
io.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from __future__ import print_function
import os
import sys
import click
from galaxy.tools.deps import commands
from galaxy.tools.deps.commands import which
def shell(cmds, **kwds):
info(cmds)
return commands.shell(cmds, **kwds)
def info(message, *args):
if args:
message = message % args
_echo(click.style(message, bold=True, fg='green'))
def can_write_to_path(path, **kwds):
if not kwds["force"] and os.path.exists(path):
error("%s already exists, exiting." % path)
return False
return True
def error(message, *args):
if args:
message = message % args
_echo(click.style(message, bold=True, fg='red'), err=True)
def warn(message, *args):
if args:
message = message % args
_echo(click.style(message, fg='red'), err=True)
def _echo(message, err=False):
if sys.version_info[0] == 2:
click.echo(message, err=err)
else:
print(message)
def untar_to(url, path, tar_args):
if which("wget"):
download_cmd = "wget -q --recursive -O - '%s'"
else:
download_cmd = "curl '%s'"
download_cmd = download_cmd % url
if tar_args:
if not os.path.exists(path):
os.makedirs(path)
untar_cmd = "tar %s" % tar_args
shell("%s | %s" % (download_cmd, untar_cmd))
else:
shell("%s > '%s'" % (download_cmd, path))