[Swift-commit] r7243 - in provenancedb: . tags
wilde at ci.uchicago.edu
wilde at ci.uchicago.edu
Tue Oct 29 15:19:35 CDT 2013
Author: wilde
Date: 2013-10-29 15:19:35 -0500 (Tue, 29 Oct 2013)
New Revision: 7243
Added:
provenancedb/tags/
provenancedb/tags/locate.server
provenancedb/tags/setup.sh
provenancedb/tags/tagrm
provenancedb/tags/tags-init.sql
provenancedb/tags/tlocate
provenancedb/tags/ttag
Log:
initial version
Added: provenancedb/tags/locate.server
===================================================================
--- provenancedb/tags/locate.server (rev 0)
+++ provenancedb/tags/locate.server 2013-10-29 20:19:35 UTC (rev 7243)
@@ -0,0 +1,86 @@
+#! /bin/sh
+
+TAGDB=${TAGDB:-provdb}
+
+SQLCMD="psql -U provdb -h swift.rcc.uchicago.edu $TAGDB"
+
+format=default
+
+echo
+
+if [ _"$1" = _ -o _"$1" = '_*' ]; then
+ WHERE="(select distinct dataset_id from annot_dataset_text)"
+else
+ WHERE=$(echo $* | sed -e "s/\([[:alnum:]_-]\+\)[[:space:]]*\([!=<>]\+\|like\|ilike\)[[:space:]]*\([[:alnum:] *%.:_-]\+\)/(select dataset_id from annot_dataset_text where name = '\1' AND value \2 '\3')/g" -e "s/ and / INTERSECT /g" -e "s/ or / UNION /g")
+fi
+
+QUERY="select * from annot_dataset_text where dataset_id in ($WHERE);"
+
+TQUERY="select * from annot_dataset_text where dataset_id in (
+ select dataset_id from annot_dataset_text where (name='owner' and value='wilde') intersect
+ select dataset_id from annot_dataset_text where (name='type' and value='pdb')
+ );"
+
+# echo -e "$QUERY\n"
+
+$SQLCMD -c "$QUERY" >t.out
+head -2 t.out >t.hdr
+tail -n +3 t.out | sort >t.body
+
+if [ $format = default ]; then
+
+cat t.hdr t.body | awk '
+BEGIN {
+ start=0
+ for(i=0;i<1024;i++) spaces = spaces " ";
+}
+start==0 { print $0 }
+start==1 {
+ if ($1 != lastid)
+ print "\n" $0;
+ else {
+ line=$0
+ sub("^[^|]*| ",nullds,line);
+ print line;
+ }
+ lastid = $1;
+}
+/------/ {
+ start=1
+ dslen=match($0,"+")-1;
+ nullds = substr(spaces,1,dslen);
+}
+'
+
+elif [ $format = cols ]; then
+
+cat t.hdr t.body | awk '
+BEGIN {
+ start=0
+ for(i=0;i<1024;i++) spaces = spaces " ";
+ fields = [ a3 a4 ];
+}
+start==0 { print $0 }
+start==1 {
+ if ($1 != lastid)
+ print "\n" $0;
+ else {
+ line=$0
+ sub("^[^|]*| ",nullds,line);
+ print line;
+ }
+ lastid = $1;
+}
+/------/ {
+ start=1
+ dslen=match($0,"+")-1;
+ nullds = substr(spaces,1,dslen);
+}
+'
+
+fi
+
+
+exit
+
+locate owner=sinitzkiy or owner=wilde
Property changes on: provenancedb/tags/locate.server
___________________________________________________________________
Added: svn:executable
+ *
Added: provenancedb/tags/setup.sh
===================================================================
--- provenancedb/tags/setup.sh (rev 0)
+++ provenancedb/tags/setup.sh 2013-10-29 20:19:35 UTC (rev 7243)
@@ -0,0 +1,42 @@
+# ensure that this script is being sourced
+
+if [ ${BASH_VERSINFO[0]} -gt 2 -a "${BASH_SOURCE[0]}" = "${0}" ] ; then
+ echo ERROR: script ${BASH_SOURCE[0]} must be executed as: source ${BASH_SOURCE[0]}
+ exit 1
+fi
+
+# Setting scripts folder to the PATH env var.
+
+TAGDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+if [ _$(which tag 2>/dev/null) != _$TAGDIR/tag ]; then
+ echo Adding $TAGDIR: to front of PATH
+ PATH=$TAGDIR:$PATH
+else
+ echo Assuming $TAGDIR: is already in PATH
+fi
+
+# Setting .pgpass
+
+if [ -e $HOME/.pgpass ]; then
+ savepgpass=$(mktemp $HOME/.pgpass.XXXX)
+ echo Saving $HOME/.pgpass in $savepgpass
+ mv $HOME/.pgpass $savepgpass
+fi
+
+cat >>$HOME/.pgpass <<END
+swift.rcc.uchicago.edu:5432:provdb:provdb:sesame
+END
+
+#----------
+
+return
+
+PATH=$PWD:/home/wilde/pgsql/bin:$PATH
+
+#-----------
+
+PATH=/home/wilde/swift/provenancedb:/home/wilde/swift/provwork:/home/wilde/pgsql/bin:$PATH
+
+alias sql="psql -U provdb -h swift.rcc.uchicago.edu provdb -c"
+
Property changes on: provenancedb/tags/setup.sh
___________________________________________________________________
Added: svn:executable
+ *
Added: provenancedb/tags/tagrm
===================================================================
--- provenancedb/tags/tagrm (rev 0)
+++ provenancedb/tags/tagrm 2013-10-29 20:19:35 UTC (rev 7243)
@@ -0,0 +1,54 @@
+#! /bin/sh
+
+usage()
+{
+ echo $0: usage:
+ cat <<END
+ -m|--multiple allow multiple tags with the same name
+ -h|-?|?|--help print this help
+END
+}
+
+TAGDB=${TAGDB:-provdb}
+SQLCMD="psql -U provdb -h swift.rcc.uchicago.edu $TAGDB"
+
+object=$1
+shift
+
+if [ $# = 0 ]; then
+ echo DELETING all tags for object = $object
+ $SQLCMD -c "DELETE FROM ds WHERE (id = '$object');"
+ $SQLCMD -c "DELETE FROM annot_dataset_text WHERE (dataset_id = '$object');"
+else
+ for name in "$@"; do
+ echo DELETING name=$name
+ $SQLCMD -c "DELETE FROM annot_dataset_text WHERE (dataset_id = '$object' AND name = '$name');"
+ done
+fi
+
+exit
+
+
+# FIXME: insert arg handling as needed:
+
+multiple=false
+while [ $# -gt 0 ]; do
+ case $1 in
+ -m|--multiple) multiple=true; shift 1 ;;
+ -h|-?|--help|-*|--*) usage; exit ;;
+ *) break ;;
+ esac
+ # shift 2
+done
+echo multiple=$multiple
+
+exit
+
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'owner', 'wilde');
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'group', 'cmts-cyber');
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'create-date', '2013.0123.23:07:29.123');
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'type', 'pdb');
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'state', 'unverified');
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'note','Initial structure prediction from loop model. mw');
+
+END
Property changes on: provenancedb/tags/tagrm
___________________________________________________________________
Added: svn:executable
+ *
Added: provenancedb/tags/tags-init.sql
===================================================================
--- provenancedb/tags/tags-init.sql (rev 0)
+++ provenancedb/tags/tags-init.sql 2013-10-29 20:19:35 UTC (rev 7243)
@@ -0,0 +1,32 @@
+-- this is the schema definition used for the main relational provenance
+-- implementation (in both sqlite3 and postgres)
+
+drop table annot_dataset_num cascade;
+drop table annot_dataset_text cascade;
+drop table ds cascade;
+
+-- ds stores all dataset identifiers.
+
+create table ds (
+ uid serial,
+ id varchar(256) primary key
+);
+
+create table annot_dataset_num (
+ -- dataset_id varchar(256) references ds (id) on delete cascade,
+ dataset_id varchar(256), -- on delete cascade,
+ name varchar(256),
+ value numeric,
+ uid serial primary key
+ -- primary key (dataset_id, name)
+);
+
+create table annot_dataset_text(
+ -- dataset_id varchar(256) references ds (id) on delete cascade,
+ dataset_id varchar(256), -- on delete cascade,
+ name varchar(256),
+ value varchar(2048),
+ uid serial primary key
+ -- primary key (dataset_id, name)
+);
+
Added: provenancedb/tags/tlocate
===================================================================
--- provenancedb/tags/tlocate (rev 0)
+++ provenancedb/tags/tlocate 2013-10-29 20:19:35 UTC (rev 7243)
@@ -0,0 +1,86 @@
+#! /bin/sh
+
+TAGDB=${TAGDB:-provdb}
+
+SQLCMD="psql -U provdb -h swift.rcc.uchicago.edu $TAGDB"
+
+format=default
+
+echo
+
+if [ _"$1" = _ -o _"$1" = '_*' ]; then
+ WHERE="(select distinct dataset_id from annot_dataset_text)"
+else
+ WHERE=$(echo $* | sed -e "s/\([[:alnum:]_-]\+\)[[:space:]]*\([!=<>]\+\|like\|ilike\)[[:space:]]*\([[:alnum:] *%.:_-]\+\)/(select dataset_id from annot_dataset_text where name = '\1' AND value \2 '\3')/g" -e "s/ and / INTERSECT /g" -e "s/ or / UNION /g")
+fi
+
+QUERY="select * from annot_dataset_text where dataset_id in ($WHERE);"
+
+TQUERY="select * from annot_dataset_text where dataset_id in (
+ select dataset_id from annot_dataset_text where (name='owner' and value='wilde') intersect
+ select dataset_id from annot_dataset_text where (name='type' and value='pdb')
+ );"
+
+echo -e "$QUERY\n"
+
+$SQLCMD -c "$QUERY" >t.out
+head -2 t.out >t.hdr
+tail -n +2 t.out | sort >t.body
+
+if [ $format = default ]; then
+
+cat t.hdr t.body | awk '
+BEGIN {
+ start=0
+ for(i=0;i<1024;i++) spaces = spaces " ";
+}
+start==0 { print $0 }
+start==1 {
+ if ($1 != lastid)
+ print "\n" $0;
+ else {
+ line=$0
+ sub("^[^|]*| ",nullds,line);
+ print line;
+ }
+ lastid = $1;
+}
+/------/ {
+ start=1
+ dslen=match($0,"+")-1;
+ nullds = substr(spaces,1,dslen);
+}
+'
+
+elif [ $format = cols ]; then
+
+cat t.hdr t.body | awk '
+BEGIN {
+ start=0
+ for(i=0;i<1024;i++) spaces = spaces " ";
+ fields = [ a3 a4 ];
+}
+start==0 { print $0 }
+start==1 {
+ if ($1 != lastid)
+ print "\n" $0;
+ else {
+ line=$0
+ sub("^[^|]*| ",nullds,line);
+ print line;
+ }
+ lastid = $1;
+}
+/------/ {
+ start=1
+ dslen=match($0,"+")-1;
+ nullds = substr(spaces,1,dslen);
+}
+'
+
+fi
+
+
+exit
+
+locate owner=sinitzkiy or owner=wilde
Property changes on: provenancedb/tags/tlocate
___________________________________________________________________
Added: svn:executable
+ *
Added: provenancedb/tags/ttag
===================================================================
--- provenancedb/tags/ttag (rev 0)
+++ provenancedb/tags/ttag 2013-10-29 20:19:35 UTC (rev 7243)
@@ -0,0 +1,68 @@
+#! /bin/sh
+
+TAGDB=${TAGDB:-provdb}
+
+SQLCMD="psql -U provdb -h swift.rcc.uchicago.edu $TAGDB"
+
+multiple=false
+while [ $# -gt 0 ]; do
+ case $1 in
+ -m|--multiple) multiple=true; shift 1 ;;
+ -h|-?|--help|-*|--*) usage; exit ;;
+ *) break ;;
+ esac
+ # shift 2
+done
+
+echo multiple=$multiple
+
+object=$1
+#count=$#
+#echo count=$count
+#last="$7"
+#echo last="$last"
+shift
+
+$SQLCMD -c "insert into ds (id) values ('$object');"
+
+
+usage()
+{
+ echo $0: usage:
+ cat <<END
+ -m|--multiple allow multiple tags with the same name
+ -h|-?|?|--help print this help
+END
+}
+
+for anno in "$@"; do
+ name=$(echo "$anno" | awk -F= '{print $1}')
+ value=$(echo "$anno" | awk -F= '{print $2}')
+ echo anno=$anno name=$name value="$value"
+ if [ $multiple = false ]; then
+ $SQLCMD -c "
+ DO
+ \$\$
+ BEGIN
+ IF EXISTS ( SELECT 1 FROM annot_dataset_text WHERE dataset_id = '$object' and name = '$name' ) THEN
+ UPDATE annot_dataset_text SET value = '$value' WHERE dataset_id = '$object' and name = '$name' ;
+ ELSE
+ INSERT INTO annot_dataset_text (dataset_id, name, value) VALUES ('$object', '$name', '$value') ;
+ END IF;
+ END;
+ \$\$"
+ else
+ $SQLCMD -c "insert into annot_dataset_text (dataset_id, name, value) values ('$object', '$name', '$value');"
+ fi
+done
+
+exit
+
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'owner', 'wilde');
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'group', 'cmts-cyber');
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'create-date', '2013.0123.23:07:29.123');
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'type', 'pdb');
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'state', 'unverified');
+insert into annot_dataset_text (dataset_id, name, value) values ('/d1/d2/f1', 'note','Initial structure prediction from loop model. mw');
+
+END
Property changes on: provenancedb/tags/ttag
___________________________________________________________________
Added: svn:executable
+ *
More information about the Swift-commit
mailing list