Beispiel #1
0
    def list(self, ignore_patterns):
        print 'CALLING list with:', ignore_patterns
        from django.conf import settings
        urlconf = __import__(settings.ROOT_URLCONF, {}, {}, [''])

        views = extract_views_from_urlpatterns(urlconf.urlpatterns)
        views = [view for view in views if getattr(view[0], 'block', None)]

        css = get_css_for_pages(views)
        ensure_dir(settings.BEMPY_STATIC_DIR)
        css_filename = os.path.join(settings.BEMPY_STATIC_DIR, 'bempy.css')
        with open(css_filename, 'w') as f:
            f.write(css.encode('utf-8'))

        js = get_js_for_pages(views)
        js_filename = os.path.join(settings.BEMPY_STATIC_DIR, 'bempy.js')
        with open(js_filename, 'w') as f:
            f.write(js.encode('utf-8'))

        storage = StaticFilesStorage(settings.BEMPY_STATIC_DIR)
        return [
            ('bempy.css', storage),
            ('bempy.js', storage),
            #            ('bempy/bempy.css', storage.path('bempy.css')),
            #                ('bempy/bempy.js', storage.path('bempy.js'))
        ]
def helppages_index(request):
    s = StaticFilesStorage()
    pages = list(get_files(s, location='helppages'))

    slugs = [x[10:-5] for x in pages]
    pks = [x[10:-1].split('_')[0] for x in pages]

    return render(request, 'article_index.html', locals())
Beispiel #3
0
def test_get_file_hash(case):
    # type: (TestCase) -> None
    strategy = Strategy()
    local_storage = StaticFilesStorage()

    with tempfile.NamedTemporaryFile(dir=local_storage.base_location) as f:
        f.write(b"spam")
        hash_ = strategy.get_local_file_hash(f.name, local_storage)
    case.assertTrue(re.fullmatch(r"^[A-z0-9]{32}$", hash_) is not None)
 def collect_files(self):
     """Find and write static files. Along the way ignore the "compiled"
     directory, if present"""
     write_storage = StaticFilesStorage(self.BUILD_DIR + "/static/")
     original_dirs = settings.STATICFILES_DIRS
     settings.STATICFILES_DIRS = [s for s in original_dirs
                                  if s != 'compiled']
     for prefixed_path, source_file in self._input_files():
         write_storage.save(prefixed_path, source_file)
     settings.STATICFILES_DIRS = original_dirs
def inner(request,dir_):
    static_file_storage = StaticFilesStorage()
    files = list(static_file_storage.listdir(dir_))
    for f in files:
        if len(f) > 0:
            out = f
    files = f[0]
    fullpath = os.path.join(dir_,files)
    print(fullpath)
    ctx = {'img':fullpath} 
    return render(request,'main/inner.html',ctx)
Beispiel #6
0
def test_get_file_hash(case):
    # disable this test on appveyor until permissions issue is solved
    if platform.system() == 'Windows':
        return
    storage = StaticFilesStorage()
    with tempfile.NamedTemporaryFile(dir=storage.base_location) as f:
        f.write(b'spam')
        h = etag.get_file_hash(storage, f.name)
    case.assertEqual(len(h), 34)
    case.assertTrue(h.startswith('"'))
    case.assertTrue(h.endswith('"'))
    for c in h[1:-1]:
        case.assertIn(c, hash_characters)
Beispiel #7
0
def test_templatetag(template_string, filename):
    storage = StaticFilesStorage(location=settings.STATICFILES_TEST_DIR)
    try:
        storage.save(name=filename,
                     content=ContentFile("body { background: red; }"))
        resp = T(template_string).render(CTX).strip().split("\n")
        expected_output = '<link href="{}{}" rel="stylesheet" type="text/css" />'.format(
            settings.STATIC_URL, filename)
        assert expected_output in resp
        assert "<!--" not in resp
        assert "-->" not in resp
    finally:
        storage.delete(filename)
    def handle(self, *args, **options):
        local_storage = StaticFilesStorage()
        base_path = local_storage.base_location

        # Ignore files in our ignore patterns
        ignore_patterns = getattr(settings, 'SYNCSTATIC_IGNORE_PATTERNS', None)
        files = set(
            utils.get_files(local_storage, ignore_patterns=ignore_patterns))

        # Remove any files that went into compilation
        files -= set(settings.PIPELINE_JS['main']['source_filenames'])
        files -= set(settings.PIPELINE_CSS['main']['source_filenames'])

        for file in files:
            print('syncing to s3: %s' % file)
            staticfiles_storage.save(file, local_storage.open(file, 'r'))
Beispiel #9
0
class CvTemplateForm(forms.Form):
    s = StaticFilesStorage()
    repertoire = []
    repertoire_pas_propre = list(get_files(s, location='collab'))
    for elt in repertoire_pas_propre:
        if "assets" in elt:
            pass
        else:
            nomDoc = elt.replace("collab\\", '')
            if ".docx" in nomDoc:
                valeur = (nomDoc, nomDoc)
                repertoire.append(valeur)
            else:
                pass
    template = forms.CharField(label='Quel template voulez-vous ?',
                               widget=forms.Select(choices=repertoire))
    collabid = forms.CharField(widget=forms.HiddenInput(), required=True)
def main(request):
    static_file_storage = StaticFilesStorage()
    dirs = list(static_file_storage.listdir('.'))
    
    for d in dirs:
        if len(d) > 0:
            out = d
    dirs = out

    #print(dirs)
    #files = list(get_files(static_file_storage,location = 'assets'))
    files  = {'dirs':dirs}
    try:
        import os
        #print(os.listdir('..'))
    except:
        pass
    return render(request,'main/main.html',files)
Beispiel #11
0
    def invoke_collect(self, layer, path):
        """ Invoke collect, reset all instance storage first and initialize
            a self.storage that's bound to the layers target STATIC_ROOT
        """
        self.stdout.write("Collecting layer %s to path %s\n" % (layer, path))
        self.storage = StaticFilesStorage(path)
        try:
            self.storage.path('')
        except NotImplementedError:
            self.local = False
        else:
            self.local = True
        self.copied_files = []
        self.symlinked_files = []
        self.unmodified_files = []
        self.post_processed_files = []
        self.layer = layer

        return self.collect()
Beispiel #12
0
def test_templatetag_multiple_parts_of_path():
    filenames = ('css/level1.css', 'css/level1-level2.css',
                 'css/level1-level2-level3.css')
    storage = StaticFilesStorage(location=settings.STATICFILES_TEST_DIR)
    try:
        for filename in filenames:
            storage.save(name=filename,
                         content=ContentFile("body { background: red; }"))
        resp = T('{% load path2css %}{% css4path "/level1/level2/level3/" %}'
                 ).render(CTX).strip()
        assert resp.split("\n") == [
            '<link href="{}css/level1.css" rel="stylesheet" type="text/css" />'
            .format(settings.STATIC_URL),
            '<link href="{}css/level1-level2.css" rel="stylesheet" type="text/css" />'
            .format(settings.STATIC_URL),
            '<link href="{}css/level1-level2-level3.css" rel="stylesheet" type="text/css" />'
            .format(settings.STATIC_URL)
        ]
    finally:
        for filename in filenames:
            storage.delete(filename)
Beispiel #13
0
def test_should_copy_file(case):
    # type: (TestCase) -> None
    strategy = Strategy()
    local_storage = StaticFilesStorage()
    remote_hash = "foo"
    mock_remote_hash = mock.patch.object(
        strategy, "get_remote_file_hash", mock.MagicMock(return_value=remote_hash)
    )

    with mock_remote_hash:
        with mock.patch.object(
            strategy, "get_local_file_hash", mock.MagicMock(return_value=remote_hash)
        ):
            case.assertFalse(
                strategy.should_copy_file("path", "prefixed_path", local_storage)
            )
        with mock.patch.object(
            strategy, "get_local_file_hash", mock.MagicMock(return_value="bar")
        ):
            case.assertTrue(
                strategy.should_copy_file("path", "prefixed_path", local_storage)
            )
Beispiel #14
0
def test_templatetag_assignment(request_path, filenames):
    storage = StaticFilesStorage(location=settings.STATICFILES_TEST_DIR)
    try:
        for filename in filenames:
            storage.save(name=filename,
                         content=ContentFile("body { background: red; }"))
        resp = T('''
        {% load path2css %}
        {% css4path path as GOOSE %}
        {% for part, exists in GOOSE %}
        {% if exists %}{{ part }}{% endif %}
        {% endfor %}
        ''').render(Context({'path': request_path})).strip()
        parts = [x.strip() for x in resp.split("\n") if x.strip()]
        expected_output = [
            "{}{}".format(settings.STATIC_URL, filename)
            for filename in filenames
        ]
        assert parts == expected_output
    finally:
        for filename in filenames:
            storage.delete(filename)
from collectfast.strategies.base import HashStrategy
from collectfast.tests.utils import make_test


class Strategy(HashStrategy[FileSystemStorage]):
    def __init__(self) -> None:
        super().__init__(FileSystemStorage())

    def get_remote_file_hash(self, prefixed_path: str) -> None:
        pass


@make_test
def test_get_file_hash(case: TestCase) -> None:
    strategy = Strategy()
    local_storage = StaticFilesStorage()

    with tempfile.NamedTemporaryFile(dir=local_storage.base_location) as f:
        f.write(b"spam")
        hash_ = strategy.get_local_file_hash(f.name, local_storage)
    case.assertTrue(re.fullmatch(r"^[A-z0-9]{32}$", hash_) is not None)


@make_test
def test_should_copy_file(case: TestCase) -> None:
    strategy = Strategy()
    local_storage = StaticFilesStorage()
    remote_hash = "foo"
    mock_remote_hash = mock.patch.object(
        strategy, "get_remote_file_hash",
        mock.MagicMock(return_value=remote_hash))
Beispiel #16
0
def default_header():
    path = 'defaults/header.jpg'
    return ImageFile(open(StaticFilesStorage().path(path), 'rb'))
Beispiel #17
0
def xmlfiles(mylocation="xml"):
    s = StaticFilesStorage()
    xmls = list(get_files(s, location=mylocation))
    xmlfiles = [(os.path.join(settings.STATIC_ROOT, filename))
                for filename in xmls]
    return xmlfiles
Beispiel #18
0
def get_file():
    s = StaticFilesStorage()
    return list(get_files(s, location='adj'))
Beispiel #19
0
def default_avatar(variation=0):
    path = 'defaults/avatar_{0}.jpg'.format(variation % 10)

    return ImageFile(open(StaticFilesStorage().path(path), 'rb'))
Beispiel #20
0
def find_static_files():
    storage = StaticFilesStorage()
    static_url = getattr(settings, 'STATIC_URL')
    return ['{}{}'.format(static_url, file) for file in get_files(storage)]
Beispiel #21
0
 def __init__(self, *args, **kwargs):
     super(S3LocalCachedMixin, self).__init__(*args, **kwargs)
     self._local = StaticFilesStorage(location=CONVOY_LOCAL_CACHE_ROOT)