raw_input just continues anyway?

oliver at obeattie.com oliver at obeattie.com
Tue Apr 3 10:51:50 EDT 2007


Hi There,

Here's the full code, if it helps:

"""
Takes a list of filenames via standard input and uploads them to
Amazon S3.

Requires S3.py:
	http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134&categoryID=47

Usage:
	cd /directory/with/media/files/
	find | grep -v ".svn" | python /path/to/update_s3.py

Before you use this, change the aws_access_key_id, aws_secret_key and
bucket_name variables at the top of the file.

You can run this multiple times on the same files -- it'll just
override the
files that were in your S3 account previously.
"""

import mimetypes
import os
import settings
import os.path
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from custom_filters import filename_slugify
import S3
import settings

aws_access_key_id = settings.AWS_ACCESS_KEY_ID
aws_secret_key = settings.AWS_SECRET_KEY

def update_s3(bucket_name=bucket_name):
	conn = S3.AWSAuthConnection(aws_access_key_id, aws_secret_key)
	for line in sys.stdin:
		filename = os.path.normpath(line[:-1])
		if ((filename == '.' or not os.path.isfile(filename)) or
(filename.find('ds_store') >= 0)):
			continue # Skip this, because it's not a file.
		print "Uploading %s" % filename_slugify(filename)
		filedata = open(filename, 'rb').read()
		content_type = mimetypes.guess_type(filename)[0]
		if not content_type:
			content_type = 'text/plain'
		conn.put(bucket_name, filename_slugify(filename),
S3.S3Object(filedata),
			{'x-amz-acl': 'private', 'Content-Type': content_type})

if __name__ == "__main__":
	bucket_name = raw_input('Name of the bucket you wish the files to be
placed into? ')
	update_s3()


Basically I pipe some files into the script - so would this cause a
linebreak?




More information about the Python-list mailing list