예제 #1
0
    def handle(self, *args, **options):
        """
        Cache Static Files
        """
        possible_js_cache = os.path.join(generate_cache_dir(get_main_js_dir()),
                                         "mediabrute_usefile")

        if os.path.isfile(possible_js_cache):
            os.unlink(possible_js_cache)

        js_urls = handlers.minify_js()
        js_file = open(possible_js_cache, "w")
        for url in js_urls:
            js_file.writelines(js_urls)
        js_file.close()

        possible_css_cache = os.path.join(
            generate_cache_dir(get_main_css_dir()), "mediabrute_usefile")

        if os.path.isfile(possible_css_cache):
            os.unlink(possible_css_cache)

        css_urls = handlers.minify_css()
        css_file = open(possible_css_cache, "w")
        for url in css_urls:
            css_file.writelines(css_urls)
        css_file.close()
예제 #2
0
 def handle(self, *args, **options):
     """
     Cache Static Files
     """
     possible_js_cache = os.path.join(generate_cache_dir(get_main_js_dir()), "mediabrute_usefile")
     
     if os.path.isfile(possible_js_cache):
         os.unlink(possible_js_cache)
     
     js_urls = handlers.minify_js()
     js_file = open(possible_js_cache, "w")
     for url in js_urls:
         js_file.writelines(js_urls)
     js_file.close()
     
     
     possible_css_cache = os.path.join(generate_cache_dir(get_main_css_dir()), "mediabrute_usefile")
     
     if os.path.isfile(possible_css_cache):
         os.unlink(possible_css_cache)
     
     css_urls = handlers.minify_css()
     css_file = open(possible_css_cache, "w")
     for url in css_urls:
         css_file.writelines(css_urls)            
     css_file.close()
     
예제 #3
0
def get_main_js_dir():
    """
    Returns the main JS directory
    
    This is where the cache directory/file will be placed
    """
    return dirs.get_main_js_dir()
예제 #4
0
def get_main_js_dir():
    """
    Returns the main JS directory
    
    This is where the cache directory/file will be placed
    """
    return dirs.get_main_js_dir()
예제 #5
0
def clear_cache():
    """
    Clears out the cached media files
    """    
    js_dir = dirs.get_main_js_dir()
    css_dir = dirs.get_main_css_dir()
    
    heavy_lifting.unlink_cache(dirs.generate_cache_dir(js_dir), "js", unlink_all=True)
    heavy_lifting.unlink_cache(dirs.generate_cache_dir(css_dir), "css", unlink_all=True)
예제 #6
0
    def test_js_dir(self):
        """
        Main JS directory default setting test
         
        should match either settings.JS_DIR or just "js"
        Test that it works as a fullpath AND standalone
        """
        fullpath = dirs.get_main_js_dir()
        ext_only = dirs.get_main_js_dir(full_path=False)

        try:
            ext_compare = settings.JS_DIR
        except AttributeError:
            ext_compare = defaults.JS_DIR

        fullpath_compare = os.path.join(dirs.get_root(), ext_compare)

        self.assertEquals(fullpath_compare, fullpath)
        self.assertEquals(ext_compare, ext_only)
예제 #7
0
 def test_js_dir(self):
     """
     Main JS directory default setting test
      
     should match either settings.JS_DIR or just "js"
     Test that it works as a fullpath AND standalone
     """
     fullpath = dirs.get_main_js_dir()
     ext_only = dirs.get_main_js_dir(full_path=False)
      
     try:
         ext_compare = settings.JS_DIR
     except AttributeError:
         ext_compare = defaults.JS_DIR
          
     fullpath_compare = os.path.join(dirs.get_root(), ext_compare)
      
     self.assertEquals(fullpath_compare, fullpath)
     self.assertEquals(ext_compare, ext_only)
예제 #8
0
    def test_jssettings(self):
        """
        Test the creation of a static JS settings file
        """
        settings_fullpath = os.path.join(dirs.get_main_js_dir(),
                                         "mediabrute-settings.js")

        if os.path.isfile(settings_fullpath):
            os.unlink(settings_fullpath)
        self.assertFalse(os.path.isfile(settings_fullpath))

        call_command("mediabrute_jssettings")
        self.assertTrue(os.path.isfile(settings_fullpath))

        os.unlink(settings_fullpath)
        self.assertFalse(os.path.isfile(settings_fullpath))

        custom_filename = "heyo.js"
        custom_fullpath = os.path.join(dirs.get_main_js_dir(), "heyo.js")

        if os.path.isfile(custom_fullpath):
            os.unlink(custom_fullpath)
        self.assertFalse(os.path.isfile(custom_fullpath))

        call_command("mediabrute_jssettings", custom_filename)
        self.assertTrue(os.path.isfile(custom_fullpath))

        os.unlink(custom_fullpath)
        self.assertFalse(os.path.isfile(custom_fullpath))

        custom_filename = "heyo"
        custom_fullpath = os.path.join(dirs.get_main_js_dir(), "heyo.js")

        if os.path.isfile(custom_fullpath):
            os.unlink(custom_fullpath)
        self.assertFalse(os.path.isfile(custom_fullpath))

        call_command("mediabrute_jssettings", custom_filename)
        self.assertTrue(os.path.isfile(custom_fullpath))

        os.unlink(custom_fullpath)
        self.assertFalse(os.path.isfile(custom_fullpath))
예제 #9
0
 def test_jssettings(self):
     """
     Test the creation of a static JS settings file
     """
     settings_fullpath = os.path.join(dirs.get_main_js_dir(), "mediabrute-settings.js")
       
     if os.path.isfile(settings_fullpath):
         os.unlink(settings_fullpath)            
     self.assertFalse(os.path.isfile(settings_fullpath))
       
     call_command("mediabrute_jssettings")
     self.assertTrue(os.path.isfile(settings_fullpath))
       
     os.unlink(settings_fullpath)            
     self.assertFalse(os.path.isfile(settings_fullpath))
       
     custom_filename = "heyo.js"
     custom_fullpath = os.path.join(dirs.get_main_js_dir(), "heyo.js")
       
     if os.path.isfile(custom_fullpath):
         os.unlink(custom_fullpath)            
     self.assertFalse(os.path.isfile(custom_fullpath))
       
     call_command("mediabrute_jssettings", custom_filename)
     self.assertTrue(os.path.isfile(custom_fullpath))
       
     os.unlink(custom_fullpath)            
     self.assertFalse(os.path.isfile(custom_fullpath))
       
     custom_filename = "heyo"
     custom_fullpath = os.path.join(dirs.get_main_js_dir(), "heyo.js")
       
     if os.path.isfile(custom_fullpath):
         os.unlink(custom_fullpath)            
     self.assertFalse(os.path.isfile(custom_fullpath))
       
     call_command("mediabrute_jssettings", custom_filename)
     self.assertTrue(os.path.isfile(custom_fullpath))
       
     os.unlink(custom_fullpath)            
     self.assertFalse(os.path.isfile(custom_fullpath))
예제 #10
0
def clear_cache():
    """
    Clears out the cached media files
    """
    js_dir = dirs.get_main_js_dir()
    css_dir = dirs.get_main_css_dir()

    heavy_lifting.unlink_cache(dirs.generate_cache_dir(js_dir),
                               "js",
                               unlink_all=True)
    heavy_lifting.unlink_cache(dirs.generate_cache_dir(css_dir),
                               "css",
                               unlink_all=True)
    def handle(self, *args, **options):
        """
        Create the settings file, write to the main JS directory
        """
        if len(args) > 0:
            filename = args[0]
        else:
            filename = defaults.JS_SETTINGS_FILENAME

        if not filename.endswith(".js"):
            filename = "%s.js" % filename

        js_dir = get_main_js_dir()
        js_settings = get_js_settings()

        settings_file = open(os.path.join(js_dir, filename), "w")
        settings_file.write(js_settings)
        settings_file.close()
 def handle(self, *args, **options):
     """
     Create the settings file, write to the main JS directory
     """
     if len(args) > 0:
         filename = args[0]
     else:
         filename = defaults.JS_SETTINGS_FILENAME
     
     if not filename.endswith(".js"):
         filename = "%s.js" % filename
     
     js_dir = get_main_js_dir()
     js_settings = get_js_settings()
     
     settings_file = open(os.path.join(js_dir, filename), "w")
     settings_file.write(js_settings)
     settings_file.close()
     
예제 #13
0
def minify_js(app_name=None):
    """
    {{ MINI_JS }} Context processor
    """
    js_dir = dirs.get_main_js_dir()
    cache_dir = dirs.generate_cache_dir(js_dir)
    
    # check for a possible 'lock' file
    possible_cache = os.path.join(cache_dir, "mediabrute_usefile")
    if os.path.isfile(possible_cache):
        txt = open(possible_cache)
        js_urls = txt.readlines()        
        return [url for url in js_urls if url != ""]

    # continue to do an on-the-fly cache if no lock file was found
    js_dirs = [js_dir, dirs.APP_JS_DIRS]
    cache_files = [compile_and_cache_js(js_dirs, cache_dir, add_settings=True),]
    
    if app_name and app_name in dirs.get_separated_apps("js"):
        cache_files.append(compile_and_cache_js([dirs.get_separated_js(app_name), ], cache_dir, app_name=app_name))    
        
    return ["%s/cache/%s" % (dirs.get_js_url(), cache_name) for cache_name in cache_files]