From 04c78b4120220b8ecd39e97f6396f6b3b8aebd54 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 3 Apr 2012 23:34:45 +0200 Subject: [PATCH] Update upload to google process --- .../net/osmand/data/index/IndexUploader.java | 85 +++++++++++++++---- build-scripts/gg/example.lst | 9 ++ build-scripts/gg/filemask.lst | 9 -- 3 files changed, 77 insertions(+), 26 deletions(-) create mode 100644 build-scripts/gg/example.lst diff --git a/DataExtractionOSM/src/net/osmand/data/index/IndexUploader.java b/DataExtractionOSM/src/net/osmand/data/index/IndexUploader.java index 99a113398d..c7f3f6bc2c 100644 --- a/DataExtractionOSM/src/net/osmand/data/index/IndexUploader.java +++ b/DataExtractionOSM/src/net/osmand/data/index/IndexUploader.java @@ -14,8 +14,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.Enumeration; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipException; @@ -40,8 +42,10 @@ import com.jcraft.jsch.Session; * This helper will find obf and zip files, create description for them, and zip them, or update the description. * This helper also can upload files through ssh,ftp or to googlecode. * - * IndexUploader dir targetDir [--ff=file] [-ssh|-ftp|-google] [--password=|--user=|--url=|--path=|--gpassword=|--privKey=|--knownHosts=] + * IndexUploader dir targetDir [--ff=file] [--fp=ptns] [--dp=ptns] [-ssh|-ftp|-google] [--password=|--user=|--url=|--path=|--gpassword=|--privKey=|--knownHosts=] * --ff file with names of files to be uploaded from the dir, supporting regexp + * --fp comma separated names of files to be uploaded from the dir, supporting regexp + * --dp comma separated names of files to be delete on remote system, supporting regexp * One of: * -ssh to upload to ssh site * -fpt to upload to ftp site @@ -97,6 +101,7 @@ public class IndexUploader { private File targetDirectory; private UploadCredentials uploadCredentials = new DummyCredentials(); private FileFilter fileFilter = new FileFilter(); + private FileFilter deleteFileFilter = null; public IndexUploader(String path, String targetPath) throws IndexUploadException { directory = new File(path); @@ -134,13 +139,32 @@ public class IndexUploader { } private int parseFilter(String[] args, int start) throws IndexUploadException { + FileFilter fileFilter = null; if (args[start].startsWith("--ff=")) { try { - fileFilter = new FilePatternFileFilter(args[start].substring("--ff=".length())); + if(fileFilter == null) { + fileFilter = new FileFilter(); + } + fileFilter.parseFile(args[start].substring("--ff=".length())); } catch (IOException e) { throw new IndexUploadException(e.getMessage()); } - return start+1; + start++; + } + if (args[start].startsWith("--fp=")) { + if(fileFilter == null) { + fileFilter = new FileFilter(); + } + fileFilter.parseCSV(args[start].substring("--fp=".length())); + start++; + } + if (args[start].startsWith("--dp=")) { + deleteFileFilter = new FileFilter(); + deleteFileFilter.parseCSV(args[start].substring("--dp=".length())); + start++; + } + if(fileFilter != null) { + this.fileFilter = fileFilter; } return start; } @@ -166,17 +190,19 @@ public class IndexUploader { protected static class FileFilter { - protected boolean fileCanBeUploaded(File f) { - return f.isFile() && !f.getName().endsWith(IndexBatchCreator.GEN_LOG_EXT); + private List matchers = null; + + public void parseCSV(String patterns){ + String[] s = patterns.split(","); + if(matchers == null) { + matchers = new ArrayList(); + } + for(String p : s) { + matchers.add(Pattern.compile(p.trim())); + } } - } - - protected static class FilePatternFileFilter extends FileFilter { - - private List matchers = new ArrayList(); - - public FilePatternFileFilter(String file) throws IOException { + public void parseFile(String file) throws IOException{ File f = new File(file); if (f.exists()) { readPatterns(f); @@ -187,6 +213,9 @@ public class IndexUploader { BufferedReader reader = new BufferedReader(new FileReader(f)); try { String line; + if(matchers == null) { + matchers = new ArrayList(); + } while ((line = reader.readLine()) != null) { matchers.add(Pattern.compile(line)); } @@ -195,18 +224,24 @@ public class IndexUploader { } } - @Override - protected boolean fileCanBeUploaded(File f) { - if (!super.fileCanBeUploaded(f)) { - return false; + public boolean patternMatches(String name){ + if(matchers == null) { + return true; } for (Pattern p : matchers) { - if (p.matcher(f.getName()).matches()) { + if (p.matcher(name).matches()) { return true; } } return false; } + + protected boolean fileCanBeUploaded(File f) { + if (!f.isFile() && !f.getName().endsWith(IndexBatchCreator.GEN_LOG_EXT)) { + return false; + } + return patternMatches(f.getName()); + } } public void run() throws IndexUploadException { @@ -241,6 +276,22 @@ public class IndexUploader { log.error(f.getName() + ": " + e.getMessage(), e); } } + if(deleteFileFilter != null) { + if(uploadCredentials instanceof UploadToGoogleCodeCredentials) { + Map files = DownloaderIndexFromGoogleCode.getIndexFiles(new LinkedHashMap()); + for (String f : files.keySet()) { + System.out.println("File on googlecode " + f + " " + files.get(f)); + if (deleteFileFilter.patternMatches(f)) { + log.info("About to delete " + f); + } + } + + //DownloaderIndexFromGoogleCode.deleteFileFromGoogleDownloads(f.getName(), ((UploadToGoogleCodeCredentials)uploadCredentials).ggtokens); + } else { + log.error("Delete file filter is not supported with this credentions (method) " + uploadCredentials); + } + } + } finally { uploadCredentials.disconnect(); } diff --git a/build-scripts/gg/example.lst b/build-scripts/gg/example.lst new file mode 100644 index 0000000000..c4d43823cf --- /dev/null +++ b/build-scripts/gg/example.lst @@ -0,0 +1,9 @@ +Germany_bayern.* +Germany_nordrhein.* +Germany.*srtm.* +German_baden.* +France_.* +Gb_england_.* +Netherlands_.* +Spain_.* +Brazil_.* diff --git a/build-scripts/gg/filemask.lst b/build-scripts/gg/filemask.lst index c6995d852b..e69de29bb2 100644 --- a/build-scripts/gg/filemask.lst +++ b/build-scripts/gg/filemask.lst @@ -1,9 +0,0 @@ -Germany_bayern.* -Germany_nordrhein.* -Germany.*srtm.* -German_baden.* -France_.* -Gb_england_.* -Netherlands_.* -Spain_.* -Brazil_.* \ No newline at end of file