#!/bin/bash # # This file is part of SECONDO. # # Copyright (C) 2007, University in Hagen, # Faculty of Mathematcs and Computer Science, # Database Systems for New Applications. # # SECONDO is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # SECONDO is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with SECONDO; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # # # script for creating a relation containing filenames and contents # call this script via: createTextRel .. # example for storing all html in the home directory (incluve subfolders) into a relation: # createTextRelation htmlfiles $(find $HOME -name "*.html") > htmlfilesobj # after that, you can restore the relation in Secondo with: restore htmlfiles from htmlfilesobj # # for many files (more than the possible argumentlist of the current bash) # or for files with spaces in filenames use a pipe for creating the Relation # # # written, 2007, December - Th. Behr # This script converts a set of jpg files into a relation in Secondo's nested list format. # There are different ways to use this script: # # 1. Converting a directory and its subdirectories: # -------------------------------------------------- # createRelation -d [>OutFileName] # The first parameter is the name of the relation to create. Ensure to use a valid # Secondo symbol. After the -d parameter, the directory containing the pictures must be # given. Because the script write to the standard output, the result can be written to # a file in the usual way. # # 2. Converting some files # ------------------------ # If only some files should be converted, the script should be called by: # createRelation ..... # # 3. Reading the filename from stdinput # ------------------------------------- # If the name of the relation is the only one argument, i.e. the script is called via # createRealation # The filenames are read from the standard input. Thereby this script can be used # within a pipe, e.g. # find -iname "*.jpg" | createRelation [>Outfile] # # Hints # ----- # The best place to call this script is Secondo's bin directory. Just enter the complete # path to the script. # On windows platforms it is not possible to use absolute path names. # CONTENTTYPE="picture" CONTENTNAME="Picture" NOW=$(date +"%Y-%m-%d-%T") CI=$SECONDO_BUILD_DIR/Tools/Generators/Pictures/checkImage which stat >/dev/null 2>&1 if [ "$?" = "0" ]; then USESTAT=TRUE stat -c %w . >/dev/null 2>&1 if [ "$?" != "0" ]; then USESTAT=FALSE fi else USESTAT=FALSE fi function writeTuple { if [ "$#" = "0" ]; then read F while [ -n "$F" ]; do $CI "$F" if [ "$?" != "0" ]; then echo "exclude file " $F >&2 else FB=$(basename "$F") if [ "$USESTAT" = "TRUE" ]; then D=$(stat -c %z "$F" | sed "s/\([^ ]*\).*/\1/g" ) else D=$NOW fi # ( ) echo -e " ( $F " echo -e " ( \"$FB\" " echo -e " \"$D\" " echo -e " \"unknown\" " echo -e " TRUE " echo -e " $F)" echo -e " )" fi read F done else while [ "$#" != "0" ]; do F=$1 $CI "$F" if [ "$?" != "0" ]; then echo "exclude file " $F >&2 else FB=$(basename "$F") if [ "$USESTAT" = "TRUE" ]; then D=$(stat -c %y $F | sed "s/\([^ ]*\).*/\1/g" ) else D=$NOW fi # ( ) echo -e " ( $F " echo -e " ( \"$FB\" " echo -e " \"$D\" " echo -e " \"unknown\" " echo -e " TRUE " echo -e " $F)" echo -e " )" fi shift done fi } ### end of configurable part #### CONTENTSTART="" CONTENTEND="" USAGE="createRelation [--oldstyle] ObjectName [..] \n" if [ "$1" = "--oldstyle" ]; then END=")())" shift else END="))" fi # check for relation name if [ "$#" = "0" ]; then echo "missing objectname" >&2 echo "$USAGE" >&2 exit 1 fi HEADER="(OBJECT $1 () (rel (tuple ( (Filename filepath)($CONTENTNAME $CONTENTTYPE ) ))) (" shift if [ "$1" = "-d" ]; then # case directory name is given shift # check for directory name if [ "$#" = "0" ]; then echo "missing argument for -d option" exit 1 fi echo -e "$HEADER" DIR=$1 shift find $DIR -iname "*.jpg" -o -iname "*.jpeg" | writeTuple else echo -e "$HEADER" if [ "$#" -gt "0" ]; then # case filenames are given as arguments for F in $* do writeTuple $F done else # no file specified, read from standardinput e.g. a pipe (use for long argumentlists) read F while [ "$F" ]; do writeTuple $F read F done fi fi echo "$END"