Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
openmole
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
RoiArthurB
openmole
Commits
02d0d44a
Commit
02d0d44a
authored
May 11, 2020
by
Romain Reuillon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Core] enh: refactor writable output
parent
9fa387e2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
52 deletions
+50
-52
openmole/core/org.openmole.core.workflow/src/main/scala/org/openmole/core/workflow/format/CSVOutputFormat.scala
...a/org/openmole/core/workflow/format/CSVOutputFormat.scala
+4
-4
openmole/core/org.openmole.core.workflow/src/main/scala/org/openmole/core/workflow/format/WritableOutput.scala
...la/org/openmole/core/workflow/format/WritableOutput.scala
+7
-9
openmole/core/org.openmole.core.workflow/src/main/scala/org/openmole/core/workflow/format/package.scala
...ain/scala/org/openmole/core/workflow/format/package.scala
+1
-1
openmole/plugins/org.openmole.plugin.hook.json/src/main/scala/org/openmole/plugin/hook/json/JSONOutputFormat.scala
...cala/org/openmole/plugin/hook/json/JSONOutputFormat.scala
+4
-4
openmole/plugins/org.openmole.plugin.hook.omr/src/main/scala/org/openmole/plugin/hook/omr/Activator.scala
...c/main/scala/org/openmole/plugin/hook/omr/Activator.scala
+1
-1
openmole/plugins/org.openmole.plugin.hook.omr/src/main/scala/org/openmole/plugin/hook/omr/OMROutputFormat.scala
.../scala/org/openmole/plugin/hook/omr/OMROutputFormat.scala
+33
-33
No files found.
openmole/core/org.openmole.core.workflow/src/main/scala/org/openmole/core/workflow/format/CSVOutputFormat.scala
View file @
02d0d44a
...
...
@@ -38,7 +38,7 @@ object CSVOutputFormat {
import
WritableOutput._
(
output
,
content
)
match
{
case
(
FileValu
e
(
file
),
PlainContent
(
variables
,
name
))
⇒
case
(
Stor
e
(
file
),
PlainContent
(
variables
,
name
))
⇒
val
f
=
name
match
{
case
None
⇒
file
.
from
(
context
)
...
...
@@ -46,12 +46,12 @@ object CSVOutputFormat {
}
writeFile
(
f
,
variables
)
case
(
FileValu
e
(
file
),
SectionContent
(
sections
))
⇒
case
(
Stor
e
(
file
),
SectionContent
(
sections
))
⇒
val
directory
=
file
.
from
(
context
)
for
{
section
←
sections
}
writeFile
(
directory
/
s
"${section.name.from(context)}.csv"
,
section
.
variables
)
case
(
StreamValue
(
ps
),
PlainContent
(
variables
,
name
))
⇒
case
(
Display
(
ps
),
PlainContent
(
variables
,
name
))
⇒
writeStream
(
ps
,
name
.
map
(
_
.
from
(
context
)),
variables
)
case
(
StreamValue
(
ps
),
SectionContent
(
sections
))
⇒
case
(
Display
(
ps
),
SectionContent
(
sections
))
⇒
for
{
section
←
sections
}
writeStream
(
ps
,
Some
(
section
.
name
.
from
(
context
)),
section
.
variables
)
}
}
...
...
openmole/core/org.openmole.core.workflow/src/main/scala/org/openmole/core/workflow/format/WritableOutput.scala
View file @
02d0d44a
...
...
@@ -23,19 +23,17 @@ import org.openmole.core.expansion.FromContext
object
WritableOutput
{
implicit
def
fromFile
(
file
:
File
)
=
FileValu
e
(
file
)
implicit
def
fromFileContext
(
file
:
FromContext
[
File
])
=
FileValu
e
(
file
)
implicit
def
fromPrintStream
(
ps
:
PrintStream
)
=
StreamValue
(
ps
)
implicit
def
fromFile
(
file
:
File
)
=
Stor
e
(
file
)
implicit
def
fromFileContext
(
file
:
FromContext
[
File
])
=
Stor
e
(
file
)
implicit
def
fromPrintStream
(
ps
:
PrintStream
)
=
Display
(
ps
)
type
Display
=
PrintStream
case
class
FileValue
(
file
:
FromContext
[
File
])
extends
WritableOutput
case
class
StreamValue
(
stream
:
PrintStream
)
extends
WritableOutput
case
class
Store
(
file
:
FromContext
[
File
])
extends
WritableOutput
case
class
Display
(
stream
:
PrintStream
)
extends
WritableOutput
def
file
(
writableOutput
:
WritableOutput
)
=
writableOutput
match
{
case
FileValu
e
(
file
)
⇒
Some
(
file
)
case
_
⇒
None
case
Stor
e
(
file
)
⇒
Some
(
file
)
case
_
⇒
None
}
}
...
...
openmole/core/org.openmole.core.workflow/src/main/scala/org/openmole/core/workflow/format/package.scala
View file @
02d0d44a
...
...
@@ -6,7 +6,7 @@ package format {
trait
FormatPackage
{
type
Display
=
WritableOutput
.
Display
def
display
(
implicit
outputRedirection
:
OutputRedirection
)
:
Display
=
outputRedirection
.
output
def
display
(
implicit
outputRedirection
:
OutputRedirection
)
:
Display
=
WritableOutput
.
Display
(
outputRedirection
.
output
)
def
CSVOutputFormat
=
format
.
CSVOutputFormat
}
}
...
...
openmole/plugins/org.openmole.plugin.hook.json/src/main/scala/org/openmole/plugin/hook/json/JSONOutputFormat.scala
View file @
02d0d44a
...
...
@@ -26,7 +26,7 @@ object JSONOutputFormat {
)
(
output
,
content
)
match
{
case
(
FileValu
e
(
file
),
PlainContent
(
variables
,
name
))
⇒
case
(
Stor
e
(
file
),
PlainContent
(
variables
,
name
))
⇒
val
f
=
name
match
{
case
Some
(
n
)
⇒
file
/
s
"${n.from(context)}.json"
...
...
@@ -36,18 +36,18 @@ object JSONOutputFormat {
f
.
from
(
context
).
withPrintStream
(
append
=
false
,
create
=
true
)
{
ps
⇒
ps
.
print
(
compact
(
render
(
variablesToJValue
(
variables
))))
}
case
(
FileValu
e
(
file
),
sections
:
SectionContent
)
⇒
case
(
Stor
e
(
file
),
sections
:
SectionContent
)
⇒
file
.
from
(
context
).
withPrintStream
(
append
=
false
,
create
=
true
)
{
ps
⇒
ps
.
print
(
compact
(
render
(
sectionContent
(
sections
))))
}
case
(
StreamValue
(
ps
),
PlainContent
(
variables
,
name
))
⇒
case
(
Display
(
ps
),
PlainContent
(
variables
,
name
))
⇒
name
match
{
case
Some
(
f
)
⇒
ps
.
println
(
s
"${f.from(context)}:"
)
ps
.
println
(
pretty
(
render
(
variablesToJValue
(
variables
))).
split
(
"\n"
).
map
(
" "
+
_
).
mkString
(
"\n"
))
case
None
⇒
ps
.
println
(
pretty
(
render
(
variablesToJValue
(
variables
))))
}
case
(
StreamValue
(
ps
),
sections
:
SectionContent
)
⇒
case
(
Display
(
ps
),
sections
:
SectionContent
)
⇒
ps
.
println
(
pretty
(
render
(
sectionContent
(
sections
))))
}
...
...
openmole/plugins/org.openmole.plugin.hook.omr/src/main/scala/org/openmole/plugin/hook/omr/Activator.scala
View file @
02d0d44a
...
...
@@ -34,7 +34,7 @@ class Activator extends PluginInfoActivator {
val
keyWords
:
Vector
[
KeyWord
]
=
Vector
(
// TaskKeyWord(objectName(JSONHook)),
// OtherKeyWord(objectName(JSON
OutputFormat))
OtherKeyWord
(
objectName
(
OMR
OutputFormat
))
)
PluginInfo
.
register
(
this
,
Vector
(
this
.
getClass
.
getPackage
),
keyWords
=
keyWords
)
...
...
openmole/plugins/org.openmole.plugin.hook.omr/src/main/scala/org/openmole/plugin/hook/omr/OMROutputFormat.scala
View file @
02d0d44a
//package org.openmole.plugin.hook.omr
package
org.openmole.plugin.hook.omr
import
org.openmole.core.dsl._
import
org.openmole.core.dsl.extension._
import
org.openmole.core.workflow.format.CSVOutputFormat
import
org.openmole.core.workflow.hook.FromContextHook
import
org.openmole.plugin.tool.json._
object
OMROutputFormat
{
implicit
def
outputFormat
:
OutputFormat
[
OMROutputFormat
,
Any
]
=
new
OutputFormat
[
OMROutputFormat
,
Any
]
{
override
def
write
(
format
:
OMROutputFormat
,
output
:
WritableOutput
,
content
:
OutputContent
,
method
:
Any
)
:
FromContext
[
Unit
]
=
FromContext
{
p
⇒
import
p._
import
org.json4s._
import
org.json4s.jackson.JsonMethods._
implicit
val
formats
=
DefaultFormats
output
match
{
case
WritableOutput
.
Display
(
stream
)
=>
implicitly
[
OutputFormat
[
CSVOutputFormat
,
Any
]].
write
(
CSVOutputFormat
(),
output
,
content
,
method
)
case
WritableOutput
.
Store
(
file
)
=>
import
org.openmole.tool.tar._
// file.from(context).withTarGZOutputStream {
//
//import org.openmole.core.dsl._
//import org.openmole.core.dsl.extension._
//import org.openmole.core.workflow.hook.FromContextHook
//import org.openmole.plugin.tool.json._
//
//object OMROutputFormat {
//
// implicit def outputFormat = new OutputFormat[OMROutputFormat, Any] {
// override def write(format: OMROutputFormat, output: WritableOutput, variables: Seq[Variable[_]]): FromContext[Unit] = FromContext { p ⇒
// import p._
// import org.json4s._
// import org.json4s.jackson.JsonMethods._
//
// implicit val formats = DefaultFormats
//
// output match {
// case WritableOutput.FileValue(file) ⇒
// file.from(context).withPrintStream(append = false, create = true) { ps ⇒
// ps.print(compact(render(variablesToJValue(variables))))
// }
// case WritableOutput.StreamValue(ps, prelude) ⇒
// prelude.foreach(ps.print)
// ps.println(pretty(render(variablesToJValue(variables))))
// }
// }
//
// override def validate(format: OMROutputFormat): FromContextHook.ValidateParameters ⇒ Seq[Throwable] = { p ⇒ Seq() }
// override def extension = ".omr"
// }
//
//}
//
//case class OMROutputFormat()
}
}
override
def
validate
(
format
:
OMROutputFormat
)
:
FromContextHook.ValidateParameters
⇒
Seq
[
Throwable
]
=
{
p
⇒
Seq
()
}
}
}
case
class
OMROutputFormat
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment