Linux-DVB-DVBT-Apps-QuartzPVR

 view release on metacpan or  search on metacpan

lib/Linux/DVB/DVBT/Apps/QuartzPVR/Crontab.pm  view on Meta::CPAN

		$lines .= "== Record Files ==\n" ;
		$lines .= "\n" ;

		foreach my $file (sort keys %rec_files)	
		{
			$lines .= "+---[ $opts_href->{'run_dir'}/$file ]------------\n" ;
			$lines .= "|\n" ;
			foreach my $line (@{$rec_files{$file}})
			{
				$lines .= "| $line\n" ;
			}
			$lines .= "+-------------------------------------------------------------------------------------\n\n" ;
		}	
	} 
	
	## Any IPLAY record files
	if (keys %iplay_files)
	{
		$lines .= "\n" ;
		$lines .= "== IPLAY Record Files ==\n" ;
		$lines .= "\n" ;

		foreach my $file (sort keys %iplay_files)	
		{
			$lines .= "+---[ $opts_href->{'run_dir'}/$file ]------------\n" ;
			$lines .= "|\n" ;
			foreach my $line (@{$iplay_files{$file}})
			{
				$lines .= "| $line\n" ;
			}
			$lines .= "+-------------------------------------------------------------------------------------\n\n" ;
		}	
	} 
	
	return $lines ;
}

#---------------------------------------------------------------------
sub display_blocks
{
	my @record_blocks = get_blocks($opts_href->{'crontag'}) ;
	
	print "\n\nBlocks:\n" ;
	foreach my $block (@record_blocks)
	{
		print "\n------------\n", $block->dump ;
	}

	@record_blocks = get_blocks($opts_href->{'crontag_iplay'}) ;
	
	print "\n\nIPLAY Blocks:\n" ;
	foreach my $block (@record_blocks)
	{
		print "\n------------\n", $block->dump ;
	}
}


#---------------------------------------------------------------------
# Update crontab to match database 
sub update
{
	my ($recording_aref) = @_ ;

	## get existing blocks
	my @record_blocks = get_blocks($opts_href->{'crontag'}) ;

	## Remove existing blocks
	$ct->remove(@record_blocks) ;

	## Create new blocks
	create_blocks($recording_aref) ;

}

#---------------------------------------------------------------------
# Update crontab to match database 
sub update_iplay
{
	my ($recording_aref) = @_ ;

	## get existing blocks
	my @record_blocks = get_blocks($opts_href->{'crontag_iplay'}) ;

	## Remove existing blocks
	$ct->remove(@record_blocks) ;

	## Create new blocks
	create_iplay_blocks($recording_aref) ;

}

#---------------------------------------------------------------------
# Write crontab 
sub commit
{
#print "commit()\n" ;
#print " + ensure $opts_href->{run_dir} is available\n" ;

    ## ensure path is available
    if (! -d "$opts_href->{run_dir}")
    {
    	mkpath("$opts_href->{run_dir}") or die "Error: Unable to create run directory $opts_href->{run_dir} : $!" ;
    }
    
#print " + clear files\n" ;
      
    ## clear record file list directory
    foreach my $f (glob("$opts_href->{run_dir}/*$opts_href->{run_ext}"))
    {
    	if (-f $f)
    	{
    		unlink $f ;
    	}
    }

#print " + create files\n" ;
    
    ## Create new files
	if (keys %rec_files)
	{
		foreach my $file (sort keys %rec_files)	
		{
			my $path = "$opts_href->{run_dir}/$file" ;
#print " + + $path\n" ;

			open my $fh, ">$path" or die "Error: Unable to create run file $path : $!" ;
			foreach my $line (@{$rec_files{$file}})
			{
				print $fh "$line\n" ;
			}
			close $fh ;
		}	
	} 

    ## Create new files
	if (keys %iplay_files)
	{



( run in 2.959 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )