Skip to content

Commit

Permalink
Merge pull request #112 from frenetic-lang/textutils
Browse files Browse the repository at this point in the history
Remove dependency on textutils
  • Loading branch information
reitblatt committed Mar 12, 2014
2 parents a3397fb + b14dec0 commit e74fcc4
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 221 deletions.
1 change: 0 additions & 1 deletion _oasis
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Library async
openflow,
cstruct.async,
threads,
textutils,
sexplib.syntax
InternalModules:
Async_OpenFlow_Log,
Expand Down
128 changes: 61 additions & 67 deletions _tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OASIS_START
# DO NOT EDIT (digest: 9b4d102d0ace6c2c7745be83aeb79c7c)
# DO NOT EDIT (digest: 872119f14ab3f21a5c84730a2ca36fe5)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
Expand All @@ -15,133 +15,127 @@
"_darcs": not_hygienic
# Library openflow
"lib/openflow.cmxs": use_openflow
<lib/*.ml{,i}>: package(threads)
<lib/*.ml{,i}>: package(core)
<lib/*.ml{,i}>: package(cstruct)
<lib/*.ml{,i}>: package(cstruct.syntax)
<lib/*.ml{,i}>: package(packet)
<lib/*.ml{,i}>: package(sexplib.syntax)
<lib/*.ml{,i}>: package(str)
<lib/*.ml{,i}>: package(cstruct)
<lib/*.ml{,i}>: package(cstruct.syntax)
<lib/*.ml{,i}>: package(threads)
# Library async
"async/async.cmxs": use_async
<async/*.ml{,i}>: use_openflow
<async/*.ml{,i}>: package(threads)
<async/*.ml{,i}>: package(core)
<async/*.ml{,i}>: package(async)
<async/*.ml{,i}>: package(packet)
<async/*.ml{,i}>: package(core)
<async/*.ml{,i}>: package(cstruct)
<async/*.ml{,i}>: package(cstruct.async)
<async/*.ml{,i}>: package(textutils)
<async/*.ml{,i}>: package(cstruct.syntax)
<async/*.ml{,i}>: package(packet)
<async/*.ml{,i}>: package(sexplib.syntax)
<async/*.ml{,i}>: package(str)
<async/*.ml{,i}>: package(cstruct)
<async/*.ml{,i}>: package(cstruct.syntax)
<async/*.ml{,i}>: package(threads)
<async/*.ml{,i}>: use_openflow
# Library quickcheck
"quickcheck/quickcheck.cmxs": use_quickcheck
<quickcheck/*.ml{,i}>: use_openflow
<quickcheck/*.ml{,i}>: package(threads)
<quickcheck/*.ml{,i}>: package(core)
<quickcheck/*.ml{,i}>: package(cstruct)
<quickcheck/*.ml{,i}>: package(cstruct.syntax)
<quickcheck/*.ml{,i}>: package(packet)
<quickcheck/*.ml{,i}>: package(quickcheck)
<quickcheck/*.ml{,i}>: package(sexplib.syntax)
<quickcheck/*.ml{,i}>: package(str)
<quickcheck/*.ml{,i}>: package(cstruct)
<quickcheck/*.ml{,i}>: package(cstruct.syntax)
<quickcheck/*.ml{,i}>: package(threads)
<quickcheck/*.ml{,i}>: use_openflow
# Executable testtool
"test/Test.byte": use_quickcheck
"test/Test.byte": use_openflow
"test/Test.byte": package(threads)
"test/Test.byte": package(core)
"test/Test.byte": package(packet)
"test/Test.byte": package(cstruct)
"test/Test.byte": package(cstruct.syntax)
"test/Test.byte": package(oUnit)
"test/Test.byte": package(pa_ounit)
"test/Test.byte": package(pa_ounit.syntax)
"test/Test.byte": package(packet)
"test/Test.byte": package(quickcheck)
"test/Test.byte": package(sexplib.syntax)
"test/Test.byte": package(str)
"test/Test.byte": package(cstruct)
"test/Test.byte": package(cstruct.syntax)
<test/*.ml{,i}>: use_quickcheck
<test/*.ml{,i}>: use_openflow
<test/*.ml{,i}>: package(threads)
"test/Test.byte": package(threads)
"test/Test.byte": use_openflow
"test/Test.byte": use_quickcheck
<test/*.ml{,i}>: package(core)
<test/*.ml{,i}>: package(packet)
<test/*.ml{,i}>: package(cstruct)
<test/*.ml{,i}>: package(cstruct.syntax)
<test/*.ml{,i}>: package(oUnit)
<test/*.ml{,i}>: package(pa_ounit)
<test/*.ml{,i}>: package(pa_ounit.syntax)
<test/*.ml{,i}>: package(packet)
<test/*.ml{,i}>: package(quickcheck)
<test/*.ml{,i}>: package(sexplib.syntax)
<test/*.ml{,i}>: package(str)
<test/*.ml{,i}>: package(cstruct)
<test/*.ml{,i}>: package(cstruct.syntax)
<test/*.ml{,i}>: package(threads)
<test/*.ml{,i}>: use_openflow
<test/*.ml{,i}>: use_quickcheck
# Executable ping_test
"ping-test/PingTest.byte": use_async
"ping-test/PingTest.byte": use_openflow
"ping-test/PingTest.byte": package(threads)
"ping-test/PingTest.byte": package(core)
"ping-test/PingTest.byte": package(async)
"ping-test/PingTest.byte": package(packet)
"ping-test/PingTest.byte": package(core)
"ping-test/PingTest.byte": package(cstruct)
"ping-test/PingTest.byte": package(cstruct.async)
"ping-test/PingTest.byte": package(cstruct.syntax)
"ping-test/PingTest.byte": package(oUnit)
"ping-test/PingTest.byte": package(pa_ounit)
"ping-test/PingTest.byte": package(pa_ounit.syntax)
"ping-test/PingTest.byte": package(textutils)
"ping-test/PingTest.byte": package(packet)
"ping-test/PingTest.byte": package(sexplib.syntax)
"ping-test/PingTest.byte": package(str)
"ping-test/PingTest.byte": package(cstruct)
"ping-test/PingTest.byte": package(cstruct.syntax)
<ping-test/*.ml{,i}>: use_async
<ping-test/*.ml{,i}>: use_openflow
<ping-test/*.ml{,i}>: package(threads)
<ping-test/*.ml{,i}>: package(core)
"ping-test/PingTest.byte": package(threads)
"ping-test/PingTest.byte": use_async
"ping-test/PingTest.byte": use_openflow
<ping-test/*.ml{,i}>: package(async)
<ping-test/*.ml{,i}>: package(packet)
<ping-test/*.ml{,i}>: package(core)
<ping-test/*.ml{,i}>: package(cstruct)
<ping-test/*.ml{,i}>: package(cstruct.async)
<ping-test/*.ml{,i}>: package(cstruct.syntax)
<ping-test/*.ml{,i}>: package(oUnit)
<ping-test/*.ml{,i}>: package(pa_ounit)
<ping-test/*.ml{,i}>: package(pa_ounit.syntax)
<ping-test/*.ml{,i}>: package(textutils)
<ping-test/*.ml{,i}>: package(packet)
<ping-test/*.ml{,i}>: package(sexplib.syntax)
<ping-test/*.ml{,i}>: package(str)
<ping-test/*.ml{,i}>: package(cstruct)
<ping-test/*.ml{,i}>: package(cstruct.syntax)
<ping-test/*.ml{,i}>: package(threads)
<ping-test/*.ml{,i}>: use_async
<ping-test/*.ml{,i}>: use_openflow
# Executable Hypervisor
"examples/Hypervisor.byte": use_async
"examples/Hypervisor.byte": use_openflow
"examples/Hypervisor.byte": package(threads)
"examples/Hypervisor.byte": package(core)
"examples/Hypervisor.byte": package(async)
"examples/Hypervisor.byte": package(packet)
"examples/Hypervisor.byte": package(core)
"examples/Hypervisor.byte": package(cstruct)
"examples/Hypervisor.byte": package(cstruct.async)
"examples/Hypervisor.byte": package(textutils)
"examples/Hypervisor.byte": package(cstruct.syntax)
"examples/Hypervisor.byte": package(packet)
"examples/Hypervisor.byte": package(sexplib.syntax)
"examples/Hypervisor.byte": package(str)
"examples/Hypervisor.byte": package(cstruct)
"examples/Hypervisor.byte": package(cstruct.syntax)
"examples/Hypervisor.byte": package(threads)
"examples/Hypervisor.byte": use_async
"examples/Hypervisor.byte": use_openflow
# Executable learning_switch
"examples/Learning_Switch.byte": use_async
"examples/Learning_Switch.byte": use_openflow
"examples/Learning_Switch.byte": package(threads)
"examples/Learning_Switch.byte": package(core)
"examples/Learning_Switch.byte": package(async)
"examples/Learning_Switch.byte": package(packet)
"examples/Learning_Switch.byte": package(core)
"examples/Learning_Switch.byte": package(cstruct)
"examples/Learning_Switch.byte": package(cstruct.async)
"examples/Learning_Switch.byte": package(textutils)
"examples/Learning_Switch.byte": package(cstruct.syntax)
"examples/Learning_Switch.byte": package(packet)
"examples/Learning_Switch.byte": package(sexplib.syntax)
"examples/Learning_Switch.byte": package(str)
"examples/Learning_Switch.byte": package(cstruct)
"examples/Learning_Switch.byte": package(cstruct.syntax)
<examples/*.ml{,i}>: use_async
<examples/*.ml{,i}>: use_openflow
<examples/*.ml{,i}>: package(threads)
<examples/*.ml{,i}>: package(core)
"examples/Learning_Switch.byte": package(threads)
"examples/Learning_Switch.byte": use_async
"examples/Learning_Switch.byte": use_openflow
<examples/*.ml{,i}>: package(async)
<examples/*.ml{,i}>: package(packet)
<examples/*.ml{,i}>: package(core)
<examples/*.ml{,i}>: package(cstruct)
<examples/*.ml{,i}>: package(cstruct.async)
<examples/*.ml{,i}>: package(textutils)
<examples/*.ml{,i}>: package(cstruct.syntax)
<examples/*.ml{,i}>: package(packet)
<examples/*.ml{,i}>: package(sexplib.syntax)
<examples/*.ml{,i}>: package(str)
<examples/*.ml{,i}>: package(cstruct)
<examples/*.ml{,i}>: package(cstruct.syntax)
<examples/*.ml{,i}>: package(threads)
<examples/*.ml{,i}>: use_async
<examples/*.ml{,i}>: use_openflow
# OASIS_STOP
<lib/*.ml>: syntax_camlp4o
<lwt/*.ml>: syntax_camlp4o
Expand Down
2 changes: 1 addition & 1 deletion async/Async_OpenFlow.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Log : sig

include Log.Global_intf

val make_colored_filtered_output : (string * string) list ->
val make_filtered_output : (string * string) list ->
Log.Output.t

end
Expand Down
60 changes: 39 additions & 21 deletions async/Async_OpenFlow_Log.ml
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
open Core.Std
open Async.Std

let filter_by_tags (enabled_tags : (string * string) list)
(messages : Log.Message.t Queue.t) : Log.Message.t Queue.t =
Queue.filter_map messages (fun msg ->
match Log.Message.tags msg with
| [] -> Some msg (* untagged messages are printed indiscriminately *)
| msg_tags ->
if List.exists ~f:(List.mem enabled_tags) msg_tags then
Some msg
else
None)

let make_colored_filtered_output (tags : (string * string) list)
module TagSet = Set.Make(struct
type t = string * string with sexp
let compare = Pervasives.compare
end)

let filter_by_tags (enabled_tags : (string * string) list) =
let enabled_tags = TagSet.of_list enabled_tags in
(fun msgs ->
Queue.filter_map msgs (fun msg ->
match Log.Message.tags msg with
| [] -> Some msg (* untagged messages are printed indiscriminately *)
| msg_tags ->
if List.exists ~f:(TagSet.mem enabled_tags) msg_tags then
Some msg
else
None))

let label_severity msg =
let debug, info, error = [`Dim], [`Blue], [`Red] in
let style, prefix = match Log.Message.level msg with
| None -> info, ""
| Some `Debug -> debug, "[DEBUG]"
| Some `Info -> info, " [INFO]"
| Some `Error -> error, "[ERROR]" in
String.concat ~sep:" "
[ prefix
; Log.Message.message msg ]

let make_filtered_output (tags : (string * string) list)
: Log.Output.t =
let filter = filter_by_tags tags in
Log.Output.create
(fun queue ->
Textutils.Console.Log.Output.create
~debug:[`Dim] ~info:[`Blue] ~error:[`Red]
(Lazy.force Writer.stderr)
(filter_by_tags tags queue))
(fun msgs ->
let writer = Lazy.force (Writer.stderr) in
return (Queue.iter (filter msgs) ~f:(fun msg ->
Writer.write writer (label_severity msg);
Writer.newline writer)))

let colorized_stderr : Log.Output.t =
make_colored_filtered_output [("openflow", "")]
let stderr : Log.Output.t =
make_filtered_output [("openflow", "")]

let log = lazy (Log.create ~level:`Info ~output:[colorized_stderr])
let log = lazy (Log.create ~level:`Info ~output:[stderr])

let set_level = Log.set_level (Lazy.force log)

Expand All @@ -50,4 +68,4 @@ let of_lazy ?(tags=[]) ?(level=`Debug) lazy_str =
let sexp ?(tags=[]) ?(level=`Debug) msg =
Log.sexp (Lazy.force log) ~tags ~level msg

let message = Log.message (Lazy.force log)
let message = Log.message (Lazy.force log)
2 changes: 1 addition & 1 deletion examples/Hypervisor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type chunk = OFAsync.Chunk.Message.t
let _ = Log.set_level `Debug

let _ = Log.set_output
[Log.make_colored_filtered_output [("openflow", "socket");
[Log.make_filtered_output [("openflow", "socket");
("openflow", "serialization")]]

let openflow_parser = OFAsync.OpenFlow0x01.chunk_conv
Expand Down
4 changes: 2 additions & 2 deletions lib/META
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OASIS_START
# DO NOT EDIT (digest: 87ef16a01b93a8a867cb1ac9883d4022)
# DO NOT EDIT (digest: 1c838b69b24adcd8387ed95f9166c840)
version = "0.2.0"
description = "Serialization library for OpenFlow"
requires = "str cstruct cstruct.syntax packet core sexplib.syntax threads"
Expand All @@ -22,7 +22,7 @@ package "quickcheck" (
package "async" (
version = "0.2.0"
description = "Serialization library for OpenFlow"
requires = "async openflow cstruct.async threads textutils sexplib.syntax"
requires = "async openflow cstruct.async threads sexplib.syntax"
archive(byte) = "async.cma"
archive(byte, plugin) = "async.cma"
archive(native) = "async.cmxa"
Expand Down
Loading

0 comments on commit e74fcc4

Please sign in to comment.