-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathutil.py
59 lines (46 loc) · 1.81 KB
/
util.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
from string import Template
from time import strftime
import os
from fabric.api import local, sudo, env, put, get
from fabric.contrib.files import exists, append
def setup_install_dir():
"""Sets up install dir and ensures its owned by Galaxy"""
if not exists(env.install_dir):
sudo("mkdir -p %s" % env.install_dir)
if not exists(env.jars_dir):
sudo("mkdir -p %s" % env.jars_dir)
# TODO: Fix bug here
chown_galaxy(os.path.split(env.install_dir)[0])
def eval_template(env, template_str):
props = {
"env": env,
"the_date": strftime('%Y%m%d'),
"the_date_with_time": strftime('%Y%m%d_%H%M%S'),
}
return Template(template_str).safe_substitute(props)
def ensure_can_sudo_into(user):
sudoers_append("%admin ALL = (" + user + ") NOPASSWD: ALL")
def sudoers_append(line):
append("/etc/sudoers", line, use_sudo=True)
def start_service(service_name):
# For reasons I don't understand this doesn't work for galaxy init
# script unless pty=False
sudo("/etc/init.d/%s start" % service_name, pty=False)
def wget(url, install_command=sudo, file_name=None):
if not file_name:
file_name = os.path.split(url)[-1]
if '?' in file_name:
file_name = file_name[0:file_name.index('?')]
if ("cache_source_downloads" in env) and (not env.cache_source_downloads):
install_command("wget %s -O %s" % (url, file_name))
else:
cache_dir = env.source_cache_dir
if not cache_dir:
cache_dir = ".downloads"
cached_file = os.path.join(cache_dir, file_name)
if os.path.exists(cached_file):
put(cached_file, file_name)
else:
install_command("wget %s -O %s" % (url, file_name))
local("mkdir -p '%s'" % cache_dir)
get(file_name, cached_file)