head	1.2;
access;
symbols
	TIGRIS_1_1_0RC2:1.2
	TIGRIS_1_1_0RC1:1.2
	TIGRIS_1_1:1.2.0.4
	TIGRIS_1_0_8:1.2
	TIGRIS_1_0_8RC3:1.2
	TIGRIS_1_0_8RC2:1.2
	TIGRIS_1_0_8RC1:1.2
	TIGRIS_1_0_7:1.2
	TIGRIS_1_0_7RC3:1.2
	TIGRIS_1_0_7RC2:1.2
	TIGRIS_1_0_7RC1:1.2
	TIGRIS_1_0_6:1.2
	TIGRIS_1_0_6RC5:1.2
	TIGRIS_1_0_6RC4:1.2
	TIGRIS_1_0_6RC3:1.2
	TIGRIS_1_0_6RC2:1.2
	TIGRIS_1_0_6RC1:1.2
	TIGRIS_1_0_5:1.2
	TIGRIS_1_0_5RC6:1.2
	TIGRIS_1_0_5RC5:1.2
	TIGRIS_1_0_5RC4:1.2
	TIGRIS_1_0_5RC3:1.2
	TIGRIS_1_0_5RC2:1.2
	TIGRIS_1_0_5RC1:1.2
	TIGRIS_1_0_4:1.2
	TIGRIS_1_0_3:1.2
	TIGRIS_1_0_2:1.2
	TIGRIS_1_0_1:1.2
	TIGRIS_1_0:1.2.0.6
	TIGRIS_1_0_0:1.2
	TIGRIS_1_0_0_RC1:1.2.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.1
	TIGRIS_0_9_2_3:1.1
	HELM_PEER_PORT_BRANCH:1.1.1.1
	TURBINE_PEER:1.2
	TIGRIS_0_9_2_1:1.2
	TIGRIS_0_9_2:1.1.0.2;
locks; strict;
comment	@# @;


1.2
date	2001.01.22.19.15.13;	author kmaples;	state Exp;
branches;
next	1.1;

1.1
date	2001.01.18.04.27.01;	author kmaples;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2001.02.21.00.36.24;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Script cleanup; drop '.' at the beginning of style defs before inserting
into database; skip global css defs., etc.
@
text
@#!/usr/bin/perl
# ================================================================
# Copyright (c) 2001 CollabNet.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. The end-user documentation included with the redistribution, if
# any, must include the following acknowlegement: "This product includes
# software developed by Collab.Net (http://www.Collab.Net/)."
# Alternately, this acknowlegement may appear in the software itself, if
# and wherever such third-party acknowlegements normally appear.
#
# 4. The hosted project names must not be used to endorse or promote
# products derived from this software without prior written
# permission. For written permission, please contact info@@collab.net.
#
# 5. Products derived from this software may not use the "Tigris" name
# nor may "Tigris" appear in their names without prior written
# permission of Collab.Net.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ====================================================================
#
# This software consists of voluntary contributions made by many
# individuals on behalf of CollabNet.
#

# 
# $Id: css2skin.pl,v 1.1 2001/01/18 04:27:01 kmaples Exp $
# 
# css2skin.pl
#
# original author: kmaples@@collab.net
#
# Utility script to take a css file, and populate Helm's 'skins' 
# tables with the data.
# 
# Usage: css2skin.pl [skin_name] [css_file]

# ====================================================================

use DBI;
use strict;

# Stuff grabbed from env.sh:

my $DB     = $ENV{DATABASE_NAME};
my $DBPW   = $ENV{DATABASE_ADMIN_PASSWORD};
my $DBUSR  = $ENV{DATABASE_ADMIN_USER};
my $DBHOST = $ENV{DATABASE_HOST};
my $DBPORT = $ENV{DATABASE_PORT};

my $dbc = join(':', 'DBI', 'mysql', $DB, $DBHOST, $DBPORT);
my $CONN = DBI->connect($dbc, $DBUSR, $DBPW, {PrintError => 0, RaiseError => 0});
my ($select, $ret, $cmd);

my ($skin_name, $file) = @@ARGV;

my $LINES;
my %STYLE;
my %STYLE_GLOBAL;
my %STYLE_DUPLICATE;

my $SKIN_ID;

## Check args:
unless(@@ARGV){
    my $script_name = $0;
    $script_name =~ s/^.*\/([\w]+)$/$1/;

    print "$script_name: usage:";
    print "\t$script_name [skin name] [css file]\n";
}
unless(-e $file){
    print "File '$file' doesn't exist.  Exiting.\n";
    exit;
}

## Check DB connection:
if(!$CONN){
    print "No connection to database.  Exiting.\n";
    exit;
} else {
    print "Connection to $dbc established\n";
}

## Get .css file:
open(F, "<$file") or die "Unable to open $file:$!\n";
    while(<F>){ $LINES .= $_; }
close(F) or die  "Unable to close $file:$!\n";

## Parse the file contents:
while($LINES =~ s/^\s*([.\w]:?[^\s]+)\s*\{([^}]+)\}//ms ){
    
    my $stylename = $1;
    my $tmp_attr  = $2;
    my %attributes;
    
#   print "STYLENAME: $stylename\nATTRIBUTE: $tmp_attr\n";

    while( $tmp_attr =~ s/\b([^:]+:[^:]+\w)\s*;//ms ){
        my ($n,$v) = split(':',$1);
        $n =~ s/^\s*//; 
        $v =~ s/^\s*//;
        $attributes{$n} = $v;
    }

    ## Filter global css tags which appear in the form 
    ## '[TAG]:[STYLENAME]':
    if($stylename =~ m/^\w+:/){
        print "WARNING: found global def; skipping\n";
        $STYLE_GLOBAL{$stylename} = \%attributes;
        next;
    } else {
        ## Get rid of the '.' at the beginning of styles
        $stylename =~ s/\.//;
    }

    if($STYLE{$stylename}){
        print "WARNING: duplicate styles named '$stylename' were found\n";
        print "  Ignoring second definition...\n";
        
        ## Preserve this in the STYLE_DUPLICATE hash, but
        ## ignore for the time being:
        $STYLE_DUPLICATE{$stylename} = \%attributes;        
        next;
    } else {
        $STYLE{$stylename} = \%attributes;
    }
#   foreach(keys(%attributes)){ print " key:'$_'\n value:'$attributes{$_}'\n"; }    
}

## Do the inserts:
## Test for unique name:
$skin_name = $CONN->quote( $skin_name );
$cmd = qq[
    SELECT * FROM HELM_SKIN WHERE
    NAME   = $skin_name
];

$select = $CONN->prepare($cmd);
$ret    = $select->execute;

if($ret && $ret ne '0E0'){
    print "Skin named $skin_name already exists.  Exiting.\n";
} else {
    ## Begin inserting style info:
    print "\n===== BEGINING SQL GENERATION ===== \n\n";
    
    $cmd = qq[INSERT INTO HELM_SKIN SET NAME=$skin_name];   
    perform_insert($CONN,$cmd);
    
    $cmd     = qq[SELECT SKIN_ID FROM HELM_SKIN WHERE NAME=$skin_name];
    $SKIN_ID = perform_select_one_element($CONN, $cmd);
    
    foreach(keys(%STYLE)){ 
#        print " FOREACH key:'$_'\n value:'$STYLE{$_}'\n"; 
        my $current_style = $_;
        my $hashref = $STYLE{$_};
        my ($style_id, $element_id);
        
        $current_style = $CONN->quote( $current_style );
         
        for(1 .. 3){ ## Gonna try this three times, then give up    
            $cmd = qq[SELECT STYLE_ID FROM HELM_STYLE WHERE NAME=$current_style];
            $style_id = perform_select_one_element($CONN, $cmd);
            
            if($style_id){
                last;
            } else {
                $cmd = qq[INSERT INTO HELM_STYLE SET NAME=$current_style];
                perform_insert($CONN,$cmd);
            }
        }
        unless($style_id){
            print "# !!! WARNING: couldn't get a STYLE_ID!\n";
            next;
        }
        while(my($attribute, $value) = each(%{$hashref})){
#           print "attr: $attribute\n val: $value\n";
            $attribute = $CONN->quote( $attribute );
            $value     = $CONN->quote( $value );

            $cmd = qq[SELECT ELEMENT_ID FROM HELM_STYLEELEMENT WHERE CSS_NAME=$attribute];
            $element_id = perform_select_one_element($CONN, $cmd);             
           
            unless($element_id){
                $cmd = qq[INSERT INTO HELM_STYLEELEMENT SET CSS_NAME=$attribute];
                perform_insert($CONN,$cmd);
                
                $cmd = qq[SELECT ELEMENT_ID FROM HELM_STYLEELEMENT WHERE CSS_NAME=$attribute];
                $element_id = perform_select_one_element($CONN, $cmd);
            }

            $cmd = qq[INSERT INTO HELM_SKIN_STYLE_ELEMENT_VALUE SET
                SKIN_ID=$SKIN_ID, STYLE_ID=$style_id, ELEMENT_ID=$element_id, VALUE=$value];
            perform_insert($CONN,$cmd);
        }
    }
}

## sql's done; print the remainders:
print "\n===== END SQL GENERATION ===== \n\n";
print "The following duplicate definitions were found (and ignored):\n";
foreach(keys(%STYLE_DUPLICATE)){
    my $key = $_;
    my $hashref = $STYLE_DUPLICATE{$_};
    print "STYLE: $key\n";
    print "DEFINITION:\n";
    while(my($attribute, $value) = each(%{$hashref})){
        print "    $attribute: $value;\n";
    }
}
print "The following global definitions were found (and ignored):\n";
foreach(keys(%STYLE_GLOBAL)){
    my $key = $_;
    my $hashref = $STYLE_GLOBAL{$_};
    print "STYLE: $key\n";
    print "DEFINITION:\n";
    while(my($attribute, $value) = each(%{$hashref})){
        print "    $attribute: $value;\n";
    
    }
}

if($select){ $select->finish(); }
$CONN->disconnect;

#---------------
sub perform_insert{
#---------------
    ## perform_insert(connection, command): 

    my $CONN = shift;
    my $cmd  = shift;

#   print "...performing $cmd...\n";
    my $select = $CONN->prepare($cmd);
    my $ret    = $select->execute;
    
    $cmd =~ s/^\s*//g; ## Pretty up for display
    
    if($ret && $ret ne '0E0'){
        print "$cmd;\n"
    } else {
        print "!! WARNING: UNABLE TO EXECUTE: $cmd\n";
    }   
    return;
}
#---------------
sub perform_select_one_element{
#---------------
    ## element = perform_select_one_element(connection, command):
    
    my $CONN = shift;
    my $cmd  = shift;

#   print "...selecting $cmd...\n";

    my $select  = $CONN->prepare($cmd);
    my $ret     = $select->execute;
    my $element = ($select->fetchrow_array)[0];
    
    return($element);
}


__END__


@


1.1
log
@Utility script to populate Helm 'skins' tables from a css file
@
text
@d49 1
a49 1
# $Id: $
d60 2
d78 1
d81 3
d127 12
d142 4
d168 1
a168 1
    print "BEGINING SQL GENERATION: \n";
d171 1
a171 1
    perform_insert($cmd);
d174 1
a174 3
    $select  = $CONN->prepare($cmd);
    $ret     = $select->execute;
    $SKIN_ID = ($select->fetchrow_array)[0];
a175 2
#    print "RET WAS $ret\nSKIN_ID = $SKIN_ID\n";
        
d186 1
a186 3
            $select      = $CONN->prepare($cmd);
            $ret         = $select->execute;
            $style_id = ($select->fetchrow_array)[0];
d192 1
a192 1
                perform_insert($cmd);
d196 1
a196 1
            print "!! WARNING: couldn't get a STYLE_ID!\n";
d205 1
a205 4
#           print "FIRST SELECT: $cmd\n";
            $select      = $CONN->prepare($cmd);
            $ret         = $select->execute;
            $element_id = ($select->fetchrow_array)[0];             
a207 1
#               print "FIRST SELECT FAILED, TRYING INSERT\n";               
d209 1
a209 1
                perform_insert($cmd);
d212 1
a212 4
#               print "SECOND SELECT: $cmd\n";
                $select      = $CONN->prepare($cmd);
                $ret         = $select->execute;
                $element_id = ($select->fetchrow_array)[0];
d217 1
a217 1
            perform_insert($cmd);
d222 24
d252 5
a256 1
    my $cmd = shift;
a265 1
#       print "RET was $ret\n";
d269 16
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d49 1
a49 1
# $Id: css2skin.pl,v 1.2 2001/01/22 19:15:13 kmaples Exp $
a59 2
# ====================================================================

a75 1

a77 3
my %STYLE_GLOBAL;
my %STYLE_DUPLICATE;

a120 12

    ## Filter global css tags which appear in the form 
    ## '[TAG]:[STYLENAME]':
    if($stylename =~ m/^\w+:/){
        print "WARNING: found global def; skipping\n";
        $STYLE_GLOBAL{$stylename} = \%attributes;
        next;
    } else {
        ## Get rid of the '.' at the beginning of styles
        $stylename =~ s/\.//;
    }

a123 4
        
        ## Preserve this in the STYLE_DUPLICATE hash, but
        ## ignore for the time being:
        $STYLE_DUPLICATE{$stylename} = \%attributes;        
d146 1
a146 1
    print "\n===== BEGINING SQL GENERATION ===== \n\n";
d149 1
a149 1
    perform_insert($CONN,$cmd);
d152 3
a154 1
    $SKIN_ID = perform_select_one_element($CONN, $cmd);
d156 2
d168 3
a170 1
            $style_id = perform_select_one_element($CONN, $cmd);
d176 1
a176 1
                perform_insert($CONN,$cmd);
d180 1
a180 1
            print "# !!! WARNING: couldn't get a STYLE_ID!\n";
d189 4
a192 1
            $element_id = perform_select_one_element($CONN, $cmd);             
d195 1
d197 1
a197 1
                perform_insert($CONN,$cmd);
d200 4
a203 1
                $element_id = perform_select_one_element($CONN, $cmd);
d208 1
a208 1
            perform_insert($CONN,$cmd);
a212 24
## sql's done; print the remainders:
print "\n===== END SQL GENERATION ===== \n\n";
print "The following duplicate definitions were found (and ignored):\n";
foreach(keys(%STYLE_DUPLICATE)){
    my $key = $_;
    my $hashref = $STYLE_DUPLICATE{$_};
    print "STYLE: $key\n";
    print "DEFINITION:\n";
    while(my($attribute, $value) = each(%{$hashref})){
        print "    $attribute: $value;\n";
    }
}
print "The following global definitions were found (and ignored):\n";
foreach(keys(%STYLE_GLOBAL)){
    my $key = $_;
    my $hashref = $STYLE_GLOBAL{$_};
    print "STYLE: $key\n";
    print "DEFINITION:\n";
    while(my($attribute, $value) = each(%{$hashref})){
        print "    $attribute: $value;\n";
    
    }
}

d219 1
a219 5
    ## perform_insert(connection, command): 

    my $CONN = shift;
    my $cmd  = shift;

d229 1
a232 16
}
#---------------
sub perform_select_one_element{
#---------------
    ## element = perform_select_one_element(connection, command):
    
    my $CONN = shift;
    my $cmd  = shift;

#   print "...selecting $cmd...\n";

    my $select  = $CONN->prepare($cmd);
    my $ret     = $select->execute;
    my $element = ($select->fetchrow_array)[0];
    
    return($element);
@


