* added --conflict option to -extract mode

This commit is contained in:
Reinhard Pointner 2012-03-10 10:24:35 +00:00
parent 0b35b1abc1
commit 64f93c991b
5 changed files with 37 additions and 18 deletions

View File

@ -63,7 +63,7 @@ public class ArgumentProcessor {
Collection<File> files = new LinkedHashSet<File>(args.getFiles(true));
if (args.extract) {
files.addAll(cli.extract(files, args.output));
files.addAll(cli.extract(files, args.output, args.conflict));
}
if (args.getSubtitles) {

View File

@ -30,6 +30,6 @@ public interface CmdlineInterface {
String getMediaInfo(File file, String format) throws Exception;
List<File> extract(Collection<File> files, String output) throws Exception;
List<File> extract(Collection<File> files, String output, String conflict) throws Exception;
}

View File

@ -928,7 +928,9 @@ public class CmdlineOperations implements CmdlineInterface {
@Override
public List<File> extract(Collection<File> files, String output) throws Exception {
public List<File> extract(Collection<File> files, String output, String conflict) throws Exception {
ConflictAction conflictAction = ConflictAction.forName(conflict);
// only keep single-volume archives or first part of multi-volume archives
List<File> archiveFiles = filter(files, Archive.VOLUME_ONE_FILTER);
List<File> extractedFiles = new ArrayList<File>();
@ -942,12 +944,19 @@ public class CmdlineOperations implements CmdlineInterface {
FileMapper outputMapper = new FileMapper(outputFolder, false);
List<File> entries = archive.listFiles();
boolean skip = true;
for (File entry : entries) {
extractedFiles.add(outputMapper.getOutputFile(entry));
File outputFile = outputMapper.getOutputFile(entry);
skip &= outputFile.exists();
extractedFiles.add(outputFile);
}
CLILogger.finest("Extracting files " + entries);
archive.extract(outputMapper);
if (!skip || conflictAction == ConflictAction.OVERRIDE) {
CLILogger.finest("Extracting files " + entries);
archive.extract(outputMapper);
} else {
CLILogger.finest("Skipped extracting files " + entries);
}
} finally {
archive.close();
}

View File

@ -187,19 +187,19 @@ List.metaClass.sortBySimilarity = { prime, Closure toStringFunction = { obj -> o
// CLI bindings
def rename(args) { args = _defaults(args)
synchronized (_cli) {
_guarded { _cli.rename(_files(args), args.action, args.conflict, args.output, args.format, args.db, args.query, args.order, args.lang, args.strict) }
_guarded { _cli.rename(_files(args), args.action as String, args.conflict as String, args.output as String, args.format as String, args.db as String, args.query as String, args.order as String, args.lang as String, args.strict as Boolean) }
}
}
def getSubtitles(args) { args = _defaults(args)
synchronized (_cli) {
_guarded { _cli.getSubtitles(_files(args), args.query, args.lang, args.output, args.encoding, args.strict) }
_guarded { _cli.getSubtitles(_files(args), args.query as String, args.lang as String, args.output as String, args.encoding as String, args.strict as Boolean) }
}
}
def getMissingSubtitles(args) { args = _defaults(args)
synchronized (_cli) {
_guarded { _cli.getMissingSubtitles(_files(args), args.query, args.lang, args.output, args.encoding, args.strict) }
_guarded { _cli.getMissingSubtitles(_files(args), args.query as String, args.lang as String, args.output as String, args.encoding as String, args.strict as Boolean) }
}
}
@ -211,25 +211,25 @@ def check(args) {
def compute(args) { args = _defaults(args)
synchronized (_cli) {
_guarded { _cli.compute(_files(args), args.output, args.encoding) }
_guarded { _cli.compute(_files(args), args.output as String, args.encoding as String) }
}
}
def extract(args) { args = _defaults(args)
synchronized (_cli) {
_guarded { _cli.extract(_files(args), args.output) }
_guarded { _cli.extract(_files(args), args.output as String, args.conflict as String) }
}
}
def fetchEpisodeList(args) { args = _defaults(args)
synchronized (_cli) {
_guarded { _cli.fetchEpisodeList(args.query, args.format, args.db, args.order, args.lang) }
_guarded { _cli.fetchEpisodeList(args.query as String, args.format as String, args.db as String, args.order as String, args.lang as String) }
}
}
def getMediaInfo(args) { args = _defaults(args)
synchronized (_cli) {
_guarded { _cli.getMediaInfo(args.file, args.format) }
_guarded { _cli.getMediaInfo(args.file as File, args.format as String) }
}
}
@ -239,11 +239,16 @@ def getMediaInfo(args) { args = _defaults(args)
*/
def _files(args) {
def files = [];
if (args.folder)
args.folder.traverse(type:FILES, maxDepth:0) { files += it }
if (args.file)
files += args.file
if (args.folder) {
(args.folder as File).traverse(type:FILES, maxDepth:0) { files += it }
}
if (args.file) {
if (args.file instanceof Iterable || args.file instanceof File[]) {
files += args.file as List
} else {
files += args.file as File
}
}
return files
}

View File

@ -193,6 +193,11 @@
<td>rename action</td>
<td>move | copy | keeplink | symlink | hardlink</td>
</tr>
<tr>
<td>--conflict</td>
<td>conflict resolution</td>
<td>override | skip | fail</td>
</tr>
<tr>
<td>-get-subtitles</td>
<td>fetch subtitles</td>