Mercurial > repos > geert-vandeweyer > files_to_ftp
comparison DownloadFiles.py @ 1:47070a3859df draft
Uploaded
author | geert-vandeweyer |
---|---|
date | Thu, 10 Jan 2013 04:09:38 -0500 |
parents | |
children | 837fafa672d2 |
comparison
equal
deleted
inserted
replaced
0:272bdc723756 | 1:47070a3859df |
---|---|
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] | |
32 fout.write("<li>%s</li>" %(len(sys.argv))) | |
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)] | |
49 ext = sys.argv[(filecounter+2)] | |
50 # copy files to tmp dir & filenames | |
51 os.system("cp '%s' '%s/%s.%s'" %(inp, storedir,name,ext)) | |
52 fout.write("<li>%s.%s</li>" %(name,ext)) | |
53 filecounter +=3 | |
54 | |
55 fout.write("</ol></p>") | |
56 fout.write("<p>Info: Files written to the '%s' subdirectory in your FTP account</p></body></html>" %(subdir)) | |
57 # close file | |
58 fout.close | |
59 | |
60 | |
61 if __name__ == "__main__": __main__() | |
62 |