Skip to content

Commit

Permalink
0.9.6-pre
Browse files Browse the repository at this point in the history
  • Loading branch information
telatin committed May 17, 2022
1 parent 90029e7 commit 1b38973
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
49 changes: 39 additions & 10 deletions src/make.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ proc newArtifactProperties(uuid, version, format, artifactType: string, archive:
result.format = format
result.artifactType = artifactType
result.archive = archive
result.append = ""
result.append = "created-with: qax"
for propPair in attributes:
if ":" notin propPair:
stderr.writeLine "[making-artifact] Invalid attribute: " & propPair
continue
try:
let
value = propPair.split(":")
result.append &= value[0] & " : " & value[1]
except Exception as e:
stderr.writeLine("Unable to create metadata: invalid attributes: ", e.msg)
stderr.writeLine("[making-artifact] Unable to create metadata: invalid attributes: ", e.msg)
quit(1)

proc makeArtifact(uuid, tmpDir, outputFile: string): bool =
Expand Down Expand Up @@ -62,7 +65,15 @@ proc makeArtifact(uuid, tmpDir, outputFile: string): bool =
setCurrentDir(initialWorkDir)
return true


proc checkAttrs(attrs: seq[string]): seq[string] =
for item in attrs:
if ":" in item:
result.add(item)
elif "=" in item:
result.add(item.split("=")[0] & " : " & item.split("=")[1])
else:
stderr.writeLine("Invalid attribute: ", item)
return
proc makeFile(text, destFile: string): bool =
try:
writeFile(destFile, text)
Expand All @@ -80,7 +91,7 @@ archive: {artifactAttributes.archive}
framework: {artifactAttributes.framework}"""
metadataFileText = fmt"""uuid: {artifactAttributes.uuid}
type: {artifactAttributes.artifactType}
format: {artifactAttributes.format}"""
format: {artifactAttributes.format}""" & "\n" & artifactAttributes.append

try:
# make dir UUID
Expand All @@ -104,6 +115,7 @@ format: {artifactAttributes.format}"""

return true
except Exception as e:
stderr.writeLine("[makeDirectory]: Unable to create temporary directory: ", e.msg)
return false

proc make(argv: var seq[string]): int =
Expand All @@ -112,7 +124,7 @@ proc make(argv: var seq[string]): int =
else: "/tmp/"

let args = docopt( format("""
Usage: make [options] -o <artifact.qzv> <inputdirectory>
Usage: make [options] [-a attr]... -o <artifact.qzv> <inputdirectory>
Create a Qiime Visualization Artifact from a directory with a website,
that must contain a 'index.html' file at the root.
Expand All @@ -126,10 +138,11 @@ Options:
-h, --help Show this help
Attributes:
--format <FORMAT> Artifact format [default: HTML[Report]]
--type <TYPE> Artifact type [default: Visualization]
--version <VERSION> Artifact framework version [default: 2019.10.0]
--archive <ARCHIVE> Artifact archive version [default: 5]
--format FORMAT Artifact format [default: HTML[Report]]
--type TYPE Artifact type [default: Visualization]
--version VERSION Artifact framework version [default: 2019.10.0]
--archive ARCHIVE Artifact archive version [default: 5]
-a, --attr ATTR... Artifact metadata attribute (key=value)
""" % ["env_temp", env_temp]), version=version(), argv=argv)

Expand All @@ -140,6 +153,20 @@ Attributes:
let
force = args["--force"]

if fileExists(absolutePath($args["--output"])):
if not force:
stderr.writeLine("ERROR: Output file already exists: ", $args["--output"])
quit(1)
else:
try:
removeFile(absolutePath($args["--output"]))
except Exception as e:
stderr.writeLine("ERROR: Unable to remove output file: ", $args["--output"])
quit(1)


if verbose:
stderr.writeLine("args: ", args)
if $args["--uuid"] == "nil":
uuid = $genUUID()
else:
Expand Down Expand Up @@ -173,13 +200,15 @@ Attributes:
stderr.writeLine(fmt"Version={aVersion};Format={aFormat};Archive={aArchive}")

var
attributes = @["creator: qax"]
attributes = checkAttrs(@(args["--attr"]))
#attributes = @[""]
artifactAttributes = newArtifactProperties(uuid, aVersion, aFormat, aType, aArchive, attributes)

# Make directory
if makeDirectory($args["<inputdirectory>"], $args["--tempdir"], artifactAttributes):
if verbose:
stderr.writeLine(" * Temporary directory created")
stderr.writeLine(artifactAttributes)
else:
stderr.writeLine("ERROR: Unable to create temporary directory: ", $args["--tempdir"])
quit(1)
Expand Down
3 changes: 2 additions & 1 deletion test/58e75511-d02e-4bea-b7b5-dd71c98e7ac5/metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
uuid: 58e75511-d02e-4bea-b7b5-dd71c98e7ac5
type: Visualization
format: HTML[Report]
format: HTML[Report]
created-with: qax
2 changes: 1 addition & 1 deletion test/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,5 @@ else
exit 1
fi

echo "$(readlink -f $BIN):$($BIN --version)"
echo "VERSION $(readlink -f $BIN 2> /dev/null):$($BIN --version)"
tput init || true

0 comments on commit 1b38973

Please sign in to comment.