custody: initial commit

This commit is contained in:
Philip Monk 2019-10-08 18:35:22 -07:00
parent 8dca89f6f8
commit 754fd61e1b
No known key found for this signature in database
GPG Key ID: B66E1F02604E44EC
3 changed files with 194 additions and 0 deletions

16
pkg/arvo/gen/sql.hoon Normal file
View File

@ -0,0 +1,16 @@
/+ *custody, *csv
|= [=key=path =loc=path]
%. ~
%- print-rows
%+ select
!, *hoon
:* (need ship.left)
physical-form.left
==
%^ join
(load:keys key-path)
(load:locations loc-path)
!, *hoon
?& !=(~ ship.left)
=(location.left location.right)
==

78
pkg/arvo/lib/csv.hoon Normal file
View File

@ -0,0 +1,78 @@
|%
++ text
%+ cook
|= =tape
(crip tape)
;~ pose
(cook tape soil:vast)
non-quote-text
==
::
++ non-quote-text
(star ;~(less com qit))
::
++ parse
|* cols=(list rule)
%+ ifix
:- ;~(sfix ;~(less (just `@`10) (star prn)) (just `@`10))
(just `@`10)
(more (just `@`10) (parse-line cols))
::
++ parse-line
|* cols=(list rule)
?~ cols
(easy ~)
?~ t.cols
i.cols
;~ plug
i.cols
;~(pfix com $(cols t.cols))
==
::
:: inner join
::
++ join
=/ name-side (ream '[left=- right=+]')
|= [left=(list vase) rite=(list vase) =hoon]
^- (list vase)
|- ^- (list vase)
=* left-loop $
?~ left
~
=/ rote rite
|- ^- (list vase)
=* rite-loop $
?~ rite
left-loop(left t.left, rite rote)
=/ slopped-row (slap (slop i.left i.rite) name-side)
=/ val (slap (slop slopped-row !>(..zuse)) hoon)
?. =(%& q.val)
rite-loop(rite t.rite)
:- slopped-row
rite-loop(rite t.rite)
::
:: filter
::
++ where
|= [rows=(list vase) =hoon]
^- (list vase)
%+ skim rows
|= =vase
=/ val (slap vase hoon)
=(%& q.val)
::
:: select
::
++ select
|= [=hoon rows=(list vase)]
^- (list vase)
%+ turn rows
|= =vase
(slap (slop vase !>(..zuse)) hoon)
::
:: pretty-print rows
::
++ print-rows
|= rows=(list vase)
(slog (turn rows sell))
--

100
pkg/arvo/lib/custody.hoon Normal file
View File

@ -0,0 +1,100 @@
/+ csv
|%
++ fed ;~(pfix sig fed:ag)
++ parse-enum
|* form=mold
%- sear :_ text:csv
|= =cord
((soft form) cord)
::
++ keys
=< form
|%
+$ form
$: =location:locations
ship=(unit ship)
=role
shard=(unit shard)
copy=(unit copy)
=physical-form
note=cord
formal-ship=(unit ship)
==
::
+$ role
$? %empty
%other
%master
%own
%spawn
%manage
%vote
%transfer
==
::
+$ shard @udshard
+$ copy ?(%a %b %c)
+$ physical-form ?(%usb %dvd %paper)
++ parsers
:~ text:csv
(punt fed)
(parse-enum role)
(punt dim:ag)
(punt (parse-enum copy))
(parse-enum physical-form)
text:csv
(punt fed)
==
::
++ parse
%+ cook
|* arg=*
^- (list form)
arg
(parse:csv parsers)
::
++ load-forms
|= =path
^- (list form)
(rash (of-wain:format .^(wain %cx path)) parse)
::
++ load
|= =path
^- (list vase)
(turn (load-forms path) |=(=form !>(form)))
--
::
++ locations
=< form
|%
+$ form
$: =location
description=@t
=physical-location
==
+$ location @tlocation
+$ physical-location @tphysicallocation
++ parsers
:~ text:csv
text:csv
text:csv
==
::
++ parse
%+ cook
|* arg=*
^- (list form)
arg
(parse:csv parsers)
::
++ load-forms
|= =path
^- (list form)
(rash (of-wain:format .^(wain %cx path)) parse)
::
++ load
|= =path
^- (list vase)
(turn (load-forms path) |=(=form !>(form)))
--
--