Created
September 23, 2016 15:56
-
-
Save wckdouglas/9ae438d4867ce0de64c6d46c5b74b0f7 to your computer and use it in GitHub Desktop.
[UT GSAF] Check if sequencing job is done and download it if it is. Sed text message to notify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| from twilio.rest import TwilioRestClient | |
| import paramiko | |
| import os | |
| import sys | |
| import time | |
| def sendMessage(job): | |
| #twilio | |
| twilio_account_sid = '' | |
| twilio_auth_token = '' | |
| client = TwilioRestClient(twilio_account_sid, twilio_auth_token) | |
| client.messages.create( | |
| to = '', | |
| from_ = '', | |
| body = 'Downloaded %s' %job, | |
| ) | |
| return 0 | |
| def makedir(directory): | |
| if not os.path.isdir(directory): | |
| os.mkdir(directory) | |
| return 0 | |
| def checkProject(run_number, job_number): | |
| client = paramiko.SSHClient() | |
| user_name = '' | |
| fourierseq = 'fourierseq.icmb.utexas.edu' | |
| key_file = '/.ssh/id_rsa.pub' | |
| raw_run_path = '/raid/jcruz/corral/' | |
| local_storage = '' | |
| client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
| client.connect(fourierseq, username=user_name, key_filename = key_file) | |
| sftp = client.open_sftp() | |
| print 'Connected %s' %(fourierseq) | |
| runs = sftp.listdir(raw_run_path) | |
| if run_number in runs: | |
| projects = sftp.listdir(raw_run_path + '/%s' %run_number) | |
| for job in job_number: | |
| project_name = 'Project_' + job | |
| if project_name in projects: | |
| remote_path = '%s/%s/%s' %(raw_run_path,run_number,project_name) | |
| local_path = '%s/%s' %(local_storage, job) | |
| makedir(local_path) | |
| for filename in sftp.listdir(remote_path): | |
| remote_name = remote_path + '/' + filename | |
| local_name = local_path + '/' + filename | |
| if not os.path.isfile(local_name): | |
| print 'Downloading %s to %s...' %(filename,local_path) | |
| sftp.get(remote_name, local_name, callback=None) | |
| sendMessage(job) | |
| else: | |
| hour = time.strftime("%H:%M:%S") | |
| date = time.strftime("%d/%m/%Y") | |
| print '%s %s\t%s not finish' %(date, hour, run_number) | |
| return 0 | |
| def main(): | |
| arguments = sys.argv | |
| if len(arguments) < 3: | |
| sys.exit('python %s <run_number> <job_number1> <job_number2> ...' %(arguments[0])) | |
| run_number = arguments[1] | |
| job_number = arguments[2:] | |
| print 'Checking %s from %s' %(','.join(job_number), run_number) | |
| checkProject(run_number, job_number) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment