Merge lp:~rharding/launchpad/yuiv4 into lp:launchpad

Proposed by Richard Harding
Status: Work in progress
Proposed branch: lp:~rharding/launchpad/yuiv4
Merge into: lp:launchpad
Diff against target: 180 lines (+120/-13)
3 files modified
Makefile (+1/-1)
buildout-templates/bin/yui_extract.in (+113/-0)
buildout.cfg (+6/-12)
To merge this branch: bzr merge lp:~rharding/launchpad/yuiv4
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+117800@code.launchpad.net

Description of the change

TBD

To post a comment you must log in.

Unmerged revisions

15733. By Richard Harding

I wonder if this will work

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2012-07-13 01:55:27 +0000
3+++ Makefile 2012-08-01 21:25:23 +0000
4@@ -66,7 +66,7 @@
5 bin/killservice bin/kill-test-services bin/lint.sh bin/retest \
6 bin/run bin/run-testapp bin/sprite-util bin/start_librarian bin/stxdocs \
7 bin/tags bin/test bin/tracereport bin/twistd bin/update-download-cache \
8- bin/watch_jsbuild
9+ bin/watch_jsbuild bin/yui_extract
10
11 BUILDOUT_TEMPLATES = buildout-templates/_pythonpath.py.in
12
13
14=== added file 'buildout-templates/bin/yui_extract.in'
15--- buildout-templates/bin/yui_extract.in 1970-01-01 00:00:00 +0000
16+++ buildout-templates/bin/yui_extract.in 2012-08-01 21:25:23 +0000
17@@ -0,0 +1,113 @@
18+#!${buildout:executable}
19+#
20+# Copyright 2012 Canonical Ltd. This software is licensed under the
21+# GNU Affero General Public License version 3 (see the file LICENSE).
22+"""
23+Extract the YUI library from the zip file in the download-cache into the build
24+directory for our JS.
25+
26+Usage:
27+
28+ yui_extract -y 3.5.1 -d download-cache/dist -b build/js
29+
30+"""
31+import argparse
32+import os
33+from os.path import (
34+ basename,
35+ exists,
36+ isdir,
37+ join,
38+ )
39+import shutil
40+import sys
41+from zipfile import ZipFile
42+
43+YUI_ZIP = "yui_%s.zip"
44+YUI_DIR = None
45+
46+
47+def _parse_args():
48+ """Parse out the command options. We want to support
49+
50+ """
51+ desc = "Extract YUI zip files into the build tree."
52+
53+ parser = argparse.ArgumentParser(description=desc)
54+
55+ parser.add_argument('-y', '--yui-version', dest='yui_version',
56+ action='store',
57+ default=None,
58+ required=True,
59+ help='What version of YUI to extract.')
60+
61+ parser.add_argument('-d', '--download-cache', dest="download_cache",
62+ action="store",
63+ default=None,
64+ required=True,
65+ help="Location of the download cache to find the YUI zip file.")
66+
67+ parser.add_argument('-b', '--build-dir', dest="build_dir",
68+ action="store",
69+ default=None,
70+ required=True,
71+ help="Location to extract the YUI zip to.")
72+
73+ args = parser.parse_args()
74+ return args
75+
76+
77+def _unzip(yui_zip, build_dir):
78+ """Unzip the yui file and place the files into the build dir."""
79+ # Zip extraction occurs into the cwd so change that.
80+ yui_dirname = basename(yui_zip).replace('.zip', '').replace('_', '-')
81+ yui_dir = join(build_dir, yui_dirname)
82+ tmp_dir = join(build_dir, 'tmp')
83+
84+ # If the directory isn't there to remove, ignore it. If it does exist
85+ # remove it so we drop our zip contents.
86+ shutil.rmtree(yui_dir, ignore_errors=True)
87+ shutil.rmtree(tmp_dir, ignore_errors=True)
88+
89+ os.makedirs(tmp_dir)
90+
91+ try:
92+ zip = ZipFile(yui_zip, 'r')
93+ zip.extractall(tmp_dir)
94+ shutil.copytree(join(tmp_dir, 'yui', 'build'), yui_dir)
95+ except Exception, exc:
96+ sys.exit(exc)
97+ finally:
98+ # Make sure that we remove the tmp dir no matter what.
99+ shutil.rmtree(tmp_dir, ignore_errors=True)
100+
101+
102+def _validate_args(args):
103+ """Verify that the args are valid.
104+
105+ The download cache exists.
106+ We have a zip file for the YUI version specified.
107+ The build directory exists.
108+
109+ """
110+ if not isdir(args.download_cache):
111+ sys.exit('Download cache not found.')
112+
113+ if not isdir(args.build_dir):
114+ sys.exit('Build directory not found.')
115+
116+ yui_zip = "%s/%s" % (args.download_cache, YUI_ZIP % args.yui_version)
117+ if not exists(yui_zip):
118+ sys.exit('Could not find download: ' + yui_zip)
119+
120+def main(args):
121+ """"""
122+ # If any args aren't valid then output info on how to correct.
123+ _validate_args(args)
124+ yui_zip = "%s/%s" % (args.download_cache, YUI_ZIP % args.yui_version)
125+ _unzip(yui_zip, args.build_dir)
126+
127+
128+if __name__ == "__main__":
129+ args = _parse_args()
130+ main(args)
131
132=== modified file 'buildout.cfg'
133--- buildout.cfg 2012-07-25 21:09:38 +0000
134+++ buildout.cfg 2012-08-01 21:25:23 +0000
135@@ -3,7 +3,6 @@
136
137 [buildout]
138 parts =
139- yui-default
140 scripts
141 filetemplates
142 tags
143@@ -11,6 +10,9 @@
144 i18n
145 txlongpoll
146 auditor
147+ yui-default
148+ yui-3.5
149+
150 unzip = true
151 eggs-directory = eggs
152 download-cache = download-cache
153@@ -40,24 +42,16 @@
154 [yui]
155 recipe = plone.recipe.command
156 command =
157- mkdir -p ${buildout:yui-directory}/yui-${:yui_version}
158- rm -rf ${buildout:yui-directory}/yui-${:yui_version}/*
159- tar -zxf download-cache/dist/yui-${:yui_version}.tar.gz \
160- --wildcards --strip-components 2 \
161- -C ${buildout:yui-directory}/yui-${:yui_version} \
162- '*/build'
163+ mkdir -p ${buildout:yui-directory}
164+ bin/yui_extract --yui-version ${:yui_version} --download-cache download-cache/dist --build-dir ${buildout:yui-directory}
165
166 [yui-default]
167 <= yui
168 yui_version = ${versions:yui}
169
170-[yui-3.4]
171-<= yui
172-yui_version = 3.4.1
173-
174 [yui-3.5]
175 <=yui
176-yui_version = 3.5.0pr1
177+yui_version = 3.5.1
178
179 [filetemplates]
180 recipe = z3c.recipe.filetemplate