From: Michael Wiebusch Date: Thu, 25 Jul 2013 16:31:15 +0000 (+0200) Subject: modularized my code further, created xmlOperation.pl as a CGI portal to functionality... X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=afd711da2c834cf016cb7481723394cc9dc92710;p=mvdsensorcontrol.git modularized my code further, created xmlOperation.pl as a CGI portal to functionality in xmlOperations.pm --- diff --git a/tools/Common.pm b/tools/Common.pm index 555577a..913be8c 100644 --- a/tools/Common.pm +++ b/tools/Common.pm @@ -8,6 +8,14 @@ ## misc utilities ############################### +sub printHash { + my $hashref = $_[0]; + for my $element ( keys %{$hashref} ) { + print $element. "=" . $hashref->{$element} . "
\n"; + } +} + + sub getStdIn { #write std in into an array and return that # if semicola are somewhere, interprete diff --git a/tools/jtageditor.pl b/tools/jtageditor.pl index 9547497..aa52e46 100755 --- a/tools/jtageditor.pl +++ b/tools/jtageditor.pl @@ -17,6 +17,7 @@ print "Content-type: text/html\n\n"; # build ancestry without ancestry tree outside # find a solution for fileLevel <=6 +# our to ENV # DONE @@ -540,12 +541,7 @@ sub by_name { return $a_name cmp $b_name; } -sub printHash { - my $hashref = $_[0]; - for my $element ( keys %{$hashref} ) { - print $element. "=" . $hashref->{$element} . "
\n"; - } -} + sub read_input { my $buffer; @@ -603,13 +599,13 @@ sub printJavaScripts { function changeAncestor(newAncestor){ var file_ = encodeURIComponent(selectedConfigFile()); var newAncestor_ = encodeURIComponent(newAncestor); - getdata('$me?action=changeAncestor&configFile='+file_+'&newAncestor='+newAncestor_,false); + getdata('xmlOperation.pl?action=changeAncestor&configFile='+file_+'&newAncestor='+newAncestor_,false); reloadSetTree(); } function deleteFile(){ var file_ = encodeURIComponent(selectedConfigFile()); - getdata('$me?action=deleteFile&configFile='+file_,false); + getdata('xmlOperation.pl?action=deleteFile&configFile='+file_,false); loadFile(); } @@ -685,7 +681,7 @@ function createFile(){ debugOutput("NewFileName: "+newFileName()); var configFile_ = encodeURIComponent(newFileName()); var specFile_ = encodeURIComponent(selectedSpecFile()); - getdata("$me?action=createFile&configFile="+configFile_+"&specFile="+specFile_,"debug",false); + getdata("xmlOperation.pl?action=createFile&configFile="+configFile_+"&specFile="+specFile_,"debug",false); getdata('$me?print=fileSelection&configFile='+configFile_,'fileSelection',false); loadFile(); @@ -697,33 +693,28 @@ getdata('$me?print=fileSelection&configFile='+file_,'fileSelection',false); } function saveSettings(register,field,value){ -//getdata("$me?debuginput=tralla","debug"); var file_ = encodeURIComponent(selectedConfigFile()); var register_ = encodeURIComponent(register); var field_ = encodeURIComponent(field); var value_ = encodeURIComponent(value); -getdata("$me?action=save&configFile="+file_+"®ister="+register_+"&field="+field_+"&value="+value_,"debug",false); -//getdata("$me?print=settree","blauerBereich",true); +getdata("xmlOperation.pl?action=save&configFile="+file_+"®ister="+register_+"&field="+field_+"&value="+value_,"debug",false); reloadSetTree(); } function deleteSettings(register,field){ -//getdata("$me?debuginput=tralla","debug"); var file_ = encodeURIComponent(selectedConfigFile()); var register_ = encodeURIComponent(register); var field_ = encodeURIComponent(field); -getdata("$me?action=delete&configFile="+file_+"®ister="+register_+"&field="+field_,"debug",false); -//getdata("$me?print=settree","blauerBereich",true); +getdata("xmlOperation.pl?action=delete&configFile="+file_+"®ister="+register_+"&field="+field_,"debug",false); reloadSetTree(); } function copyDefaultRegister(register){ var register_ = encodeURIComponent(register); var file_ =encodeURIComponent(selectedConfigFile()); -getdata("$me?action=copyDefaultRegister®ister="+register_+'&configFile='+file_,"debug",false); -//getdata("$me?print=settree","blauerBereich",true); +getdata("xmlOperation.pl?action=copyDefaultRegister®ister="+register_+'&configFile='+file_,"debug",false); reloadSetTree(); } diff --git a/tools/testgui.pl b/tools/testgui.pl index 9f027ff..8441799 100755 --- a/tools/testgui.pl +++ b/tools/testgui.pl @@ -26,12 +26,16 @@ print start_html( ); print h2("testgui"); -print "

still more to come

"; -print escapeHTML("hallo<<<>>>&&&!!"),br; -print escapeHTML($here); -chdir("./preview") or die "could not change directory!"; -system("./run.pl -t 0.1 -id ccc1ccc1"); -chdir($here); +print "
"; +print ""; +print ""; +print ""; +print "
IVDREF1AIVDREF1B
"; + + +print "
"; + +print end_html; diff --git a/tools/xmlOperation.pl b/tools/xmlOperation.pl new file mode 100755 index 0000000..d585cae --- /dev/null +++ b/tools/xmlOperation.pl @@ -0,0 +1,118 @@ +#!/usr/bin/perl -w +#print "Content-type: text/html\n\n"; + + +my $me = "xmlOperation.pl"; + +use strict; +use warnings; +use XML::LibXML; +use POSIX; +use CGI ':standard'; + +use CGI::Carp qw(fatalsToBrowser); +# use HTML::Entities; + +require Common; +require xmlOperations; + +our $confDir = '../config'; +our $specDir = '../specs'; + + +my $q = CGI->new; + +print header; +print start_html( +-title=>'xmlOperation', +-style=>{'src'=>'../layout/styles.css'} +); + +print h2("debug output"); + + +unless ($q->param()){ + print "usage:",br; + print escapeHTML("http://[...]/tools/xmlOperation.pl?action=[action]&[parameter]&[parameter]& ..."),br; + print br,br; + print "possible actions: save, delete, copyDefaultRegister, createFile, deleteFile, changeAncestor",br,br; + print "parameter summary:",br; + print "save a value into a specific field:",br; + print escapeHTML("action=save&configFile=[configFile]®ister=[register]&field=[field]&value=[value]"),br,br; + print "delete a specific field:",br; + print escapeHTML("action=delete&configFile=[configFile]®ister=[register]&field=[field]"),br,br; + print "delete a whole register:",br; + print escapeHTML("action=delete&configFile=[configFile]®ister=[register]"),br,br; + print "copy a register including default values from the specification to the config file:",br; + print escapeHTML("action=copyDefaultRegister&configFile=[configFile]®ister=[register]"),br,br; + print "create a new config file based on the given specification file",br; + print escapeHTML("action=createFile&configFile=[configFile]&specFile=[specFile]"),br,br; + print "delete a config file",br; + print escapeHTML("action=deleteFile&configFile=[configFile]"),br,br; + print "change the ancestor (include directive) of config file",br; + print escapeHTML("action=changeAncestor&configFile=[configFile]&newAncestor=[newAncestor]"),br,br; + +} + +if ( defined $q->param('action') ) { + + if ( $q->param('action') eq 'save' ) { + parseConfigFile( $q->param('configFile') ); + save( $q->param('register'), $q->param('field'), $q->param('value') ); + writeConfigFile(); + report_and_quit(); + } + if ( $q->param('action') eq 'delete' ) { + parseConfigFile( $q->param('configFile') ); + del( $q->param('register'), $q->param('field') ); + writeConfigFile(); + report_and_quit(); + } + if ( $q->param('action') eq 'copyDefaultRegister' ) { + parseConfigAndSpec( $q->param('configFile') ); + del( $q->param('register'), "" ); # delete existing register from setfile + copyDefaultRegister( $q->param('register') ); + writeConfigFile(); + report_and_quit(); + } + if ( $q->param('action') eq 'createFile' ) { + createConfigFile( $q->param('configFile'), $q->param('specFile') ); + writeConfigFile(); + report_and_quit(); + } + + if ( $q->param('action') eq 'deleteFile' ) { + deleteFile( $q->param('configFile') ); + report_and_quit(); + } + + if ( $q->param('action') eq 'changeAncestor' ) { + parseConfigFile( $q->param('configFile') ); + changeAncestor( $q->param('newAncestor') ); + writeConfigFile(); + report_and_quit(); + } + +} + + + + +print end_html; + +sub report_and_quit { + print br,br; + print "action ".$q->param('action')." executed with following parameters:",br; + my @params = $q->param(); + print ""; + for (@params) { + print ""; + + } + print "
"; + print escapeHTML($_); + print "="; + print escapeHTML($q->param($_)); + print "
"; + exit; +}