Du bist hier: Snippet-Verzeichnis » Perl (198)
Sprache:

apache_mime_merge

Sprache: English
Programmiersprache: Perl
Veröffentlicht von: agfoust [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 875


Beschreibung

So you have a new fresh install of Apache? You are upgrading, and you want to use the latest MIME definitions in the new mime.types file, but you want to incorporate the customizations you have made in your old mime.types file? This utility solves just that problem.

Code

1 #!/usr/local/bin/perl 2 # 3 # Name: Create New Combined mime.types File 4 # File: apache_mime_merge 5 # 6 # Version 0.9, Adam Foust (agfoust@yahoo.com) 7 # 8 # DESCRIPTION 9 # So you have a new fresh install of Apache? You are 10 # upgrading, and you want to use the latest MIME 11 # definitions in the new mime.types file, but you 12 # want to incorporate the customizations you have 13 # made in your old mime.types file? This utility 14 # solves just that problem. 15 # 16 # USAGE 17 # apache_mime_merge old_file new_file > new_file2 18 # 19 20 use strict; 21 22 my(%MT,%tmp,$old_file,$new_file,$fname,$type,@ext); 23 24 unless (-r $ARGV[0] && -r $ARGV[1]) { 25 print "usage: apache_mime_merge ", 26 "old_file new_file > new_file2\n"; 27 exit; 28 } 29 ($old_file,$new_file) = ($ARGV[0],$ARGV[1]); 30 31 for $fname ($old_file,$new_file) { 32 open(F,$fname) || die; 33 while (<F>) { 34 ($type,@ext) = split; 35 next unless /^\s*[^\s]+\/[^\s]+/; 36 next unless @ext; 37 $MT{$fname}{$type} = [@ext]; 38 } 39 close(F); 40 } 41 42 # The idea is to produce a copy of the new file with 43 # any carryover MIME extensions tacked on from the old 44 # file that may have been left out. 45 46 open(F,$new_file) || die; 47 while (<F>) { print $_ }; 48 close(F); 49 50 # You can manually edit the new mime.types file and 51 # resolve any conflicts (commented out by default) or 52 # simply ignore these. 53 54 print "\n# conflicts between old and new definitions\n"; 55 for $type (keys %{$MT{$new_file}}) { 56 next unless $MT{$old_file}{$type}; 57 undef %tmp; 58 map { $tmp{$_}++ } @{$MT{$old_file}{$type}}; 59 map { delete $tmp{$_} } @{$MT{$new_file}{$type}}; 60 printf "#%-31s %s\n",$type,join(" ",keys %tmp) 61 if keys %tmp; 62 } 63 64 print "\n# definitions carried over from previous ", 65 "mime.types file\n"; 66 map { delete $MT{$old_file}{$_} } keys %{$MT{$new_file}}; 67 68 map { printf "%-31s %s\n",$_,join(" ", 69 @{$MT{$old_file}{$_}}) } keys %{$MT{$old_file}}; 70 71 __END__ 72

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS