This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Implement push --list-file-types

  • Loading branch information...
seanf committed Apr 14, 2016
1 parent 101f74d commit 1be968219de1abbca1dfea584c3a7b0ba13030aa
@@ -132,10 +132,11 @@ SourceConfigPrompt promptUser() throws Exception {
console.blankLine();
console.printfln(Question, get("project.file.type.question"));
// this answer is not persisted in zanata.xml so user will still need to type it when they do the actual push
// FIXME invoke listFileTypes
console.printfln(Hint, PushOptionsImpl.fileTypeHelp);
console.printf(Question, get("file.type.prompt"));
String answer = console.expectAnyNotBlankAnswer();
// TODO this answer is not persisted in zanata.xml so user will still need to type it when they do the actual push
((PushOptionsImpl) pushOptions).setFileTypes(answer);
}
@@ -111,6 +111,12 @@ public AbstractPushStrategy getStrategy(PushOptions pushOptions) {
return strat;
}
private void checkOptions() {
if (getOpts().getListFileTypes()) {
throw new RuntimeException("\"List file types\" is only supported for project type FILE");
}
}
public static void logOptions(Logger logger, PushOptions opts) {
if (!logger.isInfoEnabled()) {
return;
@@ -208,6 +214,7 @@ private boolean pushTrans() {
@Override
public void run() throws Exception {
checkOptions();
logOptions(log, getOpts());
pushCurrentModule();
@@ -50,6 +50,8 @@
// raw file push
public int getChunkSize();
boolean getListFileTypes();
public ImmutableList<String> getFileTypes();
public String getValidate();
@@ -49,6 +49,7 @@
private ImmutableList<String> includes = ImmutableList.of();
private ImmutableList<String> excludes = ImmutableList.of();
private ImmutableList<String> fileTypes = ImmutableList.of();
private boolean listFileTypes = false;
private boolean defaultExcludes = DEF_EXCLUDES;
private String mergeType = DEF_MERGE_TYPE;
private boolean caseSensitive = DEF_CASE_SENSITIVE;
@@ -189,31 +190,35 @@ void setChunkSize(int chunkSize) {
return fileTypes;
}
public static final String fileTypeHelp = "File types to locate and transmit to the server. \n" +
"Default file extension will be used unless it is being specified. \n" +
"Pattern: TYPE[extension;extension],TYPE[extension] \n" +
"Supported types: \n" +
"\t XML_DOCUMENT_TYPE_DEFINITION[xml] \n" +
"\t PLAIN_TEXT[txt] \n" +
"\t IDML[idml] \n" +
"\t HTML[html;htm] \n" +
"\t OPEN_DOCUMENT_TEXT[odt] \n" +
"\t OPEN_DOCUMENT_PRESENTATION[odp] \n" +
"\t OPEN_DOCUMENT_GRAPHICS[odg] \n" +
"\t OPEN_DOCUMENT_SPREADSHEET[ods] \n" +
"\t SUBTITLE[srt;sbt;sub;vtt] \n" +
"\t GETTEXT[pot] \n" +
"\t PROPERTIES[properties] \n" +
"\t PROPERTIES_UTF8[properties] \n" +
"\t XLIFF[xml] \n" +
"Usage --file-types \"XML_DOCUMENT_TYPE_DEFINITION,PLAIN_TEXT[md;txt]\"";
public static final String fileTypeHelp = "File types to locate and transmit to the server.\n" +
"Pattern: TYPE[extension;extension],TYPE[extension] \n" +
"The default file extension(s) for each TYPE will be used unless\n" +
"'extension' is specified in square brackets. If overriding extensions,\n" +
"please note that most shells require quotes around square brackets unless\n" +
"they are escaped.\n" +
"The special type \"DEFAULTS\" can be used to inherit the default file types\n" +
"when setting this parameter. If this parameter is set without using\n" +
"\"DEFAULTS\", only the file types specified here will be used.\n" +
"Use --list-file-types to see supported types and their default extensions. \n" +
"Usage: --file-types \"DEFAULTS,PROPERTIES,PLAIN_TEXT[md;txt]\"";
@Option(name = "--file-types", metaVar = "TYPES",
usage = fileTypeHelp)
public void setFileTypes(String fileTypes) {
this.fileTypes = ImmutableList.copyOf(StringUtil.split(fileTypes, ","));
}
@Override
public boolean getListFileTypes() {
return this.listFileTypes;
}
@Option(name = "--list-file-types",
usage = "List file types supported by the configured server")
public void setListFileTypes(boolean listFileTypes) {
this.listFileTypes = listFileTypes;
}
@Override
public boolean getCaseSensitive() {
return caseSensitive;
@@ -30,8 +30,10 @@
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -46,6 +48,7 @@
import javax.annotation.Nullable;
import com.google.common.base.Joiner;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
@@ -251,6 +254,22 @@ public void run() throws IOException {
consoleInteractor.printfln(DisplayMode.Warning,
"Using EXPERIMENTAL project type 'file'.");
List<DocumentType> serverAcceptedTypes = client.acceptedFileTypes();
if (getOpts().getListFileTypes()) {
consoleInteractor.printfln(DisplayMode.Information, "Listing supported file types [with extensions]:");
List<DocumentType> types = new ArrayList<>(serverAcceptedTypes);
Collections.sort(types);
for (DocumentType docType : types) {
List<String> sourceExtensions = new ArrayList<>(docType.getSourceExtensions());
Collections.sort(sourceExtensions);
String exts = Joiner.on(';').join(sourceExtensions);
consoleInteractor.printfln(DisplayMode.Information, " %s[%s]", docType.name(), exts);
}
log.info("Listed file types: no files were pushed");
return;
}
// only supporting single module for now
File sourceDir = getOpts().getSrcDir();
@@ -271,9 +290,6 @@ public void run() throws IOException {
RawPushStrategy strat = new RawPushStrategy();
strat.setPushOptions(getOpts());
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
List<DocumentType> serverAcceptedTypes = client.acceptedFileTypes();
Map<DocumentType, Set<String>> filteredDocTypes =
validateFileTypes(serverAcceptedTypes, getOpts().getFileTypes());
@@ -115,6 +115,8 @@
private String[] fileTypes =
"txt,dtd,odt,fodt,odp,fodp,ods,fods,odg,fodg,odf,odb".split(",");
private boolean listFileTypes = false;
/**
* Case sensitive for includes and excludes options.
*
@@ -195,6 +197,11 @@ public int getChunkSize() {
return ImmutableList.copyOf(fileTypes);
}
@Override
public boolean getListFileTypes() {
return false;
}
@Override
public String getCommandName() {
return "push";

0 comments on commit 1be9682

Please sign in to comment.