import os
import os.path

from django.core.management.base import NoArgsCommand
from django.conf import settings

class Command(NoArgsCommand):
    
    can_import_settings = True

    def handle_noargs(self, **options):
        cache_manifest_path = os.path.join(settings.STATIC_ROOT,
                                           'cache.manifest')
        static_prefix_length = len(settings.STATIC_ROOT.split(os.sep))
        with open(cache_manifest_path, 'w') as cache_manifest:
            print >>cache_manifest, "CACHE MANIFEST"
            print >>cache_manifest, "CACHE:"
            for root, dirs, files in os.walk(settings.STATIC_ROOT):
                if root == settings.STATIC_ROOT:
                    # Don't cache admin media, desktop or markers
                    dirs.remove('admin')
                    dirs.remove('desktop')
                    dirs.remove('markers')
                url = '/'.join(root.split(os.sep)[static_prefix_length:])
                for file in files:
                    # Don't cache uncompressed JS/CSS
                    _, ext = os.path.splitext(file)
                    if ext in ('.js','.css') and 'c' != url.split('/')[0]:
                        continue
                    print >>cache_manifest, "%s%s/%s" % (settings.STATIC_URL, url, file)
@@ -766,32 +766,52 @@
                 
+ if 'admin' in dirs:
  dirs.remove('ad
@@ -827,32 +827,54 @@
                 
+ if 'desktop' in dirs:
  dirs.remove('de
@@ -900,16 +900,38 @@
         
+ if 'markers' in dirs:
  dirs.re
@@ -946,16 +946,317 @@
 rkers')%0A
+                %0A                if root == os.path.join(setting.STATIC_ROOT, 'touchmaplite', 'images'):%0A                    # Don't cache touchmaplite markers, we don't use them%0A                    if 'markers' in dirs: dirs.remove('markers')%0A                    if 'iui' in dirs: dirs.remove('iui')%0A
         
@@ -1537,16 +1537,16 @@
 /')%5B0%5D:%0A
-
         
@@ -1570,16 +1570,103 @@
 ontinue%0A
+                    %0A                    # Don't cache ourselves!%0A                    %0A
         

Fix cache.manifest generation when desktop app isn't loaded, also don't include unnecessary touchmaplite files (MOLLY-113)