I have come across a problem with the OS: Python 2.7.1 (running on Mac OS X 10.7.5). UTM command  
 I am trying to develop a script that downloads files from an FTP that matches certain criteria but if the file exists and I have a copy of it on a local dein So if I do not match the file revision time, then I will download the new copy. To achieve this, I get the FTP file revision time, convert it into timestamp and then use the OSUT to match the FTP server and use the downloaded files and the dates of the modification to change. My problem is that as soon as I get out of the substrin, where I change the time of admission and amendment, they return to the original people! I do not have anything to do in the background and I have also tested the script with the same result on the Linux server  
 If you press the code twice, it will show problems as files in debug comments The FTP server did not change, but the timestamps did not match the local people who had changed correctly. Thanks in advance for any help in this problem.   import  Import from datetime import datetime def to DownloadAndSetTimestamp (local_file, fi, nt): lf = open (local_file, 'wb') f. Returbarini ("RETR" + Fi, LF Written, 8 * 1024) lf.close Print Fi + "Downloaded!" Print "- & gt; transforming the first meat:" + str (Osstet (Sthaniy_fail) .st_mtime) print "- & gt; changes from the first time:" + str (Osstet (Sthaniy_fail) .st_atime) print "- & gt; FTP value: "+ str (int (nt)) # Time of change will be similar to server for future comparison os.utime (local_file, (int (nt), int (nt))" -> After change mtime Print: "+ Str (osstst (local_file) .st_mtime) print" - & gt; time after the change at the time: "+ str (osstst (local_file) .st_atime) ftp.ncbi.nih to connect print". Gov ... "F = ftplib.FTP ('ftp.ncbi.nih.gov') f.login () f.cwd ('/ Genome / Bacteria / ') directory = [] dirs = f.nlst (); Print "Connected and retrieve der list." Target_bug = "Streptococcus_pusdaniomoni" Print "Search for:" + target_bug ct = 0; Target_dir = "test /" for items in Direct: if item.find (target_bug) & gt; -1: To create print item #dir, if not print os.path.isdir (os.path.join (Target_dir, item)) "Dir not found ... making it ..." Omescadors ( os.path.join (Target_dir, item)) # GBK get # 1 dir f.cwd (items) Change # 2 * DIR files for files in get .gbk files file = F.anelel ( '*. GBK '): Print "----------------------------- --------------- - "local_file = os.path.join (Target_dir, item, fi) if os.path.isfile (local_file): print" ############### "Print" file "+ Local_file + "already exists Is. "#get to change the remote modified MT = F Sandsimdi ( 'Mditim' + fi) # timestamp NT = Daytime Taimstritaim (MT [4:],"% Y% m% d% H% M% S ") . FTP M timestamp: "+ str (nt) #print" Local M Timestamp: "+ str (OS)" ("% S") #print "mtime FTP:" + str (int (mt [4:]) #print .stat (local_file) .st_mtime) #print "Local A Timestamp:" + str (OSSTAT (local_file) .st_atime) If int (NT) == int (OSST (local_file) .st_mtime): Print Fi + "Not Modified" Download dropped new version of "Other: Print" "+ Fi CT + = 1 download and settemstamp (local_file, fi, nt) print" nv local em timestamp: "+ str (osstate (local_fai) ) .st_mtime) Print "NV Local A Timestamp:" + str (OSSTAT (local_file) .st_atime) Print "################" Other: Print "##### #### ####### "print" new file: "+ Fi CT + = 1 mt = Fsandsimdi ( 'Mditim' + fi) # timestamp NT = Dattaim. Uartimm (MT [4],"% Y% M% d% H% M% S "). Strftime ("% s ") DownloadAndSetTimestamp (local_file, fi, nt) print" ################ "Fkyud ( '..') f.quit () print "#" + target_bug + "Found new files and Dow loaded:" + str (ct)     
  You enter  lf.close in parentheses ; It should be  lf.close () .   Without the brackets, you are not effectively shutting down the file, instead of leaving the call after the call after the  os.utime  by the garbage collector. are given. Turning off a file causes the outstanding Io buffer material to fly, the amendment time will be updated as a side effect, which you had already clobbled the value set.   
 
 
 
No comments:
Post a Comment