annotate DownloadFiles.py @ 1:47070a3859df draft

Uploaded
author geert-vandeweyer
date Thu, 10 Jan 2013 04:09:38 -0500
parents
children 837fafa672d2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
1 #!/usr/bin/env python
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
2 #by Geert Vandeweyer.
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
3
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
4 #from galaxy import eggs
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
5 import sys, os
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
6 import os.path
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
7 import datetime
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
8
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
9 def stop_err(msg):
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
10 sys.stderr.write(msg)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
11 sys.exit()
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
12
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
13 def __main__():
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
14 htmloutfile = sys.argv[1]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
15 useremail = sys.argv[2]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
16 folder = sys.argv[3]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
17 ftpdirconfig = sys.argv[4]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
18 try:
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
19 fout = open(sys.argv[1],'w')
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
20 except:
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
21 stop_err("Output file cannot be opened for writing.")
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
22
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
23 if len(sys.argv) < 5:
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
24 stop_err("No datafiles specified!");
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
25
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
26 # write header to outfile
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
27 fout.write("<html><body><h2>Files copied to your FTP account.</h2>")
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
28 filecounter = 5
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
29 fout.write("<p><ol> ")
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
30 now = datetime.datetime.now()
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
31 date=str(now)[:10]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
32 fout.write("<li>%s</li>" %(len(sys.argv)))
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
33 # compose ftp storage location
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
34 ftpdir="%s/%s/" %(ftpdirconfig,useremail)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
35 if len(folder) == 0:
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
36 subdir = date
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
37 storedir="%s/%s/%s/" %(ftpdirconfig,useremail,date)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
38 else:
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
39 storedir="%s/%s/%s/" %(ftpdirconfig,useremail,folder)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
40 subdir = folder
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
41 if not os.path.exists(ftpdir):
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
42 os.makedirs(ftpdir)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
43 if not os.path.exists(storedir):
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
44 os.makedirs(storedir)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
45
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
46 while filecounter < len(sys.argv):
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
47 inp = sys.argv[filecounter]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
48 name = sys.argv[(filecounter+1)]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
49 ext = sys.argv[(filecounter+2)]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
50 # copy files to tmp dir & filenames
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
51 os.system("cp '%s' '%s/%s.%s'" %(inp, storedir,name,ext))
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
52 fout.write("<li>%s.%s</li>" %(name,ext))
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
53 filecounter +=3
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
54
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
55 fout.write("</ol></p>")
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
56 fout.write("<p>Info: Files written to the '%s' subdirectory in your FTP account</p></body></html>" %(subdir))
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
57 # close file
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
58 fout.close
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
59
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
60
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
61 if __name__ == "__main__": __main__()
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
62