Click here to go to the forum index Click here for the home page
 
Author Message

<  TAP and patch development  ~  Using Puppy with PERL on LinkStation

Page 1 of 3
Goto page 1, 2, 3  Next
EMJB
Posted: Thu Feb 04, 2010 11:28 am Reply with quote
Frequent contributor Joined: 08 Jul 2005 Posts: 3638 Location: Maldon Essex
Are there any PERL programmers out there who can tell me how to use puppy to transfer files to & from the Toppy within a PERL application running on a LinkStation etc? The "system" function only seems to work with other PERL programs.

EMJB
View user's profile Send private message
mstombs
Posted: Thu Feb 04, 2010 12:59 pm Reply with quote
Frequent contributor Joined: 31 Dec 2006 Posts: 938
This doesn't qualify me as a PERL programmer, but I did once modify a version of this perl script which uses the Net::FTP interface to create an auto archive function via ftpd_topfield on localhost

http://forum.toppy.org.uk/forum/viewtopic.php?p=155410#155410

_________________
TF5800 1.5TB, TS On, NSLU2 + unslung 6.10 + WD500GB + MWI 0.66, F/W: MS6 Recommended F/W 12/9/2009 -Fm+AfBmC0CfCtFsIMPePfPsScUWfWs
TAPs: EPG2MEI v0.96; QuickJump 1.72; SecCache (UK) v0.4; (MyInfo B5.6); MHEG On/Off A3; Extend v1.7; MyStuff 6.6; DumbWidescreenTV 2.44; TF5000 Display v1.53; PruneEPG 1.0; (EIT Sub v0.6 SnG);
Sig generated with help from MyInfo on 18/4/15
?
View user's profile Send private message TF5800
R2-D2
Posted: Thu Feb 04, 2010 1:59 pm Reply with quote
Frequent contributor Joined: 18 Dec 2006 Posts: 12148
system() is the way to do it. What do you get if you try this?
Code:
system("ls");

_________________
Troubleshooting -- User Manual -- Dark Side of the Matrix: Firmwares and Patches
View user's profile Send private message Visit poster's website
EMJB
Posted: Thu Feb 04, 2010 5:33 pm Reply with quote
Frequent contributor Joined: 08 Jul 2005 Posts: 3638 Location: Maldon Essex
@R2-D2

Encouraged by your response, I have made some progress, and have tried a large number of variations using the system command as in this test:

Code:
!/usr/bin/perl
   my ($sourcedir) = "/mnt/disk1/share/MoreSoftware/perl/Test";
   chdir("$sourcedir");
   print("Contents of: $sourcedir\n");
   system("ls");
   my ($filename) = "Test.txt";
   
         #Attempt 1 - puts up puppy usage message
#   my ($commandstr) = "-c put '/mnt/disk1/share/MoreSoftware/perl/Test/$filename' '/ProgramFiles/$filename'";
#   print("Attempt 1 using command string: $commandstr\n");
#   system("/opt/bin/puppy", "$commandstr");
   
         #Attempt 2 - puts up puppy usage message
#   $commandstr = "-c put /mnt/disk1/share/MoreSoftware/perl/Test/$filename /ProgramFiles/$filename";
#   print("Attempt 2 using command string: $commandstr\n");
#   system("/opt/bin/puppy", "$commandstr");                                 
   
         #Attempt 3 - complains source does not exist
   print("Attempt 3\n");
   system("/opt/bin/puppy", "-c" , "put", "'$sourcedir/Test.txt'" ,"'/ProgramFiles/$filename'");
   
         #Attempt 4 - does nothing
   print("Attempt 4\n");
   system("/opt/bin/puppy", "-c" , "put", "/mnt/disk1/share/MoreSoftware/perl/Test/Test.txt" ,"/ProgramFiles/$filename");
   
#         #Attempt 5 - puts up puppy usage message
#   print("Attempt 5\n");
#   system("/opt/bin/puppy", " -c put '/mnt/disk1/share/MoreSoftware/perl/Test/$filename' '/ProgramFiles/$filename'");


The "ls" sems to work correctly. Many of the versions I have tried put up the puppy syntax message, attempt 3 complains it can't find the test file which is listed by "ls", and attempt 4 does nothing:



Can you come to my rescue (yet again!) and tell me what I am doig wrong?

EMJB[/img]
View user's profile Send private message
R2-D2
Posted: Thu Feb 04, 2010 7:47 pm Reply with quote
Frequent contributor Joined: 18 Dec 2006 Posts: 12148
EMJB wrote:
Code:
         #Attempt 1 - puts up puppy usage message
#   my ($commandstr) = "-c put '/mnt/disk1/share/MoreSoftware/perl/Test/$filename' '/ProgramFiles/$filename'";
#   print("Attempt 1 using command string: $commandstr\n");
#   system("/opt/bin/puppy", "$commandstr");
I think you need to either put the whole commandline in one string, or each argument separately (as in your 3rd and 4th attempts).
Quote:
Code:
         #Attempt 3 - complains source does not exist
   print("Attempt 3\n");
   system("/opt/bin/puppy", "-c" , "put", "'$sourcedir/Test.txt'" ,"'/ProgramFiles/$filename'");
Stray single quotes in the filename args.
Quote:
Code:
         #Attempt 4 - does nothing
   print("Attempt 4\n");
   system("/opt/bin/puppy", "-c" , "put", "/mnt/disk1/share/MoreSoftware/perl/Test/Test.txt" ,"/ProgramFiles/$filename");
That one looks good to me. Are you sure it did nothing? Maybe increase puppy's verbosity to see what it's doing (or check what's on the Toppy!).

_________________
Troubleshooting -- User Manual -- Dark Side of the Matrix: Firmwares and Patches
View user's profile Send private message Visit poster's website
birdman
Posted: Fri Feb 05, 2010 12:36 am Reply with quote
Frequent contributor Joined: 13 Dec 2006 Posts: 1765 Location: Hitchin, HERTS Tx: Sandy Heath
EMJB wrote:
Are there any PERL programmers out there who can tell me how to use puppy to transfer files to & from the Toppy within a PERL application running on a LinkStation etc?
Yes.
But puppy can do the transfers itself, so would you like to explain what you want the perl part to do?

PS: remember that puppy will only accept Window's command-line style pathnames, so it needs \ as the separator, not /. (Windows internally allows either, as would perl, but you're passing those names to puppy.

_________________

Toppy: TF5800PVR/250 - Black, now 1TB WD10EURX
F/W: MS6 Recommended F/W 12/9/2009 -FmVrXp+BmC0CbFsIPsUUuWfZXl,
Loader: C5.14, Hardware: 1.01
TAPs: SecCache (UK) v0.4; EPG2MEI v0.96; FontManager 1.0d; QuickJump 1.71; MhegOnOff(Now1) A3; EIT Sub v0.6; MyStuff 6.6
USB connected: SheevaPlug with Debian wheezy
Sig mostly from MyInfo on 26/10/09
View user's profile Send private message
birdman
Posted: Fri Feb 05, 2010 12:42 am Reply with quote
Frequent contributor Joined: 13 Dec 2006 Posts: 1765 Location: Hitchin, HERTS Tx: Sandy Heath
R2-D2 wrote:
I think you need to either put the whole commandline in one string, or each argument separately (as in your 3rd and 4th attempts).
The latter is more efficient and "safer", as its handled by an internal fork&exec. The former may use the shell - if there are any active shell characters in the command.

_________________

Toppy: TF5800PVR/250 - Black, now 1TB WD10EURX
F/W: MS6 Recommended F/W 12/9/2009 -FmVrXp+BmC0CbFsIPsUUuWfZXl,
Loader: C5.14, Hardware: 1.01
TAPs: SecCache (UK) v0.4; EPG2MEI v0.96; FontManager 1.0d; QuickJump 1.71; MhegOnOff(Now1) A3; EIT Sub v0.6; MyStuff 6.6
USB connected: SheevaPlug with Debian wheezy
Sig mostly from MyInfo on 26/10/09
View user's profile Send private message
EMJB
Posted: Fri Feb 05, 2010 10:11 am Reply with quote
Frequent contributor Joined: 08 Jul 2005 Posts: 3638 Location: Maldon Essex
birdman wrote:
But puppy can do the transfers itself, so would you like to explain what you want the perl part to do?
I am preparing some files with the perl part, and want to transfer them to the toppy, all as one crontab task.

birdman wrote:
PS: remember that puppy will only accept Window's command-line style pathnames, so it needs \ as the separator, not /. (Windows internally allows either, as would perl, but you're passing those names to puppy.
Ah that is part of my problem - have generated some files called things like /Test/Test.txt in my Toppy root directory that I can't now delete. However it does look as if the source file has to be with the unix style slashes (remember I am running on a LinkStation, not PC).

To make life easier, have been investigating using the dir command. Can successfully display contents of DataFiles etc, but not next level down. It appears puppy needs the single quotes in these cases, but
Code:
my ($dirstr) = sprintf("%s%s%s","'","ProgramFiles\Logs","'");
produces the wrong answer. Run out of time to investigate further, but will keep you informed.

Thanks, both, for your help,

EMJB
View user's profile Send private message
EMJB
Posted: Fri Feb 05, 2010 4:25 pm Reply with quote
Frequent contributor Joined: 08 Jul 2005 Posts: 3638 Location: Maldon Essex
After much trial and error, I have got the following test code to work:
Code:
   my ($filename) = "Test.txt";
   my ($sourcedir) = "/mnt/disk1/share/MoreSoftware/perl/Test/";
   my ($destdir) = "Test/";

   my ($count) = 0;                                 # swap slashes
   $posn = index($destdir,"/");
   while ($posn >= 0 and $count < 10)
   {
      substr($destdir,$posn,1,chr(92));
      $posn = index($destdir,"/");
      $count = $count + 1;
   }

   system("/opt/bin/puppy", "-c" , "put", "$sourcedir$filename" ,"$destdir$filename");


The key points seem to be:

(1) references to directories on the Linkstation use the unix convention and (can or must?) begin with a slash.

(2) References to directories on the Toppy use the windows convention and must NOT start with a slash.

(3) Perl seems to get confused by backslashes, so the only way I have foud of correct operation is to generate the string using the Unix convention, and then convert the slashes

I have not yet tried anything with a space in the name to find if single quotes are then needed - I hope not!

Thanks for help R2-D2 & birdman,

EMJB
View user's profile Send private message
R2-D2
Posted: Fri Feb 05, 2010 10:05 pm Reply with quote
Frequent contributor Joined: 18 Dec 2006 Posts: 12148
EMJB wrote:
(3) Perl seems to get confused by backslashes, so the only way I have foud of correct operation is to generate the string using the Unix convention, and then convert the slashes
I doubt Perl itself is confused, but the (really very, very common) use of backslash as an escape character can make writing an explicit one quite tricky with the layers of evaluation that happen in a scripting language like Perl.
Quote:
I have not yet tried anything with a space in the name to find if single quotes are then needed - I hope not!
Spaces are only an issue if the whole commandline is given as a single string, so that's one reason why the separated form is preferred.

_________________
Troubleshooting -- User Manual -- Dark Side of the Matrix: Firmwares and Patches
View user's profile Send private message Visit poster's website
birdman
Posted: Fri Feb 05, 2010 10:07 pm Reply with quote
Frequent contributor Joined: 13 Dec 2006 Posts: 1765 Location: Hitchin, HERTS Tx: Sandy Heath
EMJB wrote:
(1) references to directories on the Linkstation use the unix convention and (can or must?) begin with a slash.
Odd - I've always had to use \ in both parts. Perhaps I should look at the code and see if it could handle either all the time (although I have a vague memory of having done that already).

and also wrote:
(2) References to directories on the Toppy use the windows convention and must NOT start with a slash.
I always start mine with \DataFiles (vide infra).

and also wrote:
(3) Perl seems to get confused by backslashes
I beg to differ. Perl is not confused at all - you are. Smile
In a double-quoted string ("...", qq(...), etc.) Perl will treat \ as an escape character, so if you want a real \ you need to put in \\. In a single quoted string ('...', q(...), etc.) you just need one of them.
Since you're interpolating variables you're using the "..." form.

and further wrote:
I have not yet tried anything with a space in the name to find if single quotes are then needed - I hope not!
Since you are using the LIST form of system it's not going to use a shell, so you don't need to worry about having to quote or escape spaces in the names.

FWIW: I use this code to copy things off a Toppy. I just use shell scripting.

Code:
# Expects to be given unix-style pathnames
#
fetch() {
   from="$1"
   to=`basename "$from" | sed -e's/ /_/g'`
# Now need to convert to MS-DOS ones, for puppy
# NOTE: the level of escaping needed...
#
   from=`echo "$from" | sed -e's/\//\\\\/g'`
   puppy -c get "$from" "$to"
   echo "Done $to at `date`"
}
....
  fetch '/DataFiles/4_DVD/Merlin_091010.rec'
  fetch '/DataFiles/4_DVD/My Cousin Vinny_091011.rec'
....

which just copies from that file to the current directory, and replaces any spaces in the names with _ (so I don't have to worry about spaces on the Unix command line later). But it lets me specify everything as standard Unix pathnames.

PS: You can delete the a/b/c files on the Toppy. puppy can do it (after all - it put them there) provide you specify the right mixture of \ to specify the directory) then / in the filename.

_________________

Toppy: TF5800PVR/250 - Black, now 1TB WD10EURX
F/W: MS6 Recommended F/W 12/9/2009 -FmVrXp+BmC0CbFsIPsUUuWfZXl,
Loader: C5.14, Hardware: 1.01
TAPs: SecCache (UK) v0.4; EPG2MEI v0.96; FontManager 1.0d; QuickJump 1.71; MhegOnOff(Now1) A3; EIT Sub v0.6; MyStuff 6.6
USB connected: SheevaPlug with Debian wheezy
Sig mostly from MyInfo on 26/10/09
View user's profile Send private message
EMJB
Posted: Sat Feb 06, 2010 9:52 am Reply with quote
Frequent contributor Joined: 08 Jul 2005 Posts: 3638 Location: Maldon Essex
@birdman,

Not going to get into arguments over whether it is me or perl that is confused!

With regards to the puppy issues, perhaps I have an out of date version - mine is at least two years old. I note, however, that the examples here all omit the leading backslash from the examples. What also confused me was the use of single quotes in the examples.

EMJB
View user's profile Send private message
birdman
Posted: Sun Feb 07, 2010 2:45 pm Reply with quote
Frequent contributor Joined: 13 Dec 2006 Posts: 1765 Location: Hitchin, HERTS Tx: Sandy Heath
EMJB wrote:
I note, however, that the examples here all omit the leading backslash from the examples.

That just the difference between relative and absolute pathnames. Without a leading \ the path is relative to where the remote process happens to be. And it happens to start in \ (or / - according to your preference).
Code:
puppy -c dir DataFiles
and
Code:
puppy -c dir '\DataFiles'
do the same thing
EMJB also wrote:
What also confused me was the use of single quotes in the examples.
That's just to stop the shell taking the \ as an escape character. If they were in double-quotes you'd *might* need two.
Quote:
[mysys]: echo a
a
[mysys]: echo \a
a
[mysys]: echo '\a'
\a


PS: As for me using \ in the Unix pathnames - I was wrong I always just use a filename, rather than a pathname, on the Unix side, having cd'ed to where I want it.

_________________

Toppy: TF5800PVR/250 - Black, now 1TB WD10EURX
F/W: MS6 Recommended F/W 12/9/2009 -FmVrXp+BmC0CbFsIPsUUuWfZXl,
Loader: C5.14, Hardware: 1.01
TAPs: SecCache (UK) v0.4; EPG2MEI v0.96; FontManager 1.0d; QuickJump 1.71; MhegOnOff(Now1) A3; EIT Sub v0.6; MyStuff 6.6
USB connected: SheevaPlug with Debian wheezy
Sig mostly from MyInfo on 26/10/09
View user's profile Send private message
EMJB
Posted: Sun Feb 07, 2010 4:17 pm Reply with quote
Frequent contributor Joined: 08 Jul 2005 Posts: 3638 Location: Maldon Essex
@birdman

Thanks for the further information & clarification. At the moment my application seems to be vaguely working, with no problems on the Toppy interface side using the rules above. so I am concentrating on a matching TAP before returning to the perl code - swapping between languages is not something to be done too often!

When I return to perl, I will investigate the points you raise further. Thinking about it, the failure to work with a leading slash in the path may be the difficulting (for me at least!) in generating a leading backslash in the perl code without it being interpreted as the beginning of a control code by perl. I generated the path from one with forward slashes by code that replaces all "/" character by chr(92), but perhaps there is a better way.

EMJB
View user's profile Send private message
R2-D2
Posted: Sun Feb 07, 2010 5:11 pm Reply with quote
Frequent contributor Joined: 18 Dec 2006 Posts: 12148
EMJB wrote:
perhaps there is a better way.
There is a way to write them explicitly, but quite how many backslashes you need to include in order to end up with the right number will depend on how much evaluation is being done at the point where the string is defined through to where it is used. So it can be quite a complicated and annoying thing, especially when the only reason you're forced to do this is because Microsoft made the stupid decision to use backslash as the path separator in MS-DOS (and thus Windows).

_________________
Troubleshooting -- User Manual -- Dark Side of the Matrix: Firmwares and Patches
View user's profile Send private message Visit poster's website

Display posts from previous:  

All times are GMT + 1 Hour
Page 1 of 3
Goto page 1, 2, 3  Next

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