[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bricolage-commits
Subject:    [6152] added display of output channels,
From:       slanning () bricolage ! cc
Date:       2005-01-17 16:10:32
Message-ID: 20050117161032.27357.qmail () x1 ! develooper ! com
[Download RAW message or body]

Revision: 6152
Author:   slanning
Date:     2005-01-17 08:10:30 -0800 (Mon, 17 Jan 2005)
ViewCVS:  http://viewsvn.bricolage.cc/?rev=6152&view=rev

Log Message:
-----------
added display of output channels,
option to only display top-level elements,
symbols for required/repeatable fields

Modified Files:
--------------
    bricolage/branches/rev_1_8/contrib/show_element_tree/README
    bricolage/branches/rev_1_8/contrib/show_element_tree/element_tree.pl



["r6152-slanning.diff" (r6152-slanning.diff)]

Modified: bricolage/branches/rev_1_8/contrib/show_element_tree/README
===================================================================
--- bricolage/branches/rev_1_8/contrib/show_element_tree/README	2005-01-16 15:16:12 \
                UTC (rev 6151)
+++ bricolage/branches/rev_1_8/contrib/show_element_tree/README	2005-01-17 16:10:30 \
UTC (rev 6152) @@ -1,16 +1,27 @@
 Description:
-  Prints out elements and their subelements and custom fields
-  using the output from `bric_soap element export`.
+  Prints out elements and their subelements, custom fields, and output
+  channels using the output from `bric_soap element export`.
 
 Usage:
   $ bric_soap element list_ids | bric_soap element export - > elements.xml
   $ ./element-tree.pl elements.xml
-  See also the comments in the script.
+  See the comments in the script for how to control the display
+  of custom fields, output channels, and non top-level elements.
 
+  Display of elements is in the following format:
+
+    Element name (field, repeatable_field*, required_field!, ...)
+    . Child element (fields...)
+    . . Subchildren (...)
+    > Primary output channel, other output channels
+
 Todo:
-  Show output channels for top-level elements.
   Maybe show the description.
   Maybe not show isolated non-top-level elements, like utility templates.
 
+Bugs:
+  Output channels are badly handled for version 1.8: the primary OC
+  isn't determined, and there is no distinction between sites.
+
 Author:
   o  Scott Lanning, 2004-12-17

Modified: bricolage/branches/rev_1_8/contrib/show_element_tree/element_tree.pl
===================================================================
--- bricolage/branches/rev_1_8/contrib/show_element_tree/element_tree.pl	2005-01-16 \
                15:16:12 UTC (rev 6151)
+++ bricolage/branches/rev_1_8/contrib/show_element_tree/element_tree.pl	2005-01-17 \
16:10:30 UTC (rev 6152) @@ -3,8 +3,7 @@
 # using a bric_soap export of elements
 # $ bric_soap element list_ids | bric_soap element export - > elements.xml
 # $ ./element-tree.pl elements.xml
-# Handles 1.6 or 1.8 version of bric_soap. Has the option to
-# not display the fields (see $WITHFIELDS).
+# Handles 1.6 or 1.8 versions of bric_soap.
 
 use strict;
 use warnings;
@@ -12,10 +11,13 @@
 
 my $CHILDMARKER = '. ';   # what's in front of subelements
 my $WITHFIELDS = 1;       # whether to display fields
+my $WITHOCS = 1;          # whether to display output channels
+my $TOPLEVEL_ONLY = 1;    # whether to only show toplevel elements
 my %ELEMENT;
 
 main();
 
+
 sub main {
     $|++;
     parse_xml_elements();
@@ -36,11 +38,15 @@
 sub get_element_info {
     my ($t, $node) = @_;
 
+    # name
     my $name = $node->first_child_text('key_name');
     # (before 1.8 we didn't have key_name)
     $name = $node->first_child_text('name') unless $name;
     die "wtf version of bricolage are you running?" unless $name;
 
+    # top-level
+    $ELEMENT{$name}{top_level} = $node->first_child_text('top_level');
+
     # subelements
     my @children = sort $node->first_child('subelements')->children_text;
     $ELEMENT{$name}{children} = [@children];
@@ -52,9 +58,29 @@
         my $fieldname = $field->first_child_text('key_name');
         # (before 1.8 we had name instead of key_name)
         $fieldname = $field->first_child_text('name') unless $fieldname;
+
+        my $repeatable = $field->first_child_text('repeatable') ? '*' : '';
+        my $required = $field->first_child_text('required') ? '!' : '';
+        $fieldname .= "$repeatable$required";
+
         push @fieldnames, $fieldname;
     }
     $ELEMENT{$name}{fields} = [sort @fieldnames];
+
+    # output channels
+    if ($ELEMENT{$name}{top_level}) {
+        my @ocs = $node->first_child('output_channels')->children('output_channel');
+        $ELEMENT{$name}{output_channels} = [];
+        foreach my $oc (@ocs) {
+            my $ocname = $oc->text;
+            my $is_primary = exists($oc->{att}{primary}) ? 1 : 0;
+            if ($is_primary) {
+                unshift @{ $ELEMENT{$name}{output_channels} }, $ocname;
+            } else {
+                push @{ $ELEMENT{$name}{output_channels} }, $ocname;
+            }
+        }
+    }
 }
 
 # determine each element's parent (if it has one)
@@ -65,7 +91,7 @@
                 $ELEMENT{$child}{parent} = $element;
             } else {
                 # should never happen
-                die "element=$element, child=$child\n";
+                die "All the elements aren't there: element=$element, \
child=$child\n";  }
         }
     }
@@ -100,15 +126,23 @@
       if $WITHFIELDS;
 }
 
+sub print_ocs {
+    my $element = shift;
+    print '> ', join(', ', @{ $ELEMENT{$element}{output_channels} }), $/;
+}
+
 # display parent-less elements and recursively their subelements
 sub print_parents {
     my @parents = grep {!exists $ELEMENT{$_}{parent}}
       sort {lc($a) cmp lc($b)} keys %ELEMENT;
     foreach my $element (@parents) {
+        next if $TOPLEVEL_ONLY and not $ELEMENT{$element}{top_level};
+
         print "\n$element";
         print_fields($element);
         print $/;
         my @parentstack = ($element);
         print_children($element, \@parentstack);
+        print_ocs($element) if $ELEMENT{$element}{top_level};
     }
 }



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic