Skip to content

Commit

Permalink
Simplify the Collate script using required arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
GraylinKim committed Apr 12, 2012
1 parent fb4a05e commit f5dd095
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bin/process.sh
Expand Up @@ -34,7 +34,7 @@ fi
set -e

# Organize the change files and ingest to storage
$BINDIR/run.sh collate --source $source --dest $work;
$BINDIR/run.sh collate $source $work;
$BINDIR/run.sh ingest --source $work --storage $storage --change-file $work/change.log

# Migrate all processed files to $dest for archival purposes
Expand Down
36 changes: 11 additions & 25 deletions src/main/java/gov/nysenate/openleg/scripts/Collate.java
@@ -1,48 +1,34 @@
package gov.nysenate.openleg.scripts;

import gov.nysenate.openleg.util.Config;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;

public class Collate {
private static Logger logger = Logger.getLogger(Collate.class);

public static void main(String[] args) {
CommandLine opts = null;
try {
Options options = new Options()
.addOption("s", "source", true, "Source data directory")
.addOption("d", "dest", true, "Destination data directory")
.addOption("h", "help", false, "Print this message");
opts = new PosixParser().parse(options, args);
if(opts.hasOption("-h")) {
new HelpFormatter().printHelp("posix", options );
System.exit(0);
}
} catch (ParseException e) {
logger.fatal("Error parsing arguments: ", e);
if (args.length < 2) {
System.out.println("USAGE: Collate source [... source] dest");
System.exit(0);
}

String source = opts.getOptionValue("source", Config.get("data"));
String dest = opts.getOptionValue("dest", Config.get("work", source));
File destDirectory = new File(args[args.length-1]).getAbsoluteFile();
Collection<File> sources = new ArrayList<File>();
for (int i=0; i < args.length-1; i++) {
sources.addAll(FileUtils.listFiles(new File(args[i]).getAbsoluteFile(), null, true));
}


File sourceDirectory = new File(source).getAbsoluteFile();
File destDirectory = new File(dest).getAbsoluteFile();
File bills = new File(destDirectory, "bills");
File agendas = new File(destDirectory, "agendas");
File calendars = new File(destDirectory, "calendars");
Expand All @@ -60,7 +46,7 @@ public static void main(String[] args) {
System.exit(0);
}

for (File file : FileUtils.listFiles(sourceDirectory, null, false)) {
for (File file : sources) {
logger.debug("Processing: "+file);

int inc = 1;
Expand Down

0 comments on commit f5dd095

Please sign in to comment.