|
a |
|
b/scripts/qiita-private-launcher |
|
|
1 |
#!/usr/bin/env python |
|
|
2 |
|
|
|
3 |
# ----------------------------------------------------------------------------- |
|
|
4 |
# Copyright (c) 2014--, The Qiita Development Team. |
|
|
5 |
# |
|
|
6 |
# Distributed under the terms of the BSD 3-clause License. |
|
|
7 |
# |
|
|
8 |
# The full license is in the file LICENSE, distributed with this software. |
|
|
9 |
# ----------------------------------------------------------------------------- |
|
|
10 |
|
|
|
11 |
from subprocess import Popen, PIPE |
|
|
12 |
from os import close, remove |
|
|
13 |
from tempfile import mkstemp |
|
|
14 |
|
|
|
15 |
import click |
|
|
16 |
|
|
|
17 |
# When Popen executes, the shell is not in interactive mode, |
|
|
18 |
# so it is not sourcing any of the bash configuration files |
|
|
19 |
# We need to source it so the env_script are available |
|
|
20 |
SCRIPT = """#!/bin/bash |
|
|
21 |
|
|
|
22 |
source ~/.bash_profile |
|
|
23 |
%s |
|
|
24 |
%s |
|
|
25 |
""" |
|
|
26 |
|
|
|
27 |
|
|
|
28 |
@click.command() |
|
|
29 |
@click.argument('qiita_env', required=True, nargs=1) |
|
|
30 |
@click.argument('command', required=True, nargs=1) |
|
|
31 |
@click.argument('arguments', required=True, nargs=-1) |
|
|
32 |
def start(qiita_env, command, arguments): |
|
|
33 |
"""Starts the plugin environment""" |
|
|
34 |
cmd = ['qiita-private', command] |
|
|
35 |
cmd.extend(["'%s'" % arg for arg in arguments]) |
|
|
36 |
fd, fp = mkstemp(suffix=".sh") |
|
|
37 |
close(fd) |
|
|
38 |
with open(fp, 'w') as f: |
|
|
39 |
f.write(SCRIPT % (qiita_env, ' '.join(cmd))) |
|
|
40 |
cmd = "bash %s" % fp |
|
|
41 |
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) |
|
|
42 |
stdout, stderr = proc.communicate() |
|
|
43 |
remove(fp) |
|
|
44 |
if proc.returncode and proc.returncode != 0: |
|
|
45 |
raise ValueError( |
|
|
46 |
"Error launching internal task:\n\tStdout: %s\n\tStderr: %s" |
|
|
47 |
% (stdout, stderr)) |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
if __name__ == '__main__': |
|
|
51 |
start() |