Re: Quanta Digest, Vol 58, Issue 2

"Schimara Marek" <[email protected]>
Newsgroups gmane.comp.kde.devel.quanta.user
Message-ID <[email protected]>
Dne: 6.1.2008 12:00,
[email protected] napsal:

>Am Sonntag, 6. Januar 2008 10:30:00 schrieb Schimara Marek:
>> I suppose I need to use a "Script Action" but I need to know how to define
>> an action of my own (I can write a script which would do what I want but I
>> need to know where to add my custom action, how to call it, the argument
>> which stores the current file name reference etc.). Also, if there is a
>> simpler way to sync, I would certainly appreciate it ;-)
>
>you may want to have a look at
>http://www.hoernerfranzracing.de/kde/script-actions.html - I think sitecopy
>will just do what you want :)
>
>werner


Thanks Werner,

I found some useful info in the quanta help after all, and I was able to write a script of my own, which is executed after each Save operation automatically. I did:

1. created a new script action called Sync (in settings > configure actions), with parameters
sh <full path to the script> %f
Input: None
Output: Message window
Error: Message window

2. added Sync as an action associated with "After Document Save" (in project options > event configuration)

3. created a config file (it goes into $HOME/.kde/share/apps/quanta/) in which I stored the local directory to sync into, and the ftp password - the inconvenience is that the password is stored in plain text but we're talking plain old FTP here...

And it works fine ;-) I'm attaching the script and an example config file in case somebody finds it useful (it works only with FTP though).


thanks :-)
Marek

_______________________________________________
Quanta mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/quanta
quanta-syncFTP.sh (application/x-sh, 2.3 KB)
#/usr/bin/env bash

# Author: Marek Schimara
# Date  : 06/01/2008
#
# Version 0.1

echo "Starting \"`basename $0`\" with arguments: \"$@\"
"

# Format of the config file is:
#
# [ftp.server.full.name]
#     <full path to the local dir>
#     <password>
#
#
# Lines beginning with '#' and empty lines are ignored. The order of parameters is important; there mustn't be anything else except comments and empty lines between them, and nothing else on the same line neither. 

CONFIG="$HOME/.kde/share/apps/quanta/quanta-syncFTP.conf"
if [[ ! -f $CONFIG ]]
then
    echo "Config file \"$CONFIG\" not found."
    exit
fi

# parse the argument for all the necessary parameters
FTP=`echo "$1" | sed 's|\(.*\)://.*|\1|'`
if [[ "$FTP" != "ftp" && "$FTP" != "FTP" ]]
then
    echo "This script only works with FTP based projects."
    exit
fi

USER=`echo "$1" | sed 's|.*://\(.*\)@.*|\1|;s|%40|@|'`
if [[ "$USER" == "" ]]
then
    echo "FTP user not found."
    exit
fi

SERVER=`echo "$1" | sed 's|.*@\(.*\):[0-9]*.*|\1|'`
if [[ "$SERVER" == "" ]]
then
    echo "FTP server not found."
    exit
fi

PORT=`echo "$1" | sed 's|.*:\([0-9]*\)/.*|\1|'`
if [[ "$SERVER" == "" ]]
then
    echo "FTP server port not found."
    exit
fi

FPATH=`echo "$1" | sed 's|.*:[0-9]*/|/|'`
if [[ "$FPATH" == "" ]]
then
    echo "The full path not found."
    exit
fi

FILE=`basename $FPATH`
DIR=`dirname $FPATH`

# get the config for this server from the config file
LOCAL_BASE=`egrep -v '^#|^ *$' $CONFIG | grep -A 1 "$SERVER" | tail -1 | sed 's| *||;s|\(.*\) *$|\1|'`
PASSWORD=`egrep -v '^#|^ *$' $CONFIG | grep -A 2 "$SERVER"  | tail -1 | sed 's| *||;s|\(.*\) *$|\1|'`

echo "user: $USER
server: $SERVER
port: $PORT
password: OK, found.
full path: $FPATH
directory: $DIR
local basedir: $LOCAL_BASE
file: $FILE
" 

# prepare the unattended FTP command file
FTP_COMMANDS="/tmp/quanta-syncFTP.cmd"
echo "open $SERVER $PORT
$USER
$PASSWORD
mkdir $DIR
cd $DIR
pwd
get $FILE
bye" > $FTP_COMMANDS

# prepare the local directory
if [[ ! -d $LOCAL_BASE/$DIR ]]
then
    echo "Local directory doesn't exist, creating."
    mkdir -p $LOCAL_BASE/$DIR
fi
cd $LOCAL_BASE/$DIR

# download the file
echo "FTP transfer:
"
ftp -v < $FTP_COMMANDS
rm -f $FTP_COMMANDS
echo "
\"`basename $0`\" finished. The downloaded file:
`ls -l $LOCAL_BASE/$DIR/$FILE`
"

#END
quanta-syncFTP.conf (application/octet-stream, 170 B)
# this is the first entry
[ftp.example.net]
/home/user/Desktop/example.net
password


# this is the second entry
[upload.example2.net]
/home/user/example2.net
password2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.