Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print fake shell commands. #785

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions planemo/commands/cmd_project_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from planemo import options
from planemo.cli import command_function
from planemo.io import (
info,
untar_to,
warn,
)
Expand Down Expand Up @@ -42,6 +43,7 @@ def cli(ctx, path, template=None, **kwds):
untar_args = UNTAR_ARGS % (tempdir)
untar_to(DOWNLOAD_URL, tempdir, untar_args)
template_dir = os.path.join(tempdir, template)
info("mv '%s'/* '%s'" % (template_dir, path))
for entry in os.listdir(template_dir):
shutil.move(os.path.join(template_dir, entry), path)
finally:
Expand Down
20 changes: 20 additions & 0 deletions planemo/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ def communicate(cmds, **kwds):
return output


def copy(source, dest):
info("cp '%s' '%s'" % (source, dest))
shutil.copy(source, dest)


def mkdir(path):
info("mkdir '%s'" % path)
os.mkdir(path)


def makedirs(path):
info("mkdir -p '%s'" % path)
os.makedirs(path)
Copy link
Member

@nsoranzo nsoranzo Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A slight difference between mkdir -p and os.makedirs() is that the former succeeds even if the directory already exists, while the latter fails. You may want to guard this with an if not os.path.exists(path):



def rm_rf_tree(path):
info("rm -rf '%s'" % path)
shutil.rmtree(path, ignore_errors=True)


def shell(cmds, **kwds):
if isinstance(cmds, list):
cmd_string = commands.argv_to_str(cmds)
Expand Down
12 changes: 7 additions & 5 deletions planemo/shed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json
import os
import re
import shutil
import sys
import tarfile
from collections import namedtuple
Expand All @@ -25,9 +24,12 @@
from planemo.io import (
can_write_to_path,
coalesce_return_codes,
copy as io_copy,
error,
find_matching_directories,
info,
mkdir,
rm_rf_tree,
shell,
temp_directory,
warn,
Expand Down Expand Up @@ -205,7 +207,7 @@ def shed_init(ctx, path, **kwds):
workflow_name = os.path.basename(from_workflow)
workflow_target = os.path.join(path, workflow_name)
if not os.path.exists(workflow_target):
shutil.copyfile(from_workflow, workflow_target)
io_copy(from_workflow, workflow_target)

if not can_write_to_path(repo_dependencies_path, **kwds):
return 1
Expand Down Expand Up @@ -287,7 +289,7 @@ def upload_repository(ctx, realized_repository, **kwds):
tar_path = build_tarball(path, **kwds)
if kwds.get("tar_only", False):
name = realized_repository.pattern_to_file_name("shed_upload.tar.gz")
shutil.copy(tar_path, name)
io_copy(tar_path, name)
return 0
shed_context = get_shed_context(ctx, **kwds)
update_kwds = {}
Expand Down Expand Up @@ -393,9 +395,9 @@ def _diff_in(ctx, working, realized_repository, **kwds):
)
else:
tar_path = build_tarball(path)
os.mkdir(mine)
mkdir(mine)
shell(['tar', '-xzf', tar_path, '-C', mine])
shutil.rmtree(tar_path, ignore_errors=True)
rm_rf_tree(tar_path)

output = kwds.get("output", None)
raw = kwds.get("raw", False)
Expand Down
2 changes: 1 addition & 1 deletion planemo/tool_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ def write_tool_description(ctx, tool_description, **kwds):
if tool_description.test_files:
if not os.path.exists("test-data"):
io.info("No test-data directory, creating one.")
os.makedirs('test-data')
io.makedirs('test-data')
for test_file in tool_description.test_files:
io.info("Copying test-file %s" % test_file)
try:
Expand Down