Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(826)

Unified Diff: sdk/lib/html/scripts/multiemitter.py

Issue 11691009: Moved most of html lib generating scripts into tools. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/html/scripts/logging.conf ('k') | sdk/lib/html/scripts/multiemitter_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/scripts/multiemitter.py
diff --git a/sdk/lib/html/scripts/multiemitter.py b/sdk/lib/html/scripts/multiemitter.py
deleted file mode 100644
index 19d90003be7332b21aed11b1c6047d8a794b1f2d..0000000000000000000000000000000000000000
--- a/sdk/lib/html/scripts/multiemitter.py
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/python
-# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
-# for details. All rights reserved. Use of this source code is governed by a
-# BSD-style license that can be found in the LICENSE file.
-
-"""Templating to help generate structured text."""
-
-import os
-import re
-import emitter
-import logging
-
-_logger = logging.getLogger('multiemitter')
-
-class MultiEmitter(object):
- """A set of Emitters that write to different files.
-
- Each entry has a key.
-
- file --> emitter
- key --> emitter
-
- """
-
- def __init__(self):
- self._key_to_emitter = {} # key -> Emitter
- self._filename_to_emitter = {} # filename -> Emitter
-
-
- def FileEmitter(self, filename, key=None):
- """Creates an emitter for writing to a file.
-
- When this MultiEmitter is flushed, the contents of the emitter are written
- to the file.
-
- Arguments:
- filename: a string, the path name of the file
- key: provides an access key to retrieve the emitter.
-
- Returns: the emitter.
- """
- e = emitter.Emitter()
- self._filename_to_emitter[filename] = e
- if key:
- self.Associate(key, e)
- return e
-
- def Associate(self, key, emitter):
- """Associates a key with an emitter."""
- self._key_to_emitter[key] = emitter
-
- def Find(self, key):
- """Returns the emitter associated with |key|."""
- return self._key_to_emitter[key]
-
- def Flush(self, writer=None):
- """Writes all pending files.
-
- Arguments:
- writer: a function called for each file and it's lines.
- """
- if not writer:
- writer = _WriteFile
- for file in sorted(self._filename_to_emitter.keys()):
- emitter = self._filename_to_emitter[file]
- writer(file, emitter.Fragments())
-
-
-def _WriteFile(path, lines):
- (dir, file) = os.path.split(path)
-
- # Ensure dir exists.
- if dir:
- if not os.path.isdir(dir):
- os.makedirs(dir)
-
- # Remove file if pre-existing.
- if os.path.exists(path):
- os.remove(path)
-
- # Write the file.
- # _logger.info('Flushing - %s' % path)
- f = open(path, 'w')
- f.writelines(lines)
- f.close()
« no previous file with comments | « sdk/lib/html/scripts/logging.conf ('k') | sdk/lib/html/scripts/multiemitter_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698