def __init__(self, username, api_key, *args, **kwargs): """ Wraps the constructor in some error handling and prints some messages. """ write("Connecting to CloudFiles as '%s': " % username) try: super(Connection, self).__init__(username, api_key, *args, **kwargs) print "done" except socket.gaierror, (n, desc): print "failed" raise CommandError("It looks like you aren't online (socket." + "gaierror error " + str(n) + ": " + desc + ").")
def get_container(self, container_name, create=False): """ Wraps this utility in some error handling and prints some messages. Also allows for the automatic creation of a container that doesn't exist yet, if create=True. """ write("Getting container '%s': " % container_name) try: container = super(Connection, self).get_container(container_name) print "done" except cloudfiles.errors.InvalidContainerName, e: print "failed" raise CommandError("Invalid container name: '" + str(e) + "'")
def check_public(container, make_public=False): """ Returns true if: 1) The container is public, or 2) The container is made public using the make_public param """ if container.is_public(): return True if make_public: write("Making container public: ") try: container.make_public() print "done" return True except CDNNotEnabled: print "failed (CDN is not available for your account)." print ("*** WARNING: Container is not public. Ensure that it's " + "made public, or your files will not be available over " + "the CDN. You can use the --make-public option to allow " + "this script to make the container public for you.") return False
except cloudfiles.errors.InvalidUrl, e: print "failed" raise CommandError("Could not connect (" + str(e) + ")") def get_container(self, container_name, create=False): """ Wraps this utility in some error handling and prints some messages. Also allows for the automatic creation of a container that doesn't exist yet, if create=True. """ write("Getting container '%s': " % container_name) try: container = super(Connection, self).get_container(container_name) print "done" except cloudfiles.errors.InvalidContainerName, e: print "failed" raise CommandError("Invalid container name: '" + str(e) + "'") except cloudfiles.errors.NoSuchContainer, e: if create: write("must create: ") container = self.create_container(container_name) print "created" else: print "failed" raise CommandError("The container '" + str(e) + "' does not " + "exist. Please create this container, or " + "use the --make-container option to let " + "this script create it for you.") return container