Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 26 Jul 2014, 01:24
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Can`t write PuppyPin file with variables in it. [ Solved ]
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
sunburnt


Joined: 08 Jun 2005
Posts: 5009
Location: Arizona, U.S.A.

PostPosted: Mon 14 Jan 2013, 15:39    Post subject:  Can`t write PuppyPin file with variables in it. [ Solved ]  

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:
<?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, 17:44; edited 1 time in total
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Mon 14 Jan 2013, 15:54    Post subject: Re: Can`t write PuppyPin file with variables in it.  

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:
   <backdrop style="Stretched">'"='"$MNT"'/docs/pics/EndlessBlue_1680.jpg</backdrop>


Var with double quotes surrounded by single.

Cheers,
s
Back to top
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 779

PostPosted: Mon 14 Jan 2013, 15:56    Post subject:  

Maybe:
Code:
#!/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
Back to top
View user's profile Send private message Visit poster's website 
sunburnt


Joined: 08 Jun 2005
Posts: 5009
Location: Arizona, U.S.A.

PostPosted: Mon 14 Jan 2013, 17:32    Post subject:  

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:
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 Mon 14 Jan 2013, 20:08; edited 2 times in total
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Mon 14 Jan 2013, 19:53    Post subject:  

sunburnt,

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

Don't ask me why, but they both work here.
Code:
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
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5009
Location: Arizona, U.S.A.

PostPosted: Mon 14 Jan 2013, 20:10    Post subject:  

And a great New Year to you and goingnuts!

Yeah... It`s weird how the echo or cat has to be in the file.
Back to top
View user's profile Send private message 
some1

Joined: 17 Jan 2013
Posts: 21

PostPosted: Sun 24 Feb 2013, 21:28    Post subject:  

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:
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:
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
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0669s ][ Queries: 11 (0.0029s) ][ GZIP on ]