2011-04-27 Tony Chang <tony@chromium.org>
[WebKit-https.git] / Source / WebKit / chromium / scripts / concatenate_css_files.py
index 0aa5ef30a640d6f96f01c090d17e27acdaaffb3c..6281b3f5684120233f0ae29a5e5bbd091c99e7cb 100644 (file)
@@ -32,6 +32,8 @@
 # This script concatenates in place CSS files in the order specified
 # using <link> tags in a given 'order.html' file.
 
+from __future__ import with_statement
+
 from HTMLParser import HTMLParser
 from cStringIO import StringIO
 import os.path
@@ -40,11 +42,10 @@ import sys
 
 class OrderedCSSFilesExtractor(HTMLParser):
 
-    def __init__(self, order_html_name):
+    def __init__(self, order_html):
         HTMLParser.__init__(self)
         self.ordered_css_files = []
-        order_html = open(order_html_name, 'r')
-        self.feed(order_html.read())
+        self.feed(order_html)
 
     def handle_starttag(self, tag, attrs):
         if tag == 'link':
@@ -82,7 +83,8 @@ def main(argv):
 
     output_file_name = argv.pop()
     input_order_file_name = argv[1]
-    extractor = OrderedCSSFilesExtractor(input_order_file_name)
+    with open(input_order_file_name, 'r') as order_html:
+        extractor = OrderedCSSFilesExtractor(order_html.read())
     # Unconditionally append devTools.css. It will contain concatenated files.
     extractor.ordered_css_files.append('devTools.css')