Commit 5104d33d authored by Mohamed, Fawzi Roberto (fawzi)'s avatar Mohamed, Fawzi Roberto (fawzi)
Browse files

added --source-paths-file to h5Tool

parent d8e1aaba
......@@ -28,6 +28,7 @@ import java.nio.file.attribute.BasicFileAttributes
import com.typesafe.scalalogging.StrictLogging
import eu.nomad_lab.LocalEnv
import scala.util.control.NonFatal
import scala.io.Source
object H5Tool extends StrictLogging {
......@@ -219,6 +220,7 @@ object H5Tool extends StrictLogging {
|h5Tool rename
| [--renames=<renamesFile>]
| [--source-path=<pathToH5Archive>]
| [--source-paths-file=<pathToFileWithH5ArchivesPaths>]
| [--target-dir=<pathToOutputDirectory>]
| [--flat-dir]
| [--source-paths [path1 [path2 ...]]]
......@@ -243,9 +245,11 @@ object H5Tool extends StrictLogging {
var list: List[String] = args
val renamesRe = "^--renames=(.*)$".r
val sourcePathRe = "^--source-path=(.*)$".r
val sourcePathsFileRe = "^--source-paths-file=(.*)$".r
val targetDirRe = "^--target-dir=(.*)$".r
var replacements: Seq[Replacements] = Seq()
var sourcePaths: Seq[Path] = Seq()
var sourcePathsFiles: Seq[Path] = Seq()
var targetDir: Option[Path] = None
var flatDir: Boolean = false
while (!list.isEmpty) {
......@@ -261,6 +265,8 @@ object H5Tool extends StrictLogging {
targetDir = Some(Paths.get(targetD))
case sourcePathRe(p) =>
sourcePaths = sourcePaths :+ Paths.get(p)
case sourcePathsFileRe(p) =>
sourcePathsFiles = sourcePathsFiles :+ Paths.get(p)
case "--flat-dir" => flatDir = true
case "--source-paths" =>
sourcePaths ++= list.map { x: String => Paths.get(x) }
......@@ -269,7 +275,8 @@ object H5Tool extends StrictLogging {
throw new Exception(s"unexpected argument '$other'")
}
}
for (inF <- sourcePaths) {
def renameFile(inF: Path): Unit = {
val targetPath = targetDir match {
case Some(dir) =>
val tPath = flatDir match {
......@@ -289,13 +296,20 @@ object H5Tool extends StrictLogging {
}
val targetF = FileH5.open(targetPath, write = true)
try {
for (repl <- replacements)
H5Rename.renameStr(targetF, repl)
H5Rename.renameStr(targetF, replacements)
} catch {
case NonFatal(e) =>
logger.error(s"Failure while doing replacements in file at $targetPath", e)
}
targetF.release()
}
for (inF <- sourcePaths)
renameFile(inF)
for (sFilePath <- sourcePathsFiles) {
val sFile = Source.fromFile(sFilePath.toFile)
for (p <- sFile.getLines()) {
renameFile(Paths.get(p))
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment