Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use strict;
- use warnings;
- use XML::Twig;
- use File::Find;
- use Archive::Zip qw( :ERROR_CODES );
- my @files;
- my @zfiles;
- my @dirs;
- my @files_dir;
- sub extract_zip {
- foreach my $zf(@zfiles) {
- my $zip = Archive::Zip->new();
- print "Extracting files from ".$zf."\n";
- $zip->extractTree('',substr($zf,0,-4).'/') if ($zip->read($zf)) == AZ_OK;
- }
- }
- sub modify_xml {
- foreach my $file(@files) {
- my $t = XML::Twig->new(pretty_print => 'indented');
- print "Working on ".$file."\n";
- $t->parsefile($file);
- my $root = $t->root;
- my $widget = $root->first_child('widget');
- # Removing protocolVersion from asset tag
- my $protocolversion = $root->del_att('protocolVersion');
- # Changing the value of service
- my $service = $widget->first_child('service');
- $service->set_text('S-csWDDAKNaV-') if defined $service;
- # Changing deployed
- my $deployed = $widget->first_child('deployed');
- $deployed->set_text('true') if defined $deployed;
- # Removing ob element
- my $ob = $widget->first_child('ob');
- $ob->delete if defined $ob;
- # Changing appLanguage element
- my $appLanguage = $widget->first_child('appLanguage');
- $appLanguage->cut_children if defined $appLanguage;
- $appLanguage->set_text('es');
- # Adding testStatus
- my $keywords = $widget->first_child('keywords');
- $keywords->insert_new_elt(after=>'testStatus','live') unless $widget->has_child('testStatus');
- # Adding testStatus
- my $testStatus = $widget->first_child('testStatus');
- $testStatus->insert_new_elt(after=>'priority','p1') unless $widget->has_child('priority');
- # Removing proposedCategory element
- my $proposedCategory = $widget->first_child('proposedCategory');
- $proposedCategory->delete if defined $proposedCategory;
- # Adding f4 as true
- my $f3 = $widget->first_child('f3');
- $f3->insert_new_elt(after=>'f4','true') unless $widget->has_child('f4');
- # Removing premiumResource and modifying widget
- my $widget = $widget->first_child('widget');
- my $premiumResource = $widget->first_child('premiumResource');
- $premiumResource->delete if defined $premiumResource ;
- $widget->set_att(premiumResource => "APP00");
- #$root->print;
- open (my $fh_out, '>:utf8', $file) or die "unable to open '$file' for writing: $!";
- $t->print($fh_out);
- }
- }
- sub create_zip {
- # Getting files of each directory to create its ZIP file
- foreach my $f_dir(@dirs) {
- my $obj = Archive::Zip->new();
- $obj->addTree($f_dir,'',sub { -f });
- my $zip_filename = substr $f_dir,2,length($f_dir);
- if ($obj->writeToFileNamed($zip_filename.'.zip') != AZ_OK) { # write to disk
- print "Error in archive creation!\n";
- } else {
- print "Archive ".$zip_filename.".zip created successfully!\n";
- }
- }
- }
- # Extracting ZIP files
- find(sub { push (@zfiles, $_) if -f and /\.zip$/},'.');
- &extract_zip(@zfiles);
- # Getting the directory list in the current path
- find(sub{push (@dirs, $File::Find::name) if (-d $File::Find::name)},'.');
- shift(@dirs);
- # Modifying XMLs
- find(sub { push (@files, $File::Find::name) if -f and /\.xml$/},@dirs);
- &modify_xml(@files);
- &create_zip(@dirs);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement