Release: Post-Build File Renamer

All new Coranto Addons, updates and patches to addons, will be released here...also, get support for addons within!

Moderators: Spunkmeyer, Dale Ray, SrNupsen, Bluetooth, Jackanape

Release: Post-Build File Renamer

Postby Psykosys » Wed Sep 28, 2005 6:13 pm

Here's a short, UI-free, poorly-coded (but functional!) addon I've been using to automatically rename RSS files created (using regular Coranto profiles with templates) after every build. This is necessary because Coranto 1.24 and under does not include the option to customize the extension of a templated output file. The variables that need to be set are the local path to the directory the file(s) you want renamed are in, the extensions to rename from and to, and finally the array @FRN_files needs to be set to the names (sans extension) of each of the files you want renamed after a build. Suggestions are welcome for improving the code, and it's opensource (so you can just do it yourself and repost) although it's silly to have to note that for an addon this small.

Code: Select all
#! CRADDON 1
#! NAME Post-Build file renamer
#! VERSION 0.1
#! DESCRIPTION Renames a file following each build
#! AUTHOR Psykosys
#! DOC 0

my $addon = new Addon('Post-Build File Renamer');
$addon->isPrivacyCompatible;

$addon->hook(BuildNews_Post,FRN_main);
sub FRN_main {   

## SET THESE: ##
my $FRN_filedir = '/home/user/www/folderwithxmlfile/';
my $FRN_from_extension = 'htm';
my $FRN_to_extension = 'xml';
my @FRN_files = ('rss20,rss091');
#############

   foreach my $FRN_file (@FRN_files) {
      if (-e ($FRN_filedir . $FRN_file . '.' . $FRN_from_extension)) {
         if (-e ($FRN_filedir . $FRN_file . '.' . $FRN_to_extension)) {
            unlink($FRN_filedir . $FRN_file . '.' . $FRN_to_extension);
         }
         rename(($FRN_filedir . $FRN_file . '.' . $FRN_from_extension), ($FRN_filedir . $FRN_file . '.' . $FRN_to_extension));
      }
   }


}

1;

__END__
Psykosys
 
Posts: 252
Joined: Tue Apr 15, 2003 10:37 pm
Location: Ithaca, NY

Postby leeerickson2050 » Thu Jan 19, 2006 9:53 pm

Code: Select all
#! CRADDON 1
#! NAME Post-Build file renamer
#! VERSION 0.1
#! DESCRIPTION Renames a file following each build
#! AUTHOR Psykosys
#! DOC 0

my $addon = new Addon('Post-Build File Renamer');
$addon->isPrivacyCompatible;

$addon->hook(BuildNews_Post,FRN_main);
sub FRN_main {   

## SET THESE: ##
my $FRN_filedir = '/var/www/html/xml/';
my $FRN_from_extension = 'html';
my $FRN_to_extension = 'xml';
my @FRN_files = ('rss20,rss091');
#############

   foreach my $FRN_file (@FRN_files) {
      if (-e ($FRN_filedir . $FRN_file . '.' . $FRN_from_extension)) {
         if (-e ($FRN_filedir . $FRN_file . '.' . $FRN_to_extension)) {
            unlink($FRN_filedir . $FRN_file . '.' . $FRN_to_extension);
         }
         rename(($FRN_filedir . $FRN_file . '.' . $FRN_from_extension), ($FRN_filedir . $FRN_file . '.' . $FRN_to_extension));
      }
   }


}

1;

__END__


Hmm Not working....ANy Ideas...
Lee Erickson
User avatar
leeerickson2050
 
Posts: 22
Joined: Wed Jan 11, 2006 7:55 pm
Location: Huntsville, AL

Postby Parahead » Fri Jan 20, 2006 3:19 pm

leeerickson2050 wrote:Hmm Not working....ANy Ideas...
Not working as in? No errormessage? No nothing? Maybe a stupid question but have you verified the paths? And verified them again? Like in, cut and paste the path to a shell where you do a "cd /var/www/html/xml/" to *really* make sure the path is correct. Or maybe even "ls /var/www/html/xml/rss20.html"?
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby leeerickson2050 » Fri Jan 20, 2006 8:16 pm

Not working as in Does seem to do anything.

The path is correct. I confirmed with TESTbin.
Lee Erickson
User avatar
leeerickson2050
 
Posts: 22
Joined: Wed Jan 11, 2006 7:55 pm
Location: Huntsville, AL

Postby Dale Ray » Sat Jan 21, 2006 2:14 am

## SET THESE: ##
my $FRN_filedir = '/var/www/html/xml/';
my $FRN_from_extension = 'html';
my $FRN_to_extension = 'xml';
my @FRN_files = ('rss20,rss091');
#############


Did you list the file or files that you want renamed in this line:

my @FRN_files = ('rss20,rss091');

example:

my @FRN_files = ('first_file,second_file');

you have to edit the script to provide:

the path (not URL) to the folder with the file, including a trailing slash
the current extension yopu want to change
the extension you want it changed to
a list of the file names without the extension

I suspect that you did not give it the list of file names since it isn't likely that your files are named the same as the defaults in the script.

I tested this on a local install and it worked fine.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Parahead » Sat Jan 21, 2006 7:25 am

Dale Ray wrote:I suspect that you did not give it the list of file names since it isn't likely that your files are named the same as the defaults in the script.
This was kind of my assumption too and the reason why I wanted Lee to excecute the command "ls /var/www/html/xml/rss20.html" from within a shell. He would then have gotten a "No such file or directory"-message if the file wasn't there... ;-)
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Dale Ray » Sat Jan 21, 2006 9:22 am

Psykosys,

I hope you don't mind, here is a version that adds a setting to each profile. I bumped the version number slightly. Install into your Coranto folder, enable it and then there is a setting on each profile's page for an extension. You must be using a template for this to work.

An empty setting is ignored and the default extension is used. This can be used to set the extension for each profile. You can use it to set any extension you want - xml, php, cgi, etc.
Code: Select all
#! CRADDON 1
#! NAME Post-Build File Renamer
#! VERSION 0.2
#! DESCRIPTION Renames a file following each build
#! AUTHOR Psykosys (with revisions by Dale Ray)
#! DOC 0

my $addon = new Addon('Post-Build File Renamer');
$addon->isPrivacyCompatible;

my $FRN_settings = <<'END_CODE';
push(@EditProfileSettings,
['heading: Post-Build File Renamer'],
['FRN_ext', 'New extension', "If you want the output file renamed with a different extension enter the new extension here.<br> Leave blank to use the default set on the main Coranto settings page.", $FRN_ext ]);
END_CODE

$addon->hook(BuildNews_Post,FRN_main);
sub FRN_main {
     foreach $i (sort keys %newsprofiles) {
          if ($newsprofiles{$i}->{'enabled'} && ($newsprofiles{$i}->{'type'} eq 'Standard') ) {
               if ($newsprofiles{$i}->{'FRN_ext'}) {
                    if ($newsprofiles{$i}->{'filepath'}) {
                         my $path = $newsprofiles{$i}->{'filepath'}."/";
                         } else {
                         $path = $CConfig{'htmlfile_path'}."/";
                    }
                    rename($path.$i.".".$CConfig{'ArcHtmlExt'}, $path.$i.".".$newsprofiles{$i}->{'FRN_ext'});
               }
          }
     }
}

$addon->hook('EditProfDefinition_2', \$FRN_settings);

1;

__END__


Please consider this a beta. Tested on a limited basis on a local test setup.

This loops through all of the profiles, so it may slow up build times with a large number of profiles. I couldn't figure out an alternate way to do it. Only tested with standard profiles (not Maginot).

I thought that with this addon you can use the same methods to create an RSS feed in Coranto 1.24 that you can with Coranto 1.31.2 as discussed in this thread.

Suggestions and comments welcome.

BTW - It took me over 4 hours to get this to work, even with the start by Psykosys. I guess I'll never set any records for speed coding :shock:
Last edited by Dale Ray on Sat Jan 21, 2006 9:41 am, edited 1 time in total.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Parahead » Sat Jan 21, 2006 9:34 am

Dale Ray wrote:Suggestions and comments welcome.
Nice work Dale, keep it up! :-)

Maybe one could consider changing the line:
Code: Select all
if ($newsprofiles{$i}->{'enabled'}) {
to the below, if only Standard profiles is the targeted area here?
Code: Select all
if ($newsprofiles{$i}->{'enabled'} && ($newsprofiles{$i}->{'type'} eq 'Standard') ) {
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Dale Ray » Sat Jan 21, 2006 9:43 am

Parahead wrote:Maybe one could consider changing the line:
Code: Select all
if ($newsprofiles{$i}->{'enabled'}) {
to the below, if only Standard profiles is the targeted area here?
Code: Select all
if ($newsprofiles{$i}->{'enabled'} && ($newsprofiles{$i}->{'type'} eq 'Standard') ) {


OK - I edited the code in the original post to reflect the change you suggested.

And thanks for the Parahead Seal of Approval!

Now - I am really going to go to bed - really.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Parahead » Sat Jan 21, 2006 5:22 pm

Dale Ray wrote:OK - I edited the code in the original post to reflect the change you suggested.
Hmm... Looking even deeper into the code, maybe you should place an if-statement around the code for the profile settings as well, so it only shows on Standard Profile pages? Something like:
Code: Select all
my $FRN_settings = <<'END_CODE';
if($newsprofiles{$i}->{'type'} eq 'Standard') {
  push(@EditProfileSettings,
  ['heading: Post-Build File Renamer'],
  ['FRN_ext', 'New extension', "If you want the output file renamed with a different extension enter the new extension here.<br> Leave blank to use the default set on the main Coranto settings page.", $FRN_ext ]);
}
END_CODE
And if you add that, there is actually no need for the same test I mentioned previously in in the FRN_main sub anymore...

Dale Ray wrote:And thanks for the Parahead Seal of Approval!
No need for me to approve, you are doing just fine. :-)
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Psykosys » Fri Jan 27, 2006 5:33 am

Dale Ray wrote:Psykosys,

I hope you don't mind, here is a version that adds a setting to each profile. I bumped the version number slightly. Install into your Coranto folder, enable it and then there is a setting on each profile's page for an extension. You must be using a template for this to work.

Thanks, Dale, your version's great! I was just about to change the stupid thing so I could use it in multiple directories, etc. Only I would've done it with much clunkier code and kept the awful method for settings that Lee understandably couldn't figure out...

Afterthought: I know including add-ons in the main distribution is always a very contentious issue, but doesn't it seem like this would be a good inclusion, either as Dale Ray's separate addon or in the core? Or was the next release going to have support for individual profile extension-setting anyway?
Psykosys
 
Posts: 252
Joined: Tue Apr 15, 2003 10:37 pm
Location: Ithaca, NY

Postby Dale Ray » Fri Jan 27, 2006 6:07 am

Psykosys wrote:Thanks, Dale, your version's great! I was just about to change the stupid thing so I could use it in multiple directories, etc. Only I would've done it with much clunkier code and kept the awful method for settings that Lee understandably couldn't figure out...


Glad you like it.

Psykosys wrote:Afterthought: I know including add-ons in the main distribution is always a very contentious issue, but doesn't it seem like this would be a good inclusion, either as Dale Ray's separate addon or in the core? Or was the next release going to have support for individual profile extension-setting anyway?


The new versions of Coranto address this.

I planned to do some more work on this, but I am very busy with other things right now so I am releasing a slightly changed version of this which includes the ability to change the filename and the extension as two separate setttings on the profile page. There is documentation available through the Coranto interface on the Addon page. I have only tested this on a local install, make sure you have a backup before installing any new addon.

Download Here.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Parahead » Fri Jan 27, 2006 9:50 pm

Dale Ray wrote:
Psykosys wrote:Afterthought: I know including add-ons in the main distribution is always a very contentious issue, but doesn't it seem like this would be a good inclusion, either as Dale Ray's separate addon or in the core? Or was the next release going to have support for individual profile extension-setting anyway?

The new versions of Coranto address this.
I just want to confirm what Dale Ray have said, the 1.31.x release of Coranto addresses this so that you can specify an extension for the template driven output from a profile on a per profile basis.
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Dale Ray » Wed Mar 22, 2006 6:22 am

The Post-Build File Renamer addon is now:

Post-Build File Renamer/Mover

Click on the name to go to the download page.

New in this version:

You can now optionally MOVE the file to different directory.
If the rename/move process goes wrong you will get an error message.

This only works with standard profiles and my testing was limited to a few builds on a local install of Coranto. I would advise creating a test profile. (testers welcome, reports of results welcome) As always - make a backup before using any new addon! It will allow you to set a different directory on a per profile basis for the file created when using a template with a profile.

There is no check that you have entered a valid path when you enter it on the profile settings page, but you will get an error message if the rename/move process doesn't go right.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Parahead » Sat Mar 25, 2006 11:37 am

Dale Ray wrote:There is no check that you have entered a valid path when you enter it on the profile settings page, but you will get an error message if the rename/move process doesn't go right.
Dale Ray, if you are interested I think that something like this would work to check the path when saving:
Code: Select all
if($in{'the_path_field_name'} && !(-d $in{'the_path_field_name'})) {
  AreYouSure(qq~The File Path you have specified (<strong>$in{'the_path_field_name'}</strong>) does not seem to exist, are you sure it is correct?~, $in{'the_path_field_name'})) unless $in{'really'};
}
PS. It is only three lines of code, the forum may linebreak it...
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Next

Return to Addon Release and Support

Who is online

Users browsing this forum: Google [Bot] and 0 guests

cron