Hi Cameron,<div><br></div><div>First sorry for my very very late reply, has been overloaded at work last week :(</div><div>Anyways... I will reply inline this time ;)<br><br><div class="gmail_quote">On Wed, Feb 8, 2012 at 11:59 AM, Cameron Simpson <span dir="ltr"><<a href="mailto:cs@zip.com.au">cs@zip.com.au</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[ Please reply inline; it makes the discussion read like a converation,<br>
  with context. - Cameron<br>
]<br>
<div class="im"><br>
On 08Feb2012 08:57, Sherif Shehab Aldin <<a href="mailto:silentquote@gmail.com">silentquote@gmail.com</a>> wrote:<br>
| Thanks a lot for your help, I just forgot to state that the FTP server is<br>
| not under my command, I can't control how the file grow, or how the records<br>
| are added, I can only login to It, copy the whole file.<br>
<br>
</div>Oh. That's a pity.<br>
<div class="im"><br>
| The reason why I am parsing the file and trying to get the diffs between<br>
| the new file and the old one, and copy it to new_file.time_stamp is that I<br>
| need to cut down the file size so when server (C) grabs the file, It grabs<br>
| only new data, also to cut down the network bandwidth.<br>
<br>
</div>Can a simple byte count help here? Copy the whole file with FTP. From<br>
the new copy, extract the bytes from the last byte count offset onward.<br>
Then parse the smaller file, extracting whole records for use by (C).<br>
That way you can just keep the unparsed tail (partial record I imagine)<br>
around for the next fetch.<br>
<br>
Looking at RFC959 (the FTP protocol):<br>
<br>
  <a href="http://www.w3.org/Protocols/rfc959/4_FileTransfer.html" target="_blank">http://www.w3.org/Protocols/rfc959/4_FileTransfer.html</a><br>
<br>
it looks like you can do a partial file fetch, also, by issuing a REST<br>
(restart) command to set a file offset and then issuing a RETR (retrieve)<br>
command to get the rest of the file. These all need to be in binary mode<br>
of course.<br>
<br>
So in principle you could track the byte offset of what you have fetched<br>
with FTP so far, and fetch only what is new.<br></blockquote><div><br></div><div> I am actually grabbing the file from ftp with a bash script using lftp, It seemed a simple task for python at the beginning and then I noticed the many problems. I have checked lftp and did not know how to continue downloading a file. Do I have to use ftp library, may be in python so I can use that feature?</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
| One of my problems was after mounting server (B) diffs_dir into Server (A)<br>
| throw NFS, I used to create filename.lock first into server (B) local file<br>
| then start copy filename to server (B) then remove filename.lock, so when<br>
| the daemon running on server (C) parses the files in the local_diffs dir,<br>
| ignores the files that are still being copied,<br>
|<br>
| After searching more yesterday, I found that local mv is atomic, so instead<br>
| of creating the lock files, I will copy the new diffs to tmp dir, and after<br>
| the copy is over, mv it to actual diffs dir, that will avoid reading It<br>
| while It's still being copied.<br>
<br>
</div>Yes, this sounds good. Provided the mv is on the same filesystem.<br>
<br>
For example: "mv /tmp/foo /home/username/foo" is actually a copy and not<br>
a rename because /tmp is normally a different filesystem from /home.<br>
<div class="im"><br></div></blockquote><div>Yes they are in same file system, I am making sure of that ;)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">
| Sorry if the above is bit confusing, the system is bit complex.<br>
<br>
</div>Complex systems often need fiddly solutions.<br>
<div class="im"><br>
| Also there is one more factor that confuses me, I am so bad in testing, and<br>
| I am trying to start actually implement unit testing to test my code, what<br>
| I find hard is how to test code like the one that do the copy, mv and so,<br>
| also the code that fetch data from the web.<br>
<br>
</div>Ha. I used to be very bad at testing, now I am improving and am merely<br>
weak.<br>
<br>
One approach to testing is to make a mock up of the other half of the<br>
system, and test against the mockup.<br>
<br>
For example, you have code to FTP new data and then feed it to (C). You<br>
don't control the server side of the FTP. So you might make a small mock<br>
up program that writes valid (but fictitious) data records progressively<br>
to a local data file (write record, flush, pause briefly, etc). If you<br>
can FTP to your own test machine you could then treat _that_ growing<br>
file as the remote server's data file.<br>
<br>
Then you could copy it progressively using a byte count to keep track of<br>
the bits you have seen to skip them, and the the<br>
<br>
If you can't FTP to your test system, you could abstract out the "fetch<br>
part of this file by FTP" into its own function. Write an equivalent<br>
function that fetches part of a local file just by opening it.<br>
<br>
Then you could use the local file version in a test that doesn't<br>
actually do the FTP, but could exercise the rest of it.<br>
<br>
It is also useful to make simple tests of small pieces of the code.<br>
So make the code to get part of the data a simple function, and write<br>
tests to execute it in a few ways (no new data, part of a record,<br>
several records etc).<br>
<br></blockquote><div>You are right, my problem is that I don't care about testing until my code grows badly and then I notice what I got myself into :)<br>But ur suggestion is cool. I will try to implement that once I get back to that project again... As I got some problems with another project currently so I had to go fix them first.. and then the customer wanted some changes.. ;-)</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
There are many people better than I to teach testing.<br>
<br></blockquote><div>I really appreciate your help. I am trying to learn from the mailing list, I noticed many interesting posts in the list already. I wish I could read the python-list same way.. but unfortunately the mail digest they send is quiet annoying :(</div>
<div><br></div><div>Many thanks to you, and I will keep you posted if I got other ideas. :) </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Cheers,<br>
<div class="im">--<br>
Cameron Simpson <<a href="mailto:cs@zip.com.au">cs@zip.com.au</a>> DoD#743<br>
<a href="http://www.cskk.ezoshosting.com/cs/" target="_blank">http://www.cskk.ezoshosting.com/cs/</a><br>
<br>
</div>Testing can show the presence of bugs, but not their absence.   - Dijkstra<br>
</blockquote></div><br></div>