#!/usr/bin/perl -w # # Author: pkgs@c0t0d0s0.de # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GNU Emacs; see the file COPYING. If not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # Maps planner task states to org states %statemap = ( 'C' => 'DONE', 'X' => 'DONE', 'o' => 'TODO', '_' => 'TODO' ); traverse_directory( "." ); exit 0; sub orgtimestamp { my ($pdate) = @_; $x = "\@Unknow timestamp\@"; if ( $pdate =~ /(\d\d\d\d)\.(\d\d)\.(\d\d)/ ) { $x = `date -d '$2/$3/$1' '+%Y-%m-%d %a'`; chomp $x; } #if return $x; } #orgtimestamp sub cnv { my ($infile) = @_; printf "Process $infile next...\n"; my $basefile = $infile; $basefile =~ s/\.muse//; my $outfile = $basefile . ".org"; open( IN, "<$infile" ); open( OUT, ">$outfile" ); while ( ) { $line = $_; if ( $line =~ /^#([ABC])\s(.)\s(.*)$/) { $priority = $1; $state = $2; $text = $3; # Remove task id $text =~ s/{{Tasks:\d+}}//; # Extract deadline $deadline = ""; if ( $text =~ /{{Deadline:\s(\d\d\d\d\.\d\d\.\d\d)\s.*}}/ ) { $deadline = orgtimestamp $1; # Remove deadline $text =~ s/{{Deadline:.*}}//; } #if # Extract closing date $closing = ""; if ( $state eq 'X' || $state eq 'C' ) { # There should only be one timestamp like thingy # per task... if ( $text =~ /\[\[(\d\d\d\d\.\d\d\.\d\d)\]\]/ ) { $closing = orgtimestamp $1; $text =~ s/\[\[(\d\d\d\d\.\d\d\.\d\d)\]\]//; } #if } #if # Remove daily page links $text =~ s/\[\[(\d\d\d\d\.\d\d\.\d\d)\]\]//; # Remove self refs $text =~ s/\[\[$basefile\]\]//g; # Process links [[foo]] -> [[file:foo.org]] $text =~ s/\[\[([^:\\\/\[\]]*)\]\]/\[\[file:$1\.org\]\]/g; $text =~ s/\[\[([^:\\\/\[\]]*)\]\[(.*)\]\]/\[\[file:$1\.org\]\[$2\]\]/g; # Remove remaining () $text =~ s/\(\)//g; print OUT "** $statemap{$state} [#$priority] $text\n"; if ( $deadline ) { print OUT " DEADLINE: <$deadline>\n"; } #if if ( $closing ) { print OUT " CLOSED: [$closing]\n"; } #if } else { # Process links [[foo]] -> [[file:foo.org]] $line =~ s/\[\[([^:\\\/\[\]]*)\]\]/\[\[file:$1\.org\]\[$1\]\]/g; $line =~ s/\[\[([^:\\\/\[\]]*)\]\[(.*)\]\]/\[\[file:$1\.org\]\[$2\]\]/g; print OUT $line; } } #while } sub traverse_directory { my ($directory) = @_; local *DIR; my @files = (); printf "process $directory next...\n"; opendir( DIR, $directory ); @files = readdir( DIR ); closedir( DIR ); foreach my $file ( @files ) { my $path = "$directory/$file"; next if ( ($file eq '.') || ($file eq '..') || ($file =~ /.*\.org$/) ); if( -d $path ) { traverse_directory( $path ); } else { $path = $1 if ( $path =~ /^\.\/(.*)$/); cnv( $path ); } #if } #foreach } # traverse_directory