2 ###############################################################################
9 Attempts to invoke B<clean_csv> on the specified tracked file, placing the
10 output in [file].clean
12 If given no other arguments, the invocation will lool like
16 clean_csv --config scripts/clean.conf --fix --apply [--create-headers|--use-headers <hfile>] <file>
20 otherwise, the arguments will be passed through like so
24 clean_csv [other arguments...] <file>
28 You'll need to invoke B<mig-iconv> or B<mig-skip-iconv> prior to using commands
33 B<mig-clean> <file> [other arguments...]
37 ###############################################################################
42 HOME PGHOST PGPORT PGUSER PGDATABASE MIGSCHEMA
43 MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR
49 my $mig_bin = "$FindBin::Bin/";
50 use lib "$FindBin::Bin/";
53 pod2usage(-verbose => 2) if ! $ARGV[0] || $ARGV[0] eq '--help';
55 EMig::die_if_no_env_migschema();
56 EMig::die_if_mig_tracking_table_does_not_exist();
58 my $file = abs_path($ARGV[0]);
59 if ($file =~ /^$MIGBASEWORKDIR/) {
60 call_clean_csv(@ARGV);
62 print "File falls outside of MIGWORKDIR ($MIGWORKDIR): $file\n";
67 ###############################################################################
70 my $file = abs_path(shift);
73 my $tracked_file_id = EMig::check_for_tracked_file($file);
74 if ($tracked_file_id) {
75 my $data = EMig::status_this_file($file);
77 if (! $data->{'utf8_filename'}) {
78 die "mig-iconv or mig-skip-iconv needed for UTF8 version of file: $file\n";
81 my $utf8_file = $data->{'utf8_filename'};
82 if (! -e $utf8_file) {
83 die "missing file: $utf8_file\n";
86 print "cleaning tracked file: $file\n";
88 if (scalar(@args) == 0) {
97 if (! $data->{'has_headers'}) {
98 if ($data->{'headers_file'}) {
99 push @args, '--use-headers';
100 push @args, $data->{'headers_file'};
102 push @args, '--create-headers';
107 print join(' ',@args) . "\n";
108 system('clean_csv', @args, $utf8_file);
110 my $dbh = EMig::db_connect();
111 my $clean_file = $dbh->quote($utf8_file . '.clean');
112 if (! -e $utf8_file . '.clean') {
113 print "clean file does not exist: $clean_file\n";
114 $clean_file = $dbh->quote('');
118 UPDATE $MIGSCHEMA.tracked_file
119 SET clean_filename = $clean_file
120 WHERE base_filename = " . $dbh->quote($file) . "
122 ") || die "Error inserting into table $MIGSCHEMA.tracked_file: $!\n";
123 EMig::db_disconnect($dbh);
125 print "File not currently tracked: $file\n";