Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #833 from ggalmazor/issue_824_relative_paths_in_CLI
Browse files Browse the repository at this point in the history
Issue 824 relative paths in cli
  • Loading branch information
ggalmazor authored Nov 20, 2019
2 parents 8f78fd7 + 7d84884 commit fd229a4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
23 changes: 17 additions & 6 deletions src/org/opendatakit/briefcase/operations/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,33 @@
import org.opendatakit.common.cli.Param;

public class Common {
static final Param<String> STORAGE_DIR = Param.arg("sd", "storage_directory", "Briefcase storage directory");
public static final Param<String> DEPRECATED_AGGREGATE_SERVER = Param.arg("url", "aggregate_url", "Aggregate server URL");
public static final Param<URL> SERVER_URL = Param.arg("U", "odk_url", "ODK Server URL", RequestBuilder::url);
public static final Param<Integer> MAX_HTTP_CONNECTIONS = Param.arg("mhc", "max_http_connections", "Maximum simultaneous HTTP connections (defaults to 8)", Integer::parseInt);
static final Param<Path> STORAGE_DIR = Param.arg("sd", "storage_directory", "Briefcase storage directory", Common::absolutePath);
static final Param<String> FORM_ID = Param.arg("id", "form_id", "Form ID");
static final Param<Integer> PROJECT_ID = Param.arg("pid", "project_id", "ODK Project ID number", Integer::parseInt);
static final Param<String> CREDENTIALS_USERNAME = Param.arg("u", "odk_username", "ODK Username");
static final Param<String> CREDENTIALS_EMAIL = Param.arg("E", "odk_email", "ODK Email");
static final Param<String> CREDENTIALS_PASSWORD = Param.arg("p", "odk_password", "ODK Password");
public static final Param<String> DEPRECATED_AGGREGATE_SERVER = Param.arg("url", "aggregate_url", "Aggregate server URL");
public static final Param<URL> SERVER_URL = Param.arg("U", "odk_url", "ODK Server URL", RequestBuilder::url);
public static final Param<Integer> MAX_HTTP_CONNECTIONS = Param.arg("mhc", "max_http_connections", "Maximum simultaneous HTTP connections (defaults to 8)", Integer::parseInt);

static Path getOrCreateBriefcaseDir(String storageDir) {
Path briefcaseDir = BriefcasePreferences.buildBriefcaseDir(Paths.get(storageDir));
static Path getOrCreateBriefcaseDir(Path storageDir) {
Path briefcaseDir = BriefcasePreferences.buildBriefcaseDir(storageDir);
if (!Files.exists(briefcaseDir)) {
System.err.println("The directory " + briefcaseDir.toString() + " doesn't exist. Creating it");
UncheckedFiles.createBriefcaseDir(briefcaseDir);
}
return briefcaseDir;
}

/**
* Returns an absolute path to the given string path, using the user.dir property
* to resolve input relative paths if necessary
*/
static Path absolutePath(String path) {
Path storageDir = Paths.get(path);
return storageDir.isAbsolute()
? storageDir
: Paths.get(System.getProperty("user.dir")).resolve(storageDir);
}
}
7 changes: 3 additions & 4 deletions src/org/opendatakit/briefcase/operations/Export.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.opendatakit.briefcase.reused.http.Http.DEFAULT_HTTP_CONNECTIONS;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
Expand Down Expand Up @@ -61,13 +60,13 @@
public class Export {
private static final Logger log = LoggerFactory.getLogger(Export.class);
private static final Param<Void> EXPORT = Param.flag("e", "export", "Export a form");
private static final Param<Path> EXPORT_DIR = Param.arg("ed", "export_directory", "Export directory", Paths::get);
private static final Param<Path> EXPORT_DIR = Param.arg("ed", "export_directory", "Export directory", Common::absolutePath);
private static final Param<String> FILE = Param.arg("f", "export_filename", "Filename for export operation");
private static final Param<LocalDate> START = Param.localDate("start", "export_start_date", "Export start date (inclusive)");
private static final Param<LocalDate> END = Param.localDate("end", "export_end_date", "Export end date (inclusive)");
private static final Param<Void> EXCLUDE_MEDIA = Param.flag("em", "exclude_media_export", "Exclude media in export");
private static final Param<Void> OVERWRITE = Param.flag("oc", "overwrite_csv_export", "Overwrite files during export");
private static final Param<Path> PEM_FILE = Param.arg("pf", "pem_file", "PEM file for form decryption", Paths::get);
private static final Param<Path> PEM_FILE = Param.arg("pf", "pem_file", "PEM file for form decryption", Common::absolutePath);
private static final Param<Void> PULL_BEFORE = Param.flag("pb", "pull_before", "Pull before export");
private static final Param<Void> SPLIT_SELECT_MULTIPLES = Param.flag("ssm", "split_select_multiples", "Split select multiple fields");
private static final Param<Void> INCLUDE_GEOJSON_EXPORT = Param.flag("ig", "include_geojson", "Include a GeoJSON file with spatial data");
Expand Down Expand Up @@ -96,7 +95,7 @@ public class Export {
Arrays.asList(PEM_FILE, EXCLUDE_MEDIA, OVERWRITE, START, END, PULL_BEFORE, SPLIT_SELECT_MULTIPLES, INCLUDE_GEOJSON_EXPORT, REMOVE_GROUP_NAMES, SMART_APPEND)
);

public static void export(String storageDir, String formid, Path exportDir, String baseFilename, boolean exportMedia, boolean overwriteFiles, boolean pullBefore, Optional<LocalDate> startDate, Optional<LocalDate> endDate, Optional<Path> maybePemFile, boolean splitSelectMultiples, boolean includeGeoJsonExport, boolean removeGroupNames, boolean smartAppend) {
public static void export(Path storageDir, String formid, Path exportDir, String baseFilename, boolean exportMedia, boolean overwriteFiles, boolean pullBefore, Optional<LocalDate> startDate, Optional<LocalDate> endDate, Optional<Path> maybePemFile, boolean splitSelectMultiples, boolean includeGeoJsonExport, boolean removeGroupNames, boolean smartAppend) {
CliEventsCompanion.attach(log);
Path briefcaseDir = Common.getOrCreateBriefcaseDir(storageDir);
FormCache formCache = FormCache.from(briefcaseDir);
Expand Down
5 changes: 2 additions & 3 deletions src/org/opendatakit/briefcase/operations/ImportFromODK.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.opendatakit.briefcase.operations.Common.STORAGE_DIR;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Optional;
import org.opendatakit.briefcase.model.FormStatus;
Expand All @@ -37,7 +36,7 @@
public class ImportFromODK {
private static final Logger log = LoggerFactory.getLogger(ImportFromODK.class);
private static final Param<Void> IMPORT = Param.flag("pc", "pull_collect", "Pull from Collect");
private static final Param<Path> ODK_DIR = Param.arg("od", "odk_directory", "ODK directory", Paths::get);
private static final Param<Path> ODK_DIR = Param.arg("od", "odk_directory", "ODK directory", Common::absolutePath);

public static final Operation IMPORT_FROM_ODK = Operation.of(
IMPORT,
Expand All @@ -50,7 +49,7 @@ public class ImportFromODK {
Arrays.asList(FORM_ID)
);

public static void importODK(String storageDir, Path odkDir, Optional<String> formId) {
public static void importODK(Path storageDir, Path odkDir, Optional<String> formId) {
CliEventsCompanion.attach(log);
Path briefcaseDir = Common.getOrCreateBriefcaseDir(storageDir);
FormCache formCache = FormCache.from(briefcaseDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class PullFormFromAggregate {
Arrays.asList(RESUME_LAST_PULL, INCLUDE_INCOMPLETE, FORM_ID, START_FROM_DATE, MAX_HTTP_CONNECTIONS)
);

public static void pullFormFromAggregate(String storageDir, Optional<String> formId, String username, String password, URL server, boolean resumeLastPull, Optional<LocalDate> startFromDate, boolean includeIncomplete, Optional<Integer> maybeMaxHttpConnections) {
public static void pullFormFromAggregate(Path storageDir, Optional<String> formId, String username, String password, URL server, boolean resumeLastPull, Optional<LocalDate> startFromDate, boolean includeIncomplete, Optional<Integer> maybeMaxHttpConnections) {
CliEventsCompanion.attach(log);
Path briefcaseDir = Common.getOrCreateBriefcaseDir(storageDir);
FormCache formCache = FormCache.from(briefcaseDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class PushFormToAggregate {
Arrays.asList(FORCE_SEND_BLANK, MAX_HTTP_CONNECTIONS, FORM_ID)
);

private static void pushFormToAggregate(String storageDir, Optional<String> formid, String username, String password, URL server, boolean forceSendBlank, Optional<Integer> maybeMaxConnections) {
private static void pushFormToAggregate(Path storageDir, Optional<String> formid, String username, String password, URL server, boolean forceSendBlank, Optional<Integer> maybeMaxConnections) {
CliEventsCompanion.attach(log);
Path briefcaseDir = Common.getOrCreateBriefcaseDir(storageDir);
FormCache formCache = FormCache.from(briefcaseDir);
Expand Down
3 changes: 2 additions & 1 deletion src/org/opendatakit/briefcase/ui/BriefcaseCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.opendatakit.briefcase.operations.ImportFromODK.importODK;
import static org.opendatakit.briefcase.operations.PullFormFromAggregate.pullFormFromAggregate;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -289,7 +290,7 @@ public void run() {
String password = cli.getOptionValue(ODK_PASSWORD);
String server = cli.getOptionValue(AGGREGATE_URL);
String formid = cli.getOptionValue(FORM_ID);
String storageDir = cli.getOptionValue(STORAGE_DIRECTORY);
Path storageDir = Paths.get(cli.getOptionValue(STORAGE_DIRECTORY));
String fileName = cli.getOptionValue(EXPORT_FILENAME);
String exportPath = cli.getOptionValue(EXPORT_DIRECTORY);
String startDateString = cli.getOptionValue(EXPORT_START_DATE);
Expand Down

0 comments on commit fd229a4

Please sign in to comment.