import boto, os, time

def print_result(subject, action, success):
  modifier = ' not '
  if success == True:
    modifier = ' '
  print subject + modifier + action + '.'

# We want to commit all modified files to the s3 bucket for the site
def commit_to_s3(bucket_name, src_folder):
  success = False

  try:
    # Requires S3 creds, which I set as environment variables
    connection = boto.connect_s3();
    bucket = connection.lookup(bucket_name)

    if bucket == None:
      # Create the bucket if we don't have it
      print 'Bucket ' + bucket_name + ' not found. Creating...'
      bucket = connection.create_bucket(bucket_name)
      print 'Bucket ' + bucket_name + ' created.'

    # Iterating over all files in the web-content folder
    for directory, subdirectories, files in os.walk(src_folder):
      for filename in files:
        # We want the path to get each file
        local_file_path = os.path.join(directory, filename)
        # For s3, we don't want the 'public' part of file path
        s3_file_path = local_file_path[len(src_folder)+1:]

        remote_file = bucket.get_key(s3_file_path)

        print filename + ' is uploading...'
        key_file = boto.s3.key.Key(bucket)
        key_file.key = s3_file_path
        key_file.set_contents_from_filename(local_file_path)
        key_file.make_public()

        # Will print after update or if no update was required
        print filename + ' is up to date.'

    # If we got here with no exceptions, changes have been committed
    success = True

  # Boto provides little in the way of exception handling, need a blanket
  except Exception, e:
    print e

  print_result('Changes', 'committed', success)

  return success

@@ -14,12 +14,15 @@
 os, 
-time
+hashlib
 %0A%0Ade
@@ -837,16 +837,17 @@
  files:%0A
+%0A
         
@@ -852,36 +852,36 @@
   # 
-We want th
+Set up fil
 e path
- to
+s and
  get 
-each
+s3
  fil
@@ -1064,25 +1064,24 @@
 er)+1:%5D%0A
-%0A
         
 remote_f
@@ -1076,14 +1076,10 @@
     
-remote
+s3
 _fil
@@ -1112,16 +1112,492 @@
 _path)%0A%0A
+        # If file exists: compare hashes, else: force unmatching hashes%0A        if s3_file != None:%0A          # s3 surround hash with quotes, so we need to include them%0A          local_hash = '%5C%22%25s%5C%22' %25 (%0A            hashlib.md5(open(local_file_path, 'rb').read()).hexdigest() )%0A          s3_hash = s3_file.etag%0A        else:%0A          local_hash = 0%0A          s3_hash = 1%0A%0A        # If the hashes are different, we need to upload the file%0A        if local_hash != s3_hash:%0A  
         
@@ -1632,32 +1632,34 @@
 ing...'%0A        
+ 
+ 
 key_file = boto.
@@ -1677,32 +1677,34 @@
 bucket)%0A        
+  
 key_file.key = s
@@ -1715,32 +1715,34 @@
 le_path%0A        
+ 
+ 
 key_file.set_con
@@ -1778,16 +1778,18 @@
 e_path)%0A
+  
         

Add compare md5 to only upload modified files