Mercurial > repos > geert-vandeweyer > files_to_ftp
view DownloadFiles.py @ 1:47070a3859df draft
Uploaded
author | geert-vandeweyer |
---|---|
date | Thu, 10 Jan 2013 04:09:38 -0500 |
parents | |
children | 837fafa672d2 |
line wrap: on
line source
#!/usr/bin/env python #by Geert Vandeweyer. #from galaxy import eggs import sys, os import os.path import datetime def stop_err(msg): sys.stderr.write(msg) sys.exit() def __main__(): htmloutfile = sys.argv[1] useremail = sys.argv[2] folder = sys.argv[3] ftpdirconfig = sys.argv[4] try: fout = open(sys.argv[1],'w') except: stop_err("Output file cannot be opened for writing.") if len(sys.argv) < 5: stop_err("No datafiles specified!"); # write header to outfile fout.write("<html><body><h2>Files copied to your FTP account.</h2>") filecounter = 5 fout.write("<p><ol> ") now = datetime.datetime.now() date=str(now)[:10] fout.write("<li>%s</li>" %(len(sys.argv))) # compose ftp storage location ftpdir="%s/%s/" %(ftpdirconfig,useremail) if len(folder) == 0: subdir = date storedir="%s/%s/%s/" %(ftpdirconfig,useremail,date) else: storedir="%s/%s/%s/" %(ftpdirconfig,useremail,folder) subdir = folder if not os.path.exists(ftpdir): os.makedirs(ftpdir) if not os.path.exists(storedir): os.makedirs(storedir) while filecounter < len(sys.argv): inp = sys.argv[filecounter] name = sys.argv[(filecounter+1)] ext = sys.argv[(filecounter+2)] # copy files to tmp dir & filenames os.system("cp '%s' '%s/%s.%s'" %(inp, storedir,name,ext)) fout.write("<li>%s.%s</li>" %(name,ext)) filecounter +=3 fout.write("</ol></p>") fout.write("<p>Info: Files written to the '%s' subdirectory in your FTP account</p></body></html>" %(subdir)) # close file fout.close if __name__ == "__main__": __main__()