Пример #1
0
    def urls_for_prefix(self, prefix='.'):
        url_patterns = []

        if self.path is None or not self.path.exists():
            return url_patterns

        prefixed_path = Path(self.path, prefix)
        for html_path in prefixed_path.walk():
            # skip files that don't end in .html
            if not html_path.endswith('.html'):
                continue
            rel_path = self.path.rel_path_to(html_path)
            prefix_rel_path = prefixed_path.rel_path_to(html_path)
            # skip files in underscore directories
            if rel_path.startswith('_'):
                continue
            view = SheerTemplateView.as_view(template_engine=self.slug,
                                             template_name=str(rel_path))
            regex_template = r'^%s$'
            index_template = r'^%s/$'
            if rel_path.name == 'index.html':
                if prefix_rel_path.parent:
                    slash_regex = index_template % prefix_rel_path.parent
                else:
                    slash_regex = r'^$'
                pattern = url(slash_regex, view)
                redirect_regex = regex_template % prefix_rel_path
                index_redirect = RedirectView.as_view(url='./', permanent=True)
                redirect_pattern = url(redirect_regex, index_redirect)
                url_patterns += [pattern, redirect_pattern]
            else:
                regex = regex_template % prefix_rel_path
                pattern = url(regex, view)
                url_patterns.append(pattern)
        return url_patterns
Пример #2
0
class SheerSite(object):

    def __init__(self, slug):
        self.slug = slug
        if slug in settings.SHEER_SITES:
            self.path = Path(settings.SHEER_SITES[slug])
        else:
            self.path = None

    @property
    def urls(self):
        return self.urls_for_prefix()

    def urls_for_prefix(self, prefix='.'):
        url_patterns = []

        if self.path is None or not self.path.exists():
            return url_patterns

        prefixed_path = Path(self.path, prefix)
        for html_path in prefixed_path.walk():
            # skip files that don't end in .html
            if not html_path.endswith('.html'):
                continue
            rel_path = self.path.rel_path_to(html_path)
            prefix_rel_path = prefixed_path.rel_path_to(html_path)
            # skip files in underscore directories
            if rel_path.startswith('_'):
                continue
            view = SheerTemplateView.as_view(
                template_engine=self.slug,
                template_name=str(rel_path))
            regex_template = r'^%s$'
            index_template = r'^%s/$'
            if rel_path.name == 'index.html':
                if prefix_rel_path.parent:
                    slash_regex = index_template % prefix_rel_path.parent
                else:
                    slash_regex = r'^$'
                pattern = url(slash_regex, view)
                redirect_regex = regex_template % prefix_rel_path
                index_redirect = RedirectView.as_view(url='./', permanent=True)
                redirect_pattern = url(redirect_regex, index_redirect)
                url_patterns += [pattern, redirect_pattern]
            else:
                regex = regex_template % prefix_rel_path
                pattern = url(regex, view)
                url_patterns.append(pattern)
        return url_patterns
Пример #3
0
def sync():
    params = {
        "aws_access_key_id": app.config["AWS_ACCESS_KEY_ID"],
        "aws_secret_access_key": app.config["AWS_ACCESS_KEY"],
    }

    if app.config.get('AWS_S3_CALLING_FORMAT'):
        params['calling_format'] = app.config['AWS_S3_CALLING_FORMAT']

    if app.config.get("AWS_REGION"):
        c = boto.s3.connect_to_region(app.config["AWS_REGION"], **params)
    else:
        c = boto.connect_s3(**params)

    b = c.get_bucket(app.config["S3_BUCKET"])
    k = Key(b)

    local_path = app.config["FREEZER_DESTINATION"]
    destination_path = app.config["S3_DESTINATION"]

    local_path = Path(local_path)
    destination_path = Path(destination_path)

    for path, file_dir, files in os.walk(local_path):
        for local_file in files:
            file_path = Path(path, local_file)
            rel_path = Path(destination_path,
                            local_path.rel_path_to(file_path))

            logger.info("- Uploading file %s" % (rel_path,))

            k.key = rel_path
            k.set_contents_from_filename(file_path)
            b.set_acl("public-read", k.key)

    logger.info("Sync complete!")
Пример #4
0
 def test4(self):
     p1 = Path("swedish", "chef")
     assert p1.rel_path_to(self.d) == Path(os.path.pardir, os.path.pardir)
Пример #5
0
 def test3(self):
     p1 = Path("animals", "elephant")
     assert p1.rel_path_to(self.d) == Path(os.path.pardir)
Пример #6
0
 def test2(self):
     p1 = Path("animals", "elephant")
     p2 = Path("images", "image1.gif")
     assert p1.rel_path_to(p2) == Path(os.path.pardir, "images",
                                       "image1.gif")
Пример #7
0
 def test1(self):
     p1 = Path("animals", "elephant")
     p2 = Path("animals", "mouse")
     assert p1.rel_path_to(p2) == Path("mouse")
Пример #8
0
 def test4(self):
     p1 = Path("swedish", "chef")
     assert p1.rel_path_to(self.d) == Path(os.path.pardir, os.path.pardir)
Пример #9
0
 def test3(self):
     p1 = Path("animals", "elephant")
     assert p1.rel_path_to(self.d) == Path(os.path.pardir)
Пример #10
0
 def test2(self):
     p1 = Path("animals", "elephant")
     p2 = Path("images", "image1.gif")
     assert p1.rel_path_to(p2) == Path(os.path.pardir, "images", "image1.gif")
Пример #11
0
 def test1(self):
     p1 = Path("animals", "elephant")
     p2 = Path("animals", "mouse")
     assert p1.rel_path_to(p2) == Path("mouse")