Mercurial > repos > geert-vandeweyer > files_to_ftp
annotate DownloadFiles.py @ 2:837fafa672d2 draft
common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
author | geert-vandeweyer |
---|---|
date | Tue, 07 May 2013 09:02:02 -0400 |
parents | 47070a3859df |
children | fe42761670f1 |
rev | line source |
---|---|
1 | 1 #!/usr/bin/env python |
2 #by Geert Vandeweyer. | |
3 | |
4 #from galaxy import eggs | |
5 import sys, os | |
6 import os.path | |
7 import datetime | |
8 | |
9 def stop_err(msg): | |
10 sys.stderr.write(msg) | |
11 sys.exit() | |
12 | |
13 def __main__(): | |
14 htmloutfile = sys.argv[1] | |
15 useremail = sys.argv[2] | |
16 folder = sys.argv[3] | |
17 ftpdirconfig = sys.argv[4] | |
18 try: | |
19 fout = open(sys.argv[1],'w') | |
20 except: | |
21 stop_err("Output file cannot be opened for writing.") | |
22 | |
23 if len(sys.argv) < 5: | |
24 stop_err("No datafiles specified!"); | |
25 | |
26 # write header to outfile | |
27 fout.write("<html><body><h2>Files copied to your FTP account.</h2>") | |
28 filecounter = 5 | |
29 fout.write("<p><ol> ") | |
30 now = datetime.datetime.now() | |
31 date=str(now)[:10] | |
2
837fafa672d2
common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents:
1
diff
changeset
|
32 #fout.write("<li>%s</li>" %(len(sys.argv))) |
1 | 33 # compose ftp storage location |
34 ftpdir="%s/%s/" %(ftpdirconfig,useremail) | |
35 if len(folder) == 0: | |
36 subdir = date | |
37 storedir="%s/%s/%s/" %(ftpdirconfig,useremail,date) | |
38 else: | |
39 storedir="%s/%s/%s/" %(ftpdirconfig,useremail,folder) | |
40 subdir = folder | |
41 if not os.path.exists(ftpdir): | |
42 os.makedirs(ftpdir) | |
43 if not os.path.exists(storedir): | |
44 os.makedirs(storedir) | |
45 | |
46 while filecounter < len(sys.argv): | |
47 inp = sys.argv[filecounter] | |
48 name = sys.argv[(filecounter+1)] | |
2
837fafa672d2
common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents:
1
diff
changeset
|
49 name = name.replace(':','_') |
837fafa672d2
common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents:
1
diff
changeset
|
50 name = name.replace(' ','_') |
837fafa672d2
common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents:
1
diff
changeset
|
51 name = name.replace('@','_AT_') |
1 | 52 ext = sys.argv[(filecounter+2)] |
53 # copy files to tmp dir & filenames | |
54 os.system("cp '%s' '%s/%s.%s'" %(inp, storedir,name,ext)) | |
2
837fafa672d2
common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents:
1
diff
changeset
|
55 ## gzip if fastq/fastqsanger/vcf |
837fafa672d2
common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents:
1
diff
changeset
|
56 if ( ext == "fastq" or ext == "fastqsanger" or ext == "vcf" or ext == "sam" or ext == "txt"): |
837fafa672d2
common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents:
1
diff
changeset
|
57 os.system("gzip -9 '%s/%s.%s'" %(storedir,name,ext)) |
1 | 58 fout.write("<li>%s.%s</li>" %(name,ext)) |
59 filecounter +=3 | |
60 | |
61 fout.write("</ol></p>") | |
62 fout.write("<p>Info: Files written to the '%s' subdirectory in your FTP account</p></body></html>" %(subdir)) | |
63 # close file | |
64 fout.close | |
65 | |
66 | |
67 if __name__ == "__main__": __main__() | |
68 |