<commit_before>#!/usr/bin/perl
package main;

our $VERSION = '0.03';

use strict;
use warnings;
use File::Compare;
use File::Copy;
use File::Basename;
use File::Path;
use Getopt::Long;
use Pod::Usage;

sub update() {
	my $sf = shift;
	my $df = shift;
	for my $f ($sf, $df) {
		if (! -e $sf) {
			print "File: $sf does not exist\n";
			return 1;
		} elsif (! -r $sf) {
			print "File: $sf can not be read\n";
			return 1;
		}
	}
	if ( (-e $sf) && (-r $sf) ) {
		if (-d $sf && ! -e $df) {
			print "updating directory: $df\n";
			mkdir($df) or die $!;
		} elsif (compare($sf, $df)) {
			print "updating file: $df\n";
			copy($sf, $df) or die $!;
		}
		return 0;
	}
}

# packup dotfiles to a tar.gz file
# @arguments:
# 	tarfile: archive file name
# 	flistref: ref to file list
sub pack() {
	require Archive::Tar;
	my $tarfile = shift;
	my $h = shift;
	print "start packing\n";
	my $tar = Archive::Tar->new;
	for (@{$h}) {
		print "adding=> [$_]\n";
	}
	$tar->add_files(@{$h});
	print "write to file => [$tarfile]\n";
	$tar->write($tarfile, Archive::Tar->COMPRESS_GZIP);
}

sub deploy() {
	my $sf = shift;
	my $df = shift;
	my $fname = basename($df);
	my $dname = dirname($df);
	if (! -d $dname) {
		mkpath($dname);
	}
	if ( (-e $sf) && (-r $sf) ) {
		if (compare($sf, $df)) {
			print "deploy file: $df\n";
			copy($sf, $df) or die $!;
		}
	}
}

BEGIN {
	# signal handler
	$SIG{TERM} = $SIG{INT} = sub {
		my $sig = shift;
		print "SIGNAL: $sig\n";
	};
	my @flist = (
		"bash_profile",
		"bashrc",
		"emacs",
		"emacs.d/init.el",
		"gitconfig",
		"gitignore",
		"pythonrc",
		"shell/*",
		"shell/profile.d/*",
		"shrc",
		"vimrc",
		"vim/plugin/OxnzToolkit.vim",
		"vim/plugin/DoxygenToolkit.vim",
		"vim/doc/OxnzToolkit.txt",
		"zshrc",
	);
	my $help;
	my $pfile;
	my $update;
	my $deploy;
	GetOptions(
		"help|h!"	=> \$help,
		"update|u!" => \$update,
		"pack|p=s"	=> \$pfile,
		"deploy|d!" => \$deploy,
	) or pod2usage(2);

	if (defined($help)) {
		pod2usage(0);
	} elsif (defined($pfile)) {
		&pack($pfile, \@flist);
	} elsif (defined($update)) {
		# prefix len
		my $len = length(glob("~/") . ".");
		for my $p (@flist) {
			for my $f (glob("~/.$p")) {
				&update($f, substr($f, $len));
			}
		}
	} elsif (defined($deploy)) {
		for my $f (@flist) {
			&deploy($f, glob("~/.$f"));
		}
	} else {
		pod2usage(0);
	}
}

END {
}
<commit_msg>fix deploy and update func<commit_after>#!/usr/bin/perl
package main;

our $VERSION = '0.03';

use strict;
use warnings;
use File::Compare;
use File::Copy;
use File::Basename;
use File::Path;
use Getopt::Long;
use Pod::Usage;

sub update() {
	my $sf = shift;
	my $df = shift;
	my $tdir = dirname($df);
	if (! -e $sf) {
		print "File: $sf does not exist\n";
		return 1;
	} elsif (! -r $sf) {
		print "File: $sf can not be read\n";
		return 1;
	}

	if (! -e $tdir) {
		print "Making directory: $tdir\n";
		mkdir($tdir);
	}

	if ( -d $sf) {
		if (! -e $df) {
			print "updating directory: $df\n";
			mkdir($df) or die $!;
		}
	} elsif (compare($sf, $df)) {
		print "updating file: $df\n";
		copy($sf, $df) or die $!;
	}
	return 0;
}

# packup dotfiles to a tar.gz file
# @arguments:
# 	tarfile: archive file name
# 	flistref: ref to file list
sub pack() {
	require Archive::Tar;
	my $tarfile = shift;
	my $h = shift;
	print "start packing\n";
	my $tar = Archive::Tar->new;
	for (@{$h}) {
		print "adding=> [$_]\n";
	}
	$tar->add_files(@{$h});
	print "write to file => [$tarfile]\n";
	$tar->write($tarfile, Archive::Tar->COMPRESS_GZIP);
}

sub deploy() {
	my $sf = shift;
	my $df = shift;
	my $fname = basename($df);
	my $dname = dirname($df);
	if (! -d $dname) {
		mkpath($dname);
	}
	if ( (-e $sf) && (-r $sf) ) {
		if (-d $sf) {
			if (! -e $df) {
				print "deploy directory: $df\n";
				mkdir($df) or die $!;
			}
		} elsif (compare($sf, $df)) {
			print "deploy file: $df\n";
			copy($sf, $df) or die $!;
		}
	}
}

BEGIN {
	# signal handler
	$SIG{TERM} = $SIG{INT} = sub {
		my $sig = shift;
		print "SIGNAL: $sig\n";
	};
	my @flist = (
		"bash_profile",
		"bashrc",
		"emacs",
		"emacs.d/init.el",
		"gitconfig",
		"gitignore",
		"pythonrc",
		"shell/*",
		"shell/profile.d/*",
		"shrc",
		"vimrc",
		"vim/plugin/OxnzToolkit.vim",
		"vim/plugin/DoxygenToolkit.vim",
		"vim/doc/OxnzToolkit.txt",
		"zshrc",
	);
	my $help;
	my $pfile;
	my $update;
	my $deploy;
	GetOptions(
		"help|h!"	=> \$help,
		"update|u!" => \$update,
		"pack|p=s"	=> \$pfile,
		"deploy|d!" => \$deploy,
	) or pod2usage(2);

	if (defined($help)) {
		pod2usage(0);
	} elsif (defined($pfile)) {
		&pack($pfile, \@flist);
	} elsif (defined($update)) {
		# prefix len
		my $len = length(glob("~/") . ".");
		for my $p (@flist) {
			for my $f (glob("~/.$p")) {
				&update($f, substr($f, $len));
			}
		}
	} elsif (defined($deploy)) {
		my $len = length(glob("~/") . ".");
		for my $p (@flist) {
			for my $f (glob($p)) {
				&deploy($f, glob("~/.$f"));
			}
		}
	} else {
		pod2usage(0);
	}
}

END {
}

{'fraction_non_alphanumeric': 0.23233557320301365, 'fraction_numerical': 0.004886988393402566, 'mean_word_length': 3.0461285008237233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6655419', 'n_tokens_mistral': 2413, 'n_tokens_neox': 2190, 'n_words': 528}