Example #1
0
 def create_directory(self, pathname):
     req = urllib2.Request(pathname, '')
     req.add_header("Content-Type", "application/directory")
     req.add_header("X-Auth-Token", get_auth_token())
     req.get_method = lambda: "PUT"
     res = urllib2.urlopen(req).read()
     if res or res == "":
         self.stdout.write("Created directory: %s\n" % pathname)
     else:
         self.stdout.write("%s\n" % res)
Example #2
0
def _get_cdn_enabled_containers():
    path = "%s%s?format=json" % (settings.CDN_URL, settings.TENANT_ID)
    req = urllib2.Request(path)
    req.add_header("Content-type", "application/json")
    req.add_header("X-Auth-Token", get_auth_token())
    response = urllib2.urlopen(req)
    enabled_containers = {}
    for container in simplejson.loads(response.read()):
        enabled_containers[container["name"]] = {"https": container["x-cdn-ssl-uri"], "http": container["x-cdn-uri"]}
    return enabled_containers
Example #3
0
def create_directory(container):
    '''Creates a directory in the Object Store.

    :param container: :class:`str` The name of the directory to make.
    '''
    container = "%s%s/%s/%s?format=json" % (
        settings.OBJECT_STORE_URL, settings.TENANT_ID,
        settings.OBJECT_STORE_CONTAINER, container
    )
    req = urllib2.Request(container)
    req.add_header("Content-type", "application/directory")
    req.add_header("Content-length", "0")
    req.add_header("Accept", "application/json")
    req.add_header("X-Auth-Token", get_auth_token())
    req.get_method = lambda: "PUT"
    response = urllib2.urlopen(req)
    return response.getcode()
Example #4
0
 def upload_file(self, top, pathname):
     '''
     Uploads a file to the ObjectStore using the TTL value defined in the
     settings file and setting the correct mimetypes.
     '''
     # fix path ending to /
     if top[-1] != os.path.sep:
         top = top + os.path.sep
     baseprefix = len(os.path.commonprefix([self.basedir, top]))
     base = pathname[baseprefix:]
     path = self.prepare_path(base)
     req = urllib2.Request(path, open(pathname).read())
     ext = os.path.splitext(path)[1]
     mimetype = mimetypes.types_map.get(ext)
     if mimetype:
         req.add_header("Content-Type", mimetype)
     # default 24 hours
     req.add_header("X-TTL", self.settings.get(ext, "86400"))
     req.add_header("X-Auth-Token", get_auth_token())
     req.get_method = lambda: "PUT"
     if urllib2.urlopen(req).read() == "":
         print "Uploaded: %s" % pathname