svg2-tools: Move directories-to-copy from build.pl to publish.xml.

Move directories-to-copy from build.pl to publish.xml.

diffstat:

 build.py           |  25 ++++++++++++-------------
 publish/config.js  |   7 +++++++
 publish/publish.js |  13 ++++++++++++-
 3 files changed, 31 insertions(+), 14 deletions(-)

diffs (204 lines):

diff --git a/build.py b/build.py
--- a/build.py
+++ b/build.py
@@ -5,29 +5,19 @@
 
 # Note that we have to change directory below to make sure that build output
 # goes in the 'build' directory, not in the 'master' directory. For that
 # reason it's important that we use absolute paths!
 
 '''
 '''
 
-# It would be good if "tocopy" list could be extracted from
-# publish.xml instead of being hard coded here.
-
-tocopy = """
-  style
-  images
-  examples
-""".split()
-
-
-
 import os, sys, signal, commands
 from os.path import isfile, abspath, getmtime, exists, join, normpath
+from xml.dom import minidom
 import shutil
 
 def exit(code, *message):
   if len(message):
     if code == 0:
       print message[0]
     else:
       sys.stderr.write(message[0] + '\n')
@@ -110,27 +100,36 @@ if len(sys.argv) == 2 and sys.argv[1] ==
     for file in files[:]:
       file = join(parent, file)
       if file != readme:
         os.remove(file)
     for dir in dirs[:]:
       os.rmdir(join(parent, dir))
   sys.exit(0)
 
-# Get all the pages from publish.xml:
+# Get all the pages and resources from publish.xml:
 
 os.chdir(master_dir)
 status, output = getstatusoutput("node \"" +
     native_path(join(tools_dir, "publish/publish.js")) + "\" --list-pages")
 os.chdir(repo_dir)
 if status != 0:
   exit(1, 'FAIL: could not get list of specification pages')
 
 all = output.split()
 
+os.chdir(master_dir)
+status, output = getstatusoutput("node \"" +
+    native_path(join(tools_dir, "publish/publish.js")) + "\" --list-resources")
+os.chdir(repo_dir)
+if status != 0:
+  exit(1, 'FAIL: could not get list of resources')
+
+resources = output.split()
+
 # Build chapters as required:
 
 deps = [
   join(master_dir, "publish.xml"),
   join(master_dir, "definitions.xml"),
 ]
 for filename in os.listdir(publishjs_dir):
   path = join(publishjs_dir, filename)
@@ -181,17 +180,17 @@ else:
 if buildSinglePage:
   os.chdir(master_dir)
   run("node \"" +
       native_path(join(tools_dir, join("publish","publish.js"))) +
       "\" --build-single-page")
   os.chdir(repo_dir) # chdir back
 
 # Copy over anything else that needs to be copied to 'publish':
-for f in tocopy:
+for f in resources:
   tocopypath = join(master_dir, f)
   if os.path.exists(tocopypath):
     copyto = os.path.join(publish_dir,os.path.basename(tocopypath))
     shutil.rmtree(copyto, ignore_errors=True)
     shutil.copytree(tocopypath, copyto)
 
 # Done:
 
diff --git a/publish/config.js b/publish/config.js
--- a/publish/config.js
+++ b/publish/config.js
@@ -142,16 +142,23 @@ function Config(filename) {
   var definitionsFilenamesAndBases = [];
   for (var n = root.firstChild; n; n = n.nextSibling) {
     if (n.nodeName == 'definitions') {
       definitionsFilenamesAndBases.push([n.getAttribute('href'), n.getAttribute('base') || null]);
     }
   }
   this.definitions = definitions.load(definitionsFilenamesAndBases.reverse());
 
+  this.resources = [];
+  for (var n = root.firstChild; n; n = n.nextSibling) {
+    if (n.nodeName == 'resource') {
+      this.resources.push(n.getAttribute('href'));
+    }
+  }
+
   this.interfacesFile = attr(root, 'interfaces', 'idl');
   this.pages = { };
   this.pageOrder = [];
 
   var chapter = 1, appendix = 1;
   for (var n = root.firstChild; n; n = n.nextSibling) {
     if (n.nodeType != 1) continue;
     var name = n.getAttribute('name');
diff --git a/publish/publish.js b/publish/publish.js
--- a/publish/publish.js
+++ b/publish/publish.js
@@ -7,30 +7,35 @@ var config = require('./config.js'),
 
 var conf;
 
 function syntax() {
   console.error('Usage: node publish.js options');
   console.error('');
   console.error('Options:');
   console.error('  --list-pages            Print the names of all pages of the specification.');
+  console.error('  --list-resources        Print the names of all resource files/directories');
+  console.error('                            to be copied to the publish directory.');
   console.error('  --build [PAGE ...]      Builds the specified pages, or all pages if');
   console.error('                            none specified.');
   console.error('  --build-single-page     Builds the single page version of the specification.');
   console.error('  --local-style           Link to local W3C style sheets rather than w3.org.');
   console.error('  --help                  Show this message.');
 }
 
 function parseOptions() {
   var opts = { rest: [] };
   for (var i = 2; i < process.argv.length; i++) {
     switch (process.argv[i]) {
       case '--list-pages':
         opts.listPages = true;
         break;
+      case '--list-resources':
+        opts.listResources = true;
+        break;
       case '--build':
         opts.build = true;
         break;
       case '--build-single-page':
         opts.buildSinglePage = true;
         break;
       case '--local-style':
         opts.localStyle = true;
@@ -48,16 +53,20 @@ function parseOptions() {
   }
   return opts;
 }
 
 function listPages() {
   console.log(conf.pageOrder.join('\n'));
 }
 
+function listResources() {
+  console.log(conf.resources.join('\n'));
+}
+
 function checkAllPagesValid(pages) {
   for (var i = 0; i < pages.length; i++) {
     if (!conf.pages[pages[i]]) {
       var invalid = [pages[i]];
       while (++i < pages.length) {
         if (!conf.pages[pages[i]]) {
           invalid.push(pages[i]);
         }
@@ -188,22 +197,24 @@ function buildSinglePage() {
   if (foundMathjax) {
     head.appendChild(utils.parse('<script src="style/load-mathjax.js"></script>'));
   }
 
   fs.writeFileSync(outputFilename, doc.toString());
 }
 
 var opts = parseOptions();
-if (opts.help || (!!opts.listPages + !!opts.build + !!opts.buildSinglePage) != 1) {
+if (opts.help || (!!opts.listPages + !!opts.listResources + !!opts.build + !!opts.buildSinglePage) != 1) {
   syntax();
   process.exit(opts.help ? 0 : 1);
 } else {
   conf = config.load('publish.xml');
   conf.localStyleSheets = opts.localStyle;
   if (opts.listPages) {
     listPages();
+  } else if (opts.listResources) {
+    listResources();
   } else if (opts.build) {
     buildPages(opts.rest);
   } else if (opts.buildSinglePage) {
     buildSinglePage();
   }
 }

Received on Friday, 5 April 2013 07:34:18 UTC