-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpostIt.py
executable file
·96 lines (75 loc) · 3.13 KB
/
postIt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
# -*- coding: utf-8 -*-
from leader import *
config = load_config()
import sys
def percent_cb(complete, total):
sys.stdout.write('.')
sys.stdout.flush()
import time
startTime = time.time()
import boto.sns
sns_conn = boto.sns.connect_to_region(aws_access_key_id=config.access_key,
aws_secret_access_key=config.secret_key,
region_name='us-east-1')
import boto.s3.connection
from boto.s3.bucket import Bucket
from boto.s3.key import Key
conn = boto.connect_s3(aws_access_key_id=config.access_key,
aws_secret_access_key=config.secret_key,
calling_format=boto.s3.connection.OrdinaryCallingFormat())
# host = 'objects.dreamhost.com',
# host = 's3.amazonaws.com' default
# is_secure=False, # uncommmnt if you are not using ssl
uploadedHTML = 0
uploadedHTMLSize = 0
uploadedZIP = 0
uploadedZIPSize = 0
print 'All Buckets'
for bucket in conn.get_all_buckets():
print '{name}\t{created}'.format(name=bucket.name,created=bucket.creation_date)
dopt = Bucket(conn, name='dopt')
k = Key(dopt)
#print 'Files in HTML Bucket'
#for key in dopt.list():
# print '{name}\t{size}\t{modified}'.format(name=key.name, size=key.size, modified=key.last_modified)
#print ''
print 'Starting Upload to HTML Bucket'
import os
for (dirpath, dnames, fnames) in os.walk('./'):
if 'bin' not in dirpath:
for f in fnames:
# print dirpath, dnames, f
if f.endswith('.html') or f.endswith('.css') or f.endswith('.ico') or f.endswith('.png') or f.endswith('.pdf'):
fileName = os.path.join(dirpath, f)
remoteLocation = config.session_id+'/'+f
print 'Uploading %s to Amazon S3 bucket %s at %s' % (f, dopt, remoteLocation)
k.key = remoteLocation
k.set_contents_from_filename(fileName, cb=percent_cb, num_cb=10)
#print ''
uploadedHTML += 1
uploadedHTMLSize += os.path.getsize(fileName)
#dopt_logs = Bucket(conn, name='dopt-logs')
#k = Key(dopt_logs)
#for (dirpath, dnames, fnames) in os.walk('./'):
# for f in fnames:
# #print dirpath, dnames, f
# if f.endswith('.zip') and f.startswith('leader_'):
# fileName = os.path.join(dirpath, f)
# remoteLocation = config.session_id+'/'+f
# print 'Uploading %s to Amazon S3 bucket %s at %s' % (f, dopt_logs, remoteLocation)
# k.key = remoteLocation
# k.set_contents_from_filename(fileName, cb=percent_cb, num_cb=10)
# print ''
# uploadedZIP += 1
# uploadedZIPSize += os.path.getsize(fileName)
# print 'deleting local copy:', fileName
# os.remove(fileName)
endTime = time.time()
subject = 'Leader Board Posted'
message = 'time: '+str(endTime-startTime)+'\n'+\
'uploaded html: '+str(uploadedHTML)+' - '+str(uploadedHTMLSize)+'\n'+\
'uploaded zip: '+str(uploadedZIP)+' - '+str(uploadedZIPSize)+'\n'
print 'subject:',subject
print 'body:',message
publication = sns_conn.publish(config.topicarn, message, subject=subject)