Beispiel #1
0
def prepare_raphael():
    package_dir = os.path.dirname(__file__)
    raphael_dest_path = os.path.join(package_dir, 'raphael-build')

    # remove previous raphael library build
    print 'recursivly removing "%s"' % raphael_dest_path
    shutil.rmtree(raphael_dest_path, ignore_errors=True)
    print 'create new "%s"' % raphael_dest_path
    os.mkdir(raphael_dest_path)

    for filename in [MINIFIED, FULL]:
        url = urlparse.urljoin(BASEURL, filename)
        print 'downloading "%s"' % url
        f = urllib2.urlopen(url)
        file_data = f.read()
        f.close()
        dest_filename = os.path.join(raphael_dest_path, filename)
        dest = open(dest_filename, 'wb')
        print 'writing data to "%s"' % dest_filename
        dest.write(file_data)
        dest.close()

    py_path = os.path.join(package_dir, '_lib.py')
    print 'Generating inclusion module "%s"' % py_path

    library = Library('raphael')
    inclusion_map = {}
    inclusion = inclusion_map['raphael'] = ResourceInclusion(library, FULL)
    inclusion.modes['minified'] = ResourceInclusion(library, MINIFIED)
    code = generate_code(**inclusion_map)
    module = open(py_path, 'w')
    module.write(code)
    module.close()
Beispiel #2
0
def convert_to_inclusions(d):
    yui = Library('yui', 'yui-build')
    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)

    # add the SAM skin
    sam = ResourceInclusion(yui, 'assets/skins/sam/skin.css')
    inclusion_map['sam'] = sam
    
    # now generate code
    return generate_code(**inclusion_map)