コード例 #1
0
 def connectionMade(self):
     """after ip is checked, begin connection"""
     PeerProtocol.connectionMade(self)
     # check action to be made
     if self.factory.download.startswith(ASK_DOWNLOAD_FILES):
         if self.factory.files:
             self.setRawMode()
             # TODO: check place where to download and non overwriting
             # create file
             file_path, size = self.factory.files.pop()
             self.factory.manager.update_file(file_path[-1], size)
             down_path = os.path.abspath(os.path.join(
                 get_prefs("download_repo"),
                 file_path[-1]))
             print "loading into", down_path
             self.file = open(down_path, "w+b")
             self.sendLine("%s %s"% (self.factory.download,
                                     UNIVERSAL_SEP.join(file_path)))
         else:
             self.factory.manager._on_all_files()
     elif self.factory.download.startswith(ASK_DOWNLOAD_BLOG)\
              or self.factory.download.startswith(ASK_DOWNLOAD_SHARED):
         self.setRawMode()
         self.file = StringIO()
         self.sendLine(self.factory.download)
     elif self.factory.download.startswith(ASK_DOWNLOAD_PROFILE):
         self.setRawMode()
         self.file = tempfile.NamedTemporaryFile()
         self.sendLine(self.factory.download)
     elif self.factory.download.startswith(ASK_UPLOAD):
         self.file = None
         self.setLineMode()
         self.sendLine(self.factory.download)
     else:
         print "unexpected command %s"% self.factory.download
コード例 #2
0
 def get_message(self):
     """format message to send to client according to file to be
     uploaded"""
     if self.message == MESSAGE_PROFILE:
         self.file = tempfile.NamedTemporaryFile()
         message = ASK_UPLOAD_PROFILE
     elif self.message == MESSAGE_BLOG:
         self.file = StringIO()
         message = ASK_UPLOAD_BLOG
     elif self.message == MESSAGE_SHARED:
         self.file = StringIO()
         message = ASK_UPLOAD_SHARED
     elif self.message == MESSAGE_FILES:
         # TODO: check place where to download and non overwriting
         down_path = os.path.abspath(os.path.join(
             get_prefs().get("download_repo"),
             self.split_path[-1]))
         self.file = open(down_path, "w+b")
         self.manager.download_dlg.update_file(self.split_path, self.size)
         message = "%s %s"% (ASK_UPLOAD_FILES,
                             UNIVERSAL_SEP.join(self.split_path))
     else:
         print "%s not valid"% self.message
         message = MESSAGE_ERROR
     return message
コード例 #3
0
def format_data_file(split_path, size=0):
    new_path = UNIVERSAL_SEP.join(split_path)
    return "%s,%s"% (size, new_path)