{"action":"created","comment":{"url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/comments/86739140","pull_request_review_id":7380777,"id":86739140,"diff_hunk":"@@ -0,0 +1,170 @@\n+\"\"\" \n+    Module for controlling deliveries os samples and projects to castor (THE castor!!!!)\n+\"\"\"\n+\n+import paramiko\n+import getpass\n+import glob\n+import time\n+\n+\n+from deliver import *\n+\n+\n+## cehcks if a file/folder exists in the remote location\n+## http://stackoverflow.com/questions/850749/check-whether-a-path-exists-on-a-remote-host-using-paramiko\n+def rexists(sftp, path):\n+    \"\"\"os.path.exists for paramiko's SCP object\n+    \"\"\"\n+    try:\n+        sftp.stat(path)\n+    except IOError, e:\n+        if 'No such file' in str(e):\n+            return False\n+        raise\n+    else:\n+        return True\n+\n+\n+class CastorProjectDeliverer(ProjectDeliverer):\n+    \"\"\" This object takes care of delivering project samples to castor's wharf.\n+    \"\"\"\n+    def __init__(self, projectid=None, sampleid=None, **kwargs):\n+        super(CastorProjectDeliverer, self).__init__(\n+            projectid,\n+            sampleid,\n+            **kwargs)\n+        # castor specific fields\n+        self.castordeliverypath = getattr(self, 'castordeliverypath', None)\n+        self.castorsftpserver = getattr(self, 'castorsftpserver', None)\n+        self.castorsftpserver_user = getattr(self, 'castorsftpserver_user', None)\n+    \n+\n+    def deliver_project(self):\n+        \"\"\" Deliver all samples in a project to castor\n+            \n+            :returns: True if all samples were delivered successfully, False if\n+                any sample was not properly delivered or ready to be delivered\n+        \"\"\"\n+        try:\n+            logger.info(\"Delivering {} to {}\".format(\n+                str(self), self.expand_path(self.castordeliverypath)))\n+            if self.get_delivery_status() == 'DELIVERED' \\\n+                    and not self.force:\n+                logger.info(\"{} has already been delivered\".format(str(self)))\n+                return True\n+            # right now, don't catch any errors since we're assuming any thrown\n+            # errors needs to be handled by manual intervention\n+            status = True\n+            # Open sftp session with castor, in this way multiple tranfer will be possible\n+            try:\n+                transport=paramiko.Transport(self.castorsftpserver)\n+                password = getpass.getpass(prompt='Bianca/Castor Password for user {}:'.format(self.castorsftpserver_user))\n+                transport.connect(username = \"{}-{}\".format(self.castorsftpserver_user, self.uppnexid), password = password)\n+            except Exception as e:\n+                logger.error(\"Caught exception: {}: {}\".format(e.__class__, e))\n+                raise\n+\n+            #memorize all samples that needs to be delivered\n+            samples_to_deliver = [sentry['sampleid'] for sentry in db.project_sample_entries(\n+                    db.dbcon(), self.projectid).get('samples', [])]\n+            status = True\n+            #open the sftp client\n+            #sftp_client = transport.open_sftp_client()\n+            sftp_client = MySFTPClient.from_transport(transport)\n+            # move to the delivery directory in the sftp\n+            #open one client session and leave it open for all the time of the transfer\n+            sftp_client.chdir(self.expand_path(self.castordeliverypath))\n+            #create the project folder in the remote server\n+            if not rexists(sftp_client, self.projectid):","path":"taca_ngi_pipeline/deliver/deliver_castor.py","position":79,"original_position":79,"commit_id":"9c3ef16ee871b83c4aef8362c6f8cb83d06c6674","original_commit_id":"9c3ef16ee871b83c4aef8362c6f8cb83d06c6674","user":{"login":"b97pla","id":886632,"avatar_url":"https://avatars.githubusercontent.com/u/886632?v=3","gravatar_id":"","url":"https://api.github.com/users/b97pla","html_url":"https://github.com/b97pla","followers_url":"https://api.github.com/users/b97pla/followers","following_url":"https://api.github.com/users/b97pla/following{/other_user}","gists_url":"https://api.github.com/users/b97pla/gists{/gist_id}","starred_url":"https://api.github.com/users/b97pla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b97pla/subscriptions","organizations_url":"https://api.github.com/users/b97pla/orgs","repos_url":"https://api.github.com/users/b97pla/repos","events_url":"https://api.github.com/users/b97pla/events{/privacy}","received_events_url":"https://api.github.com/users/b97pla/received_events","type":"User","site_admin":false},"body":"is this necessary, doesn't your implementation of the client handle this?","created_at":"2016-11-07T09:40:06Z","updated_at":"2016-11-07T09:40:06Z","html_url":"https://github.com/SciLifeLab/taca-ngi-pipeline/pull/26#discussion_r86739140","pull_request_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/26","_links":{"self":{"href":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/comments/86739140"},"html":{"href":"https://github.com/SciLifeLab/taca-ngi-pipeline/pull/26#discussion_r86739140"},"pull_request":{"href":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/26"}}},"pull_request":{"url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/26","id":92138495,"html_url":"https://github.com/SciLifeLab/taca-ngi-pipeline/pull/26","diff_url":"https://github.com/SciLifeLab/taca-ngi-pipeline/pull/26.diff","patch_url":"https://github.com/SciLifeLab/taca-ngi-pipeline/pull/26.patch","issue_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/issues/26","number":26,"state":"open","locked":false,"title":"Data Delivery to Bianca´s Wharf","user":{"login":"vezzi","id":1209695,"avatar_url":"https://avatars.githubusercontent.com/u/1209695?v=3","gravatar_id":"","url":"https://api.github.com/users/vezzi","html_url":"https://github.com/vezzi","followers_url":"https://api.github.com/users/vezzi/followers","following_url":"https://api.github.com/users/vezzi/following{/other_user}","gists_url":"https://api.github.com/users/vezzi/gists{/gist_id}","starred_url":"https://api.github.com/users/vezzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vezzi/subscriptions","organizations_url":"https://api.github.com/users/vezzi/orgs","repos_url":"https://api.github.com/users/vezzi/repos","events_url":"https://api.github.com/users/vezzi/events{/privacy}","received_events_url":"https://api.github.com/users/vezzi/received_events","type":"User","site_admin":false},"body":"New delivery class to move via sftp data to bianca wharf.. needs more testing\r\nFor now move only projects not single samples\r\n\r\n","created_at":"2016-11-03T11:53:39Z","updated_at":"2016-11-07T09:40:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a92bc9744125de4f987696e71b7a9528194cdf3","assignee":{"login":"b97pla","id":886632,"avatar_url":"https://avatars.githubusercontent.com/u/886632?v=3","gravatar_id":"","url":"https://api.github.com/users/b97pla","html_url":"https://github.com/b97pla","followers_url":"https://api.github.com/users/b97pla/followers","following_url":"https://api.github.com/users/b97pla/following{/other_user}","gists_url":"https://api.github.com/users/b97pla/gists{/gist_id}","starred_url":"https://api.github.com/users/b97pla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b97pla/subscriptions","organizations_url":"https://api.github.com/users/b97pla/orgs","repos_url":"https://api.github.com/users/b97pla/repos","events_url":"https://api.github.com/users/b97pla/events{/privacy}","received_events_url":"https://api.github.com/users/b97pla/received_events","type":"User","site_admin":false},"assignees":[{"login":"b97pla","id":886632,"avatar_url":"https://avatars.githubusercontent.com/u/886632?v=3","gravatar_id":"","url":"https://api.github.com/users/b97pla","html_url":"https://github.com/b97pla","followers_url":"https://api.github.com/users/b97pla/followers","following_url":"https://api.github.com/users/b97pla/following{/other_user}","gists_url":"https://api.github.com/users/b97pla/gists{/gist_id}","starred_url":"https://api.github.com/users/b97pla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b97pla/subscriptions","organizations_url":"https://api.github.com/users/b97pla/orgs","repos_url":"https://api.github.com/users/b97pla/repos","events_url":"https://api.github.com/users/b97pla/events{/privacy}","received_events_url":"https://api.github.com/users/b97pla/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/26/commits","review_comments_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/26/comments","review_comment_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/issues/26/comments","statuses_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/statuses/9c3ef16ee871b83c4aef8362c6f8cb83d06c6674","head":{"label":"vezzi:master","ref":"master","sha":"9c3ef16ee871b83c4aef8362c6f8cb83d06c6674","user":{"login":"vezzi","id":1209695,"avatar_url":"https://avatars.githubusercontent.com/u/1209695?v=3","gravatar_id":"","url":"https://api.github.com/users/vezzi","html_url":"https://github.com/vezzi","followers_url":"https://api.github.com/users/vezzi/followers","following_url":"https://api.github.com/users/vezzi/following{/other_user}","gists_url":"https://api.github.com/users/vezzi/gists{/gist_id}","starred_url":"https://api.github.com/users/vezzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vezzi/subscriptions","organizations_url":"https://api.github.com/users/vezzi/orgs","repos_url":"https://api.github.com/users/vezzi/repos","events_url":"https://api.github.com/users/vezzi/events{/privacy}","received_events_url":"https://api.github.com/users/vezzi/received_events","type":"User","site_admin":false},"repo":{"id":52961075,"name":"taca-ngi-pipeline","full_name":"vezzi/taca-ngi-pipeline","owner":{"login":"vezzi","id":1209695,"avatar_url":"https://avatars.githubusercontent.com/u/1209695?v=3","gravatar_id":"","url":"https://api.github.com/users/vezzi","html_url":"https://github.com/vezzi","followers_url":"https://api.github.com/users/vezzi/followers","following_url":"https://api.github.com/users/vezzi/following{/other_user}","gists_url":"https://api.github.com/users/vezzi/gists{/gist_id}","starred_url":"https://api.github.com/users/vezzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vezzi/subscriptions","organizations_url":"https://api.github.com/users/vezzi/orgs","repos_url":"https://api.github.com/users/vezzi/repos","events_url":"https://api.github.com/users/vezzi/events{/privacy}","received_events_url":"https://api.github.com/users/vezzi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vezzi/taca-ngi-pipeline","description":"A TACA plugin adding functionality relevant for the ngi_pipeline","fork":true,"url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline","forks_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/forks","keys_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/teams","hooks_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/hooks","issue_events_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/issues/events{/number}","events_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/events","assignees_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/assignees{/user}","branches_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/branches{/branch}","tags_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/tags","blobs_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/git/refs{/sha}","trees_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/statuses/{sha}","languages_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/languages","stargazers_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/stargazers","contributors_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/contributors","subscribers_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/subscribers","subscription_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/subscription","commits_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/commits{/sha}","git_commits_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/git/commits{/sha}","comments_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/comments{/number}","issue_comment_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/issues/comments{/number}","contents_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/contents/{+path}","compare_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/merges","archive_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/downloads","issues_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/issues{/number}","pulls_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/pulls{/number}","milestones_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/milestones{/number}","notifications_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/labels{/name}","releases_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/releases{/id}","deployments_url":"https://api.github.com/repos/vezzi/taca-ngi-pipeline/deployments","created_at":"2016-03-02T12:28:33Z","updated_at":"2016-03-02T12:28:34Z","pushed_at":"2016-11-03T11:51:52Z","git_url":"git://github.com/vezzi/taca-ngi-pipeline.git","ssh_url":"git@github.com:vezzi/taca-ngi-pipeline.git","clone_url":"https://github.com/vezzi/taca-ngi-pipeline.git","svn_url":"https://github.com/vezzi/taca-ngi-pipeline","homepage":null,"size":200,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SciLifeLab:master","ref":"master","sha":"1b95a6387ee7addec0721fab482ed55ea2549090","user":{"login":"SciLifeLab","id":713611,"avatar_url":"https://avatars.githubusercontent.com/u/713611?v=3","gravatar_id":"","url":"https://api.github.com/users/SciLifeLab","html_url":"https://github.com/SciLifeLab","followers_url":"https://api.github.com/users/SciLifeLab/followers","following_url":"https://api.github.com/users/SciLifeLab/following{/other_user}","gists_url":"https://api.github.com/users/SciLifeLab/gists{/gist_id}","starred_url":"https://api.github.com/users/SciLifeLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SciLifeLab/subscriptions","organizations_url":"https://api.github.com/users/SciLifeLab/orgs","repos_url":"https://api.github.com/users/SciLifeLab/repos","events_url":"https://api.github.com/users/SciLifeLab/events{/privacy}","received_events_url":"https://api.github.com/users/SciLifeLab/received_events","type":"Organization","site_admin":false},"repo":{"id":35877476,"name":"taca-ngi-pipeline","full_name":"SciLifeLab/taca-ngi-pipeline","owner":{"login":"SciLifeLab","id":713611,"avatar_url":"https://avatars.githubusercontent.com/u/713611?v=3","gravatar_id":"","url":"https://api.github.com/users/SciLifeLab","html_url":"https://github.com/SciLifeLab","followers_url":"https://api.github.com/users/SciLifeLab/followers","following_url":"https://api.github.com/users/SciLifeLab/following{/other_user}","gists_url":"https://api.github.com/users/SciLifeLab/gists{/gist_id}","starred_url":"https://api.github.com/users/SciLifeLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SciLifeLab/subscriptions","organizations_url":"https://api.github.com/users/SciLifeLab/orgs","repos_url":"https://api.github.com/users/SciLifeLab/repos","events_url":"https://api.github.com/users/SciLifeLab/events{/privacy}","received_events_url":"https://api.github.com/users/SciLifeLab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SciLifeLab/taca-ngi-pipeline","description":"A TACA plugin adding functionality relevant for the ngi_pipeline","fork":true,"url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline","forks_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/forks","keys_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/teams","hooks_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/hooks","issue_events_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/issues/events{/number}","events_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/events","assignees_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/assignees{/user}","branches_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/branches{/branch}","tags_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/tags","blobs_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/git/refs{/sha}","trees_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/statuses/{sha}","languages_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/languages","stargazers_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/stargazers","contributors_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/contributors","subscribers_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/subscribers","subscription_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/subscription","commits_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/commits{/sha}","git_commits_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/git/commits{/sha}","comments_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/comments{/number}","issue_comment_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/issues/comments{/number}","contents_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/contents/{+path}","compare_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/merges","archive_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/downloads","issues_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/issues{/number}","pulls_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls{/number}","milestones_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/milestones{/number}","notifications_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/labels{/name}","releases_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/releases{/id}","deployments_url":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/deployments","created_at":"2015-05-19T11:15:49Z","updated_at":"2016-03-23T10:29:07Z","pushed_at":"2016-11-03T11:53:39Z","git_url":"git://github.com/SciLifeLab/taca-ngi-pipeline.git","ssh_url":"git@github.com:SciLifeLab/taca-ngi-pipeline.git","clone_url":"https://github.com/SciLifeLab/taca-ngi-pipeline.git","svn_url":"https://github.com/SciLifeLab/taca-ngi-pipeline","homepage":null,"size":198,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/26"},"html":{"href":"https://github.com/SciLifeLab/taca-ngi-pipeline/pull/26"},"issue":{"href":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/issues/26"},"comments":{"href":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/issues/26/comments"},"review_comments":{"href":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/26/comments"},"review_comment":{"href":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/pulls/26/commits"},"statuses":{"href":"https://api.github.com/repos/SciLifeLab/taca-ngi-pipeline/statuses/9c3ef16ee871b83c4aef8362c6f8cb83d06c6674"}}}}
{"actor":{"display_login":"b97pla"}}