draft method for getting the last status line
authorAdriana Draghici <adriana008@gmail.com>
Thu, 22 Apr 2010 16:39:34 +0000 (16:39 +0000)
committerAdriana Draghici <adriana008@gmail.com>
Thu, 22 Apr 2010 16:39:40 +0000 (16:39 +0000)
autorun/PROTOCOL
autorun/Util.py
autorun/server/Server.py
ppf/log-parser/generic/GenericStatusParser.py

index e036edc..287c984 100644 (file)
@@ -71,9 +71,17 @@ Serverul pastreaza un fisier cu info despre toate fisierele downloadate:
 
 4. Mesaje STATUS
  - trimise de client pt interogarea starii
- -----> tipul mesajului STATUS_MSG (definit in Util.py)
- -----> 
-
+ -----> (tipul mesajului STATUS_MSG, identificator transfer ) 
+ <----- tuplu (ACK, dictionar cu parametrii transferului )
+ - identificatorul unui transfer reprezinta pid-ul intors de server la 
+    pornirea unui client pt un anumit fisier
+ - parametrii transferului pot fi:
+        - timestamp
+        - nume fisier torrent
+        - upload, download speed
+        - upload, download size
+        - eta
+        - number of peers
 
 
 
index 192123a..36b4476 100644 (file)
@@ -21,7 +21,7 @@ BUFFER_SIZE = 4096
 
 START_MSG = 1
 STOP_MSG = 2
-STATUS_MSG = 3
+GET_STATUS = 3
 GET_CLIENTS = 4
 GET_OUTPUT = 5
 ARCHIVE = 6
index 1681011..4609625 100644 (file)
@@ -291,6 +291,13 @@ class MyDaemon(Daemon):
                 else: # erase sessions file
                     f = open(SESSIONS_FILE, "w")
                     f.close()
+            
+            elif msg[0] == GET_STATUS:
+                #TODO: current ideea: call parse_status_line from GenericStatusParser
+                # create a dictionary from the returned list, its better to use a dictionary 
+                # because it is position independent
+                pass
+            
             else:
                 err_msg = "Error: wrong message type";
 
index c2bfd5e..e9b30ca 100644 (file)
@@ -83,6 +83,19 @@ class GenericStatusParser:
 
         return (num_peers, dht, download_speed, upload_speed, download_size, upload_size, eta)
 
+    def parse_last_status_line(self, filename,line):
+        # read last line from status log file
+        f = open(filename, "r")
+        f.seek(-1, os.SEEK_END)
+
+        # seek before the beginning of the last line
+
+        while f.read(1) != '\n' :
+            f.seek(-2, os.SEEK_CUR)
+        line = f.readline()
+        f.close()
+        return self.parse_status_line(line)
+
     def parse_status_file(self, client_session_id, session_start, filename, callback_func, callback_arg = None):
 
         message_time = session_start