Created
March 9, 2020 20:15
-
-
Save danizen/8d41f63c7bb4e35793a8e5d4d41fac16 to your computer and use it in GitHub Desktop.
Django app to load from a webapp bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
class BundleMap(object): | |
def __init__(self, rootpath): | |
self.rootpath = rootpath | |
self.rebuild() | |
def rebuild(self): | |
self.map = { 'css': {}, 'js': {} } | |
for name in os.listdir(self.rootpath): | |
m = re.match(r'([a-z]+)\.[a-z0-9]+\.bundle.(js|css)', name) | |
if m is not None: | |
bname = m.group(1) | |
btype = m.group(2) | |
if btype in self.map: | |
self.map[btype][bname] = name | |
def get_bundle(self, btype, name): | |
return self.map[btype][name] if name in self.map[btype] else None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment