Can`t write PuppyPin file with variables in it. [ Solved ]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

Can`t write PuppyPin file with variables in it. [ Solved ]

#1 Post by sunburnt »

I`m rewriting my Puppy setup script, and writing PuppyPin is part of it.

My PuppyPin file I want to write has variables, but they`re written as literals:

Code: Select all

<?xml version="1.0"?>
<pinboard>
  <backdrop style="Stretched">$MNT/docs/pics/EndlessBlue_1680.jpg</backdrop>
  <icon x="32" y="32" label="file">/usr/local/bin/rox</icon>
  <icon x="102" y="32" label="mount">/usr/sbin/pmount</icon>
  <icon x="32" y="128" label="console">/usr/bin/rxvt</icon>
  <icon x="32" y="224" label="play">/usr/local/bin/defaultmediaplayer</icon>
  <icon x="32" y="320" label="browse">/usr/local/bin/defaultbrowser</icon>
  <icon x="32" y="416" label="Apps">$MNT/apps</icon>
  <icon x="102" y="416" label="DnLd">$MNT/dnld</icon>
  <icon x="32" y="512" label="Docs">$MNT/docs</icon>
  <icon x="102" y="512" label="Docs_PC">$MNT/docs_PC</icon>
  <icon x="32" y="608" label="AppPkg">$MNT/AppPkg</icon>
  <icon x="32" y="704" label="BaCon">$MNT/BaCon</icon>
  <icon x="32" y="852" label="trash">/usr/local/apps/Trash</icon>
</pinboard>
I tried single quoting the whole XML code except for the variables: $MNT
Then I tried single quoting each line of code except for the variables.
Both methods just write $MNT instead of it`s value: /mnt/sda3

I hope I don`t have to do a complex set of "echo -e -n" commands.
Seems like it should be simple, just another reason why I dislike XML...

### HowTo write an XML file so variables in it are evaluated properly?
Last edited by sunburnt on Mon 14 Jan 2013, 21:44, edited 1 time in total.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

Re: Can`t write PuppyPin file with variables in it.

#2 Post by seaside »

sunburnt wrote:I`m rewriting my Puppy setup script, and writing PuppyPin is part of it.



### HowTo write an XML file so variables in it are evaluated properly?
sunburnt,

Try -

Code: Select all

   <backdrop style="Stretched">'"='"$MNT"'/docs/pics/EndlessBlue_1680.jpg</backdrop>
Var with double quotes surrounded by single.

Cheers,
s

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#3 Post by goingnuts »

Maybe:

Code: Select all

#!/bin/sh
MNT=/dev/sda1
echo '<?xml version="1.0"?>
<pinboard>
  <backdrop style="Stretched">'$MNT'/docs/pics/EndlessBlue_1680.jpg</backdrop>
  <icon x="32" y="32" label="file">/usr/local/bin/rox</icon>
</pinboard>' > testresult.txt

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#4 Post by sunburnt »

Hi seaside; It`s good to hear from you again.
I tried doubles inside singles and it just removes the doubles leaving the singles.

I`m still working on AppPkg, it`s evolved quite a bit and getting better.

goingnuts; I pretty much knew your solution would work.
I was hoping to be able to leave the PuppyPin file pristine, but...
I modified your script to source PuppyPin with an argument.
Call modded PuppyPin with: . /(path)/PuppyPin /mnt/sda3

Code: Select all

echo '<?xml version="1.0"?>
<pinboard>
  <backdrop style="Stretched">'$1'/docs/pics/EndlessBlue_1680.jpg</backdrop>
  <icon x="32" y="32" label="file">/usr/local/bin/rox</icon>
  <icon x="102" y="32" label="mount">/usr/sbin/pmount</icon>
  <icon x="32" y="128" label="console">/usr/bin/rxvt</icon>
  <icon x="32" y="224" label="play">/usr/local/bin/defaultmediaplayer</icon>
  <icon x="32" y="320" label="browse">/usr/local/bin/defaultbrowser</icon>
  <icon x="32" y="416" label="Apps">'$1'/apps</icon>
  <icon x="102" y="416" label="DnLd">'$1'/dnld</icon>
  <icon x="32" y="512" label="Docs">'$1'/docs</icon>
  <icon x="102" y="512" label="Docs_PC">'$1'/docs_PC</icon>
  <icon x="32" y="608" label="AppPkg">'$1'/AppPkg</icon>
  <icon x="32" y="704" label="BaCon">'$1'/BaCon</icon>
  <icon x="32" y="852" label="trash">/usr/local/apps/Trash</icon>
</pinboard>' > $HOME/Choices/ROX-Filer/PuppyPin
# It`s weird how in no way can you read PuppyPin and echo it properly ( XML ).

# I guess I need to refresh Puppy`s Hot Mount to redraw the desktop drive icons.

### Thanks seaside and goingnuts !!!
.
Last edited by sunburnt on Tue 15 Jan 2013, 00:08, edited 2 times in total.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#5 Post by seaside »

sunburnt,

Happy New Year and here's hoping you'll get your "ideal" wish for a minimal system. :D

Don't ask me why, but they both work here.

Code: Select all

MNT=/dev/sda1
echo '<?xml version="1.0"?>
<pinboard>
  <backdrop style="Stretched">'"$MNT"'/docs/pics/EndlessBlue_1680.jpg</backdrop>
  <icon x="32" y="32" label="file">/usr/local/bin/rox</icon>
</pinboard>' > testresult.txt

 cat testresult.txt
<?xml version="1.0"?>
<pinboard>
  <backdrop style="Stretched">/dev/sda1/docs/pics/EndlessBlue_1680.jpg</backdrop>
  <icon x="32" y="32" label="file">/usr/local/bin/rox</icon>
</pinboard>
Regards,
s

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#6 Post by sunburnt »

And a great New Year to you and goingnuts!

Yeah... It`s weird how the echo or cat has to be in the file.

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#7 Post by some1 »

Hi

Here is code for a "pristine" template-file.
The template -file PuppyPinz - contains only literals plus the $1 var.

Despite the extra action the code is only slightly slower than sourcing an
"echo"-formatted template-file.


Mechanics:
Suck the template-file in
Encapsulate - so it will be an assignment when sourced -
write the var NEWPIN to the newpuppypin.
The $1 -which is hardcoded in the template-file -
and given as Value on function-call - is expanded when the stuff arrives sourced from the template-file.

There are variants - but this was the fastest I could come up with.
A cat-here version was 4-5 times slower - probably cause of the cat.:wink:

Code: Select all

function roxpintpl_3() 
	# read;write;source;write
IFS=$'\n';echo "NEWPIN='""$(<"$2")""'">./tmppin	
source ./tmppin    # DOT-source instead
echo -n "$NEWPIN">newpuppypin	
}
Call with this:

Code: Select all

roxpintpl_3 "THIS/WORKS" "$HOME/Choices/ROX-Filer/PuppyPinz"
where
THIS/WORKS -> test Upperpath
PuppyPinz >- the template-file

---
Nice idea with the variable as placeholder in the template.
I needed that.


Thanks and cheers

Post Reply