[Checkins] SVN: hurry.yui/trunk/s Some cleanups of the preparation system.

Martijn Faassen faassen at infrae.com
Tue Oct 7 13:35:05 EDT 2008


Log message for revision 91876:
  Some cleanups of the preparation system.
  

Changed:
  U   hurry.yui/trunk/setup.py
  A   hurry.yui/trunk/src/hurry/yui/depend.py
  A   hurry.yui/trunk/src/hurry/yui/download.py
  U   hurry.yui/trunk/src/hurry/yui/prepare.py
  D   hurry.yui/trunk/src/hurry/yui/yuidepend.py
  D   hurry.yui/trunk/src/hurry/yui/yuidl.py

-=-
Modified: hurry.yui/trunk/setup.py
===================================================================
--- hurry.yui/trunk/setup.py	2008-10-07 17:29:18 UTC (rev 91875)
+++ hurry.yui/trunk/setup.py	2008-10-07 17:35:04 UTC (rev 91876)
@@ -23,7 +23,6 @@
     entry_points= {
     'console_scripts': [
       'yuiprepare = hurry.yui.prepare:main',
-      'yuidepend = hurry.yui.yuidepend:main',
       ]
     },
 

Copied: hurry.yui/trunk/src/hurry/yui/depend.py (from rev 91874, hurry.yui/trunk/src/hurry/yui/yuidepend.py)
===================================================================
--- hurry.yui/trunk/src/hurry/yui/depend.py	                        (rev 0)
+++ hurry.yui/trunk/src/hurry/yui/depend.py	2008-10-07 17:35:04 UTC (rev 91876)
@@ -0,0 +1,111 @@
+import sys, os
+import urllib2
+import simplejson
+
+from hurry.resource import Library, ResourceInclusion, generate_code
+
+YUILOADER_BETA_URL_TEMPLATE = ('http://yui.yahooapis.com/%s/build/yuiloader'
+                               '/yuiloader-beta.js')
+
+YUILOADER_URL_TEMPLATE = ('http://yui.yahooapis.com/%s/build/yuiloader'
+                         '/yuiloader.js')
+
+def depend(version):
+    d = load_json(version)
+    return convert_to_inclusions(d)
+
+def convert_to_inclusions(d):
+    yui = Library('yui')
+    inclusion_map = {}
+    for name, value in d.items():
+        name = normalize_name(name)
+        inclusion_map[name] = ResourceInclusion(yui,
+                                                deminize(value['path']))
+                
+    # fix up dependency structure
+    # XXX note that this doesn't establish proper rollup backreferences
+    # but this doesn't matter as we're just going to generate the
+    # code that does...
+    for name, value in d.items():
+        name = normalize_name(name)
+        inclusion = inclusion_map[name]
+
+        for require in value.get('requires', []):
+            require = normalize_name(require)
+            inclusion.depends.append(inclusion_map[require])
+
+        for supersede_name in value.get('supersedes', []):
+            orig_supersede_name = supersede_name
+            supersede_name = normalize_name(supersede_name)
+            r = inclusion_map[supersede_name]
+            # only supersede things that don't supersede themselves
+            if not d[orig_supersede_name].get('supersedes'):
+                inclusion.supersedes.append(r)
+
+        for mode_name in get_modes(inclusion):
+            inclusion.modes[mode_name] = mode_inclusion = convert_to_mode(
+                inclusion, mode_name)
+
+    # now generate code
+    return generate_code(**inclusion_map)
+    
+def normalize_name(n):
+    return str(n.replace('-', '_'))
+
+def deminize(path):
+    rest, ext = os.path.splitext(path)
+    if rest.endswith('-min'):
+        rest = rest[:-len('-min')]
+    return rest + ext
+
+def convert_to_mode(inclusion, mode):
+    rest, ext = os.path.splitext(inclusion.relpath)
+    if mode == 'minified':
+        result = ResourceInclusion(inclusion.library,
+                                   rest + '-min' + ext)
+    elif mode == 'debug':
+        result = ResourceInclusion(inclusion.library,
+                                   rest + '-debug' + ext)
+    else:
+        result = inclusion
+        
+    return result
+
+def get_modes(inclusion):
+    ext = inclusion.ext()
+    if ext == '.css':
+        return ['minified']
+    elif ext == '.js':
+        return ['minified', 'debug']
+    else:
+        return []
+    
+def load_json(version):
+    try:
+        f = urllib2.urlopen(YUILOADER_URL_TEMPLATE % version)
+        data = f.read()
+        f.close()
+    except urllib2.HTTPError:
+        f = urllib2.urlopen(YUILOADER_BETA_URL_TEMPLATE % version)
+        data = f.read()
+        f.close()
+    s = "'moduleInfo': "
+    i = data.find(s)
+    i = i + len(s)
+    j = data.find("'yuitest': {", i)
+    j = data.find('}', j)
+    j = data.find('}', j + 1)
+    text = data[i:j + 1]
+    json = normalize_json(text)
+    return simplejson.loads(json)
+
+def normalize_json(text):
+    # proper json has doubly quoted strings
+    text = text.replace("'", '"')
+    result = []
+    for line in text.splitlines():
+        i = line.find('//')
+        if i != -1:
+            line = line[:i] + '\n'
+        result.append(line)
+    return ''.join(result)

Copied: hurry.yui/trunk/src/hurry/yui/download.py (from rev 91874, hurry.yui/trunk/src/hurry/yui/yuidl.py)
===================================================================
--- hurry.yui/trunk/src/hurry/yui/download.py	                        (rev 0)
+++ hurry.yui/trunk/src/hurry/yui/download.py	2008-10-07 17:35:04 UTC (rev 91876)
@@ -0,0 +1,45 @@
+import urllib2
+import tempfile, shutil
+import os
+
+SF_URL_TEMPLATE = 'http://sourceforge.net/project/downloading.php?group_id=165715&filename=yui_%s.zip'
+
+def download(version, callback):
+    """Download a yui of version.
+
+    When downloaded, call callback with path to directory
+    with an extracted YUI. The callback will then be able to copy
+    this to the appropriate location.
+    """
+    url = SF_URL_TEMPLATE % version
+    f = urllib2.urlopen(url)
+    data = f.read()
+    f.close()
+
+    download_url = find_a_href(data, 'direct link')
+
+    f = urllib2.urlopen(download_url)
+    file_data = f.read()
+    f.close()
+
+    dirpath = tempfile.mkdtemp()
+    try:
+        yui_path = os.path.join(dirpath, 'yui.zip')
+        ex_path = os.path.join(dirpath, 'yui_ex')
+        g = open(yui_path, 'wb')
+        g.write(file_data)
+        g.close()
+        os.system('unzip -qq "%s" -d "%s"' % (yui_path, ex_path))
+        callback(ex_path)
+    finally:
+        shutil.rmtree(dirpath, ignore_errors=True)
+
+def find_a_href(data, content):
+    """Given start of content of the <a href="">content</a> find href.
+    """
+    i = data.find(content)
+    a = '<a href="'
+    href_start = data.rfind(a, 0, i)
+    href_start += len(a)
+    href_end = data.find('"', href_start)
+    return data[href_start:href_end]

Modified: hurry.yui/trunk/src/hurry/yui/prepare.py
===================================================================
--- hurry.yui/trunk/src/hurry/yui/prepare.py	2008-10-07 17:29:18 UTC (rev 91875)
+++ hurry.yui/trunk/src/hurry/yui/prepare.py	2008-10-07 17:35:04 UTC (rev 91876)
@@ -1,8 +1,8 @@
 import os, sys
 import shutil
 
-from hurry.yui.yuidepend import yuidepend
-from hurry.yui.yuidl import download
+from hurry.yui.depend import depend
+from hurry.yui.download import download
 
 def main():
     try:
@@ -26,7 +26,7 @@
     download(version, copy_yui)
 
     # get dependency structure and create 'yui.py' into package
-    code = yuidepend(version)
+    code = depend(version)
     yui_py_path = os.path.join(package_dir, 'yui.py')
     f = open(yui_py_path, 'w')
     f.write(code)

Deleted: hurry.yui/trunk/src/hurry/yui/yuidepend.py
===================================================================
--- hurry.yui/trunk/src/hurry/yui/yuidepend.py	2008-10-07 17:29:18 UTC (rev 91875)
+++ hurry.yui/trunk/src/hurry/yui/yuidepend.py	2008-10-07 17:35:04 UTC (rev 91876)
@@ -1,127 +0,0 @@
-import sys, os
-import urllib2
-import simplejson
-
-from hurry.resource import Library, ResourceInclusion, generate_code
-
-YUILOADER_BETA_URL_TEMPLATE = ('http://yui.yahooapis.com/%s/build/yuiloader'
-                               '/yuiloader-beta.js')
-
-YUILOADER_URL_TEMPLATE = ('http://yui.yahooapis.com/%s/build/yuiloader'
-                         '/yuiloader.js')
-
-
-def main():
-    try:
-        version = sys.argv[1]
-    except IndexError:
-        print "Usage: yuidepend <YUI version>"
-        return
-    print yuidepend(version)
-
-def yuidepend(version):
-    d = load_json(version)
-    return convert_to_inclusions(d)
-
-def convert_to_inclusions(d):
-    yui = Library('yui')
-    inclusion_map = {}
-    for name, value in d.items():
-        name = normalize_name(name)
-        inclusion_map[name] = ResourceInclusion(yui,
-                                                deminize(value['path']))
-                
-    # fix up dependency structure
-    # XXX note that this doesn't establish proper rollup backreferences
-    # but this doesn't matter as we're just going to generate the
-    # code that does...
-    for name, value in d.items():
-        name = normalize_name(name)
-        inclusion = inclusion_map[name]
-
-        for require in value.get('requires', []):
-            require = normalize_name(require)
-            inclusion.depends.append(inclusion_map[require])
-
-        for supersede_name in value.get('supersedes', []):
-            orig_supersede_name = supersede_name
-            supersede_name = normalize_name(supersede_name)
-            r = inclusion_map[supersede_name]
-            # only supersede things that don't supersede themselves
-            if not d[orig_supersede_name].get('supersedes'):
-                inclusion.supersedes.append(r)
-
-        for mode_name in get_modes(inclusion):
-            inclusion.modes[mode_name] = mode_inclusion = convert_to_mode(
-                inclusion, mode_name)
-
-    # now generate code
-    return generate_code(**inclusion_map)
-    
-def normalize_name(n):
-    return str(n.replace('-', '_'))
-
-def deminize(path):
-    rest, ext = os.path.splitext(path)
-    if rest.endswith('-min'):
-        rest = rest[:-len('-min')]
-    return rest + ext
-
-def convert_to_mode(inclusion, mode):
-    rest, ext = os.path.splitext(inclusion.relpath)
-    if mode == 'minified':
-        result = ResourceInclusion(inclusion.library,
-                                   rest + '-min' + ext)
-    elif mode == 'debug':
-        result = ResourceInclusion(inclusion.library,
-                                   rest + '-debug' + ext)
-    else:
-        result = inclusion
-        
-    return result
-
-def get_modes(inclusion):
-    ext = inclusion.ext()
-    if ext == '.css':
-        return ['minified']
-    elif ext == '.js':
-        return ['minified', 'debug']
-    else:
-        return []
-    
-def sorted_dependencies(d):
-    """Given dictionary created sorted list of items.
-
-    Sort by how much we depend.
-    """
-    
-    
-def load_json(version):
-    try:
-        f = urllib2.urlopen(YUILOADER_URL_TEMPLATE % version)
-        data = f.read()
-        f.close()
-    except urllib2.HTTPError:
-        f = urllib2.urlopen(YUILOADER_BETA_URL_TEMPLATE % version)
-        data = f.read()
-        f.close()
-    s = "'moduleInfo': "
-    i = data.find(s)
-    i = i + len(s)
-    j = data.find("'yuitest': {", i)
-    j = data.find('}', j)
-    j = data.find('}', j + 1)
-    text = data[i:j + 1]
-    json = normalize_json(text)
-    return simplejson.loads(json)
-
-def normalize_json(text):
-    # proper json has doubly quoted strings
-    text = text.replace("'", '"')
-    result = []
-    for line in text.splitlines():
-        i = line.find('//')
-        if i != -1:
-            line = line[:i] + '\n'
-        result.append(line)
-    return ''.join(result)

Deleted: hurry.yui/trunk/src/hurry/yui/yuidl.py
===================================================================
--- hurry.yui/trunk/src/hurry/yui/yuidl.py	2008-10-07 17:29:18 UTC (rev 91875)
+++ hurry.yui/trunk/src/hurry/yui/yuidl.py	2008-10-07 17:35:04 UTC (rev 91876)
@@ -1,45 +0,0 @@
-import urllib2
-import tempfile, shutil
-import os
-
-SF_URL_TEMPLATE = 'http://sourceforge.net/project/downloading.php?group_id=165715&filename=yui_%s.zip'
-
-def download(version, callback):
-    """Download a yui of version.
-
-    When downloaded, call callback with path to directory
-    with an extracted YUI. The callback will then be able to copy
-    this to the appropriate location.
-    """
-    url = SF_URL_TEMPLATE % version
-    f = urllib2.urlopen(url)
-    data = f.read()
-    f.close()
-
-    download_url = find_a_href(data, 'direct link')
-
-    f = urllib2.urlopen(download_url)
-    file_data = f.read()
-    f.close()
-
-    dirpath = tempfile.mkdtemp()
-    try:
-        yui_path = os.path.join(dirpath, 'yui.zip')
-        ex_path = os.path.join(dirpath, 'yui_ex')
-        g = open(yui_path, 'wb')
-        g.write(file_data)
-        g.close()
-        os.system('unzip -qq "%s" -d "%s"' % (yui_path, ex_path))
-        callback(ex_path)
-    finally:
-        shutil.rmtree(dirpath, ignore_errors=True)
-
-def find_a_href(data, content):
-    """Given start of content of the <a href="">content</a> find href.
-    """
-    i = data.find(content)
-    a = '<a href="'
-    href_start = data.rfind(a, 0, i)
-    href_start += len(a)
-    href_end = data.find('"', href_start)
-    return data[href_start:href_end]



More information about the Checkins mailing list