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

Trackhub S3 Integration #13

Open
wants to merge 4 commits 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: 1 addition & 1 deletion trackhub/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def _check_name(name):
regex = re.compile('[^a-zA-Z0-9-_]')
regex = re.compile('[^a-zA-Z0-9-_.]')
if regex.search(name):
raise ValueError('Non-alphanumeric character in name "%s"' % name)

Expand Down
37 changes: 29 additions & 8 deletions trackhub/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
from fabric.api import local, settings, run, abort, cd, env, hide, put
from fabric.contrib.console import confirm
import track
import boto
from boto.s3.key import Key


def upload_s3(local_fn, remote_fn, **kwargs):
s3 = boto.connect_s3()
bucket = s3.get_bucket("sauron-yeo")
k = Key(bucket)
k.key = remote_fn
k.set_contents_from_filename(local_fn)
k.make_public()
return ["done"]


def upload_file(host, user, local_fn, remote_fn, port=22,
rsync_options='-azvr --progress', run_local=False):
Expand Down Expand Up @@ -33,15 +46,18 @@ def upload_file(host, user, local_fn, remote_fn, port=22,


def upload_hub(host, user, hub, port=22, rsync_options='-azvr --progress',
run_local=False):
run_local=False, run_s3=False):
kwargs = dict(host=host, user=user, port=port, rsync_options=rsync_options,
run_local=run_local)
print kwargs
results = []

if run_s3:
cur_upload_file = upload_s3
else:
cur_upload_file = upload_file
# First the hub file:
results.extend(
upload_file(
cur_upload_file(
local_fn=hub.local_fn,
remote_fn=hub.remote_fn,
**kwargs)
Expand All @@ -50,7 +66,7 @@ def upload_hub(host, user, hub, port=22, rsync_options='-azvr --progress',
# Then the genomes file:
print hub.genomes_file.local_fn
results.extend(
upload_file(
cur_upload_file(
local_fn=hub.genomes_file.local_fn,
remote_fn=hub.genomes_file.remote_fn,
**kwargs)
Expand All @@ -59,7 +75,7 @@ def upload_hub(host, user, hub, port=22, rsync_options='-azvr --progress',
# then the trackDB file:
for g in hub.genomes_file.genomes:
results.extend(
upload_file(
cur_upload_file(
local_fn=g.trackdb.local_fn,
remote_fn=g.trackdb.remote_fn,
**kwargs
Expand All @@ -70,7 +86,7 @@ def upload_hub(host, user, hub, port=22, rsync_options='-azvr --progress',
print repr(t)
if t._html:
results.extend(
upload_file(
cur_upload_file(
local_fn=t._html.local_fn,
remote_fn=t._html.remote_fn,
**kwargs)
Expand All @@ -79,11 +95,16 @@ def upload_hub(host, user, hub, port=22, rsync_options='-azvr --progress',


def upload_track(host, user, track, port=22, rsync_options='-azvr --progress',
run_local=False):
run_local=False, run_s3=False):

if run_s3:
cur_upload_file = upload_s3
else:
cur_upload_file = upload_file
kwargs = dict(host=host, user=user, local_fn=track.local_fn,
remote_fn=track.remote_fn, rsync_options=rsync_options,
run_local=run_local)
results = upload_file(**kwargs)
results = cur_upload_file(**kwargs)
if track.tracktype == 'bam':
kwargs['local_fn'] += '.bai'
kwargs['remote_fn'] += '.bai'
Expand Down