def send_file_to_rackspace(fname): """Sends the created file to the Rackspace CDN. Arguments: arguments - dictionary returned by the validate_arguments function The file saved to arguments["file"] is uploaded to Rackspace CDN and stored in container RS_CONTAINER_NAME using the current file name. The file name is taken with the extension, but without the whole path. After loding the file, th function checks if the file is listed in the container objects list. """ rsfname = fname.split('/')[-1:][0] container = get_rackspace_container() f = container.create_object(rsfname) print "Uploading %s" % fname f.load_from_filename(fname) if file_is_in_container(rsfname, container): rs_file_uri = url_join(container.public_uri(), rsfname) print "... %s" % rs_file_uri else: print "Couldn't upload file." return rs_file_uri
def create_sitemap_index(path): global CONFIG site_map_uri = CONFIG.get("Sitemap", "SitemapURI") fpath = os.path.join(path, "all_item_urls.xml") with open(fpath, "w") as f: line = '<?xml version="1.0" encoding="UTF-8"?>\n' + \ '<sitemapindex xmlns="' + \ 'http://www.sitemaps.org/schemas/sitemap/0.9">\n' f.write(line) for item in os.listdir(path): # Skip file being written to if item == "all_item_urls.xml": continue # sitemaps.dp.la is a CNAME pointing to the CDN host file_uri = url_join(site_map_uri, item) lastmod_dt = datetime.utcfromtimestamp( os.path.getmtime(os.path.join(path, item))) line = "\t<sitemap>\n" + \ "\t\t<loc>%s</loc>\n\t\t<lastmod>%s</lastmod>\n" % \ (file_uri, iso_utc_with_tz(lastmod_dt)) + "\t</sitemap>\n" f.write(line) f.write("</sitemapindex>")
def create_sitemap_index(path): global CONFIG site_map_uri = CONFIG.get("Sitemap", "SitemapURI") fpath = os.path.join(path, "all_item_urls.xml") with open(fpath, "w") as f: line = '<?xml version="1.0" encoding="UTF-8"?>\n' + \ '<sitemapindex xmlns="' + \ 'http://www.sitemaps.org/schemas/sitemap/0.9">\n' f.write(line) for item in os.listdir(path): # Skip file being written to if item == "all_item_urls.xml": continue # sitemaps.dp.la is a CNAME pointing to the CDN host file_uri = url_join(site_map_uri, item) lastmod_dt = datetime.utcfromtimestamp(os.path.getmtime( os.path.join(path, item) )) line = "\t<sitemap>\n" + \ "\t\t<loc>%s</loc>\n\t\t<lastmod>%s</lastmod>\n" % \ (file_uri, iso_utc_with_tz(lastmod_dt)) + "\t</sitemap>\n" f.write(line) f.write("</sitemapindex>")