Ejemplo n.º 1
0
 def defferedDeleteFile(user_id, cmd, name, path, file_id, servers):
     for server in servers:
         server_ip = str(server[0])
         server_port = str(server[1])
         src_file = os.path.normpath(path + '/' + name)
         json_file = os.path.normpath(tmp_dir + '/fsc_' + self.login + '_' + name + '_' + str(randint(0, 100000)) + '.json')
         dumpConfigToJSON(json_file, cmd, user_id, file_id, src_file, key)
         self.__SendInfoToFileServer(json_file, server_ip, server_port)
         try:
             if (os.path.exists(src_file) and os.path.isfile(src_file)):
                 os.remove(src_file)
             if (os.path.exists(path) and os.path.isdir(path)):
                 root_dir = self.gui.FileManager.files_folder.defaultDir
                 fileInFolder = len(os.walk(path).next()[2])
                 if fileInFolder == 0:
                     for root, dirs, files in os.walk(path):
                         for name in dirs:
                             path_to_folder = os.path.join(root, name)
                             if len(os.walk(path_to_folder).next()[2]) == 0:
                                 if os.path.exists(path_to_folder):
                                     shutil.rmtree(path_to_folder)
                         if root != root_dir:
                             parentDir = self.gui.FileManager.files_folder.getParentDir(root)
                             if self.gui.FileManager.files_folder.currentDir == root:
                                 self.gui.FileManager.files_folder.currentDir = parentDir
                             os.chdir(parentDir)
                             if os.path.exists(root) and len(os.walk(root).next()[2]) == 0:
                                 shutil.rmtree(root)
         except IOError:
             pass
         except OSError:
             pass
         evt = UpdateFileListCtrlEvent()
         wx.PostEvent(self.gui, evt)
Ejemplo n.º 2
0
    def __CLNK(self, data):
        """
            Downloading file by link from another file storage
        """
        tmp_dir = os.curdir
        file_info = data.get('file_info', None)
        if file_info:
            file_id, filename, key, server = file_info
            if file_id and filename and key and server:
                file_path = ''
                while file_path == '':
                    self.clear_console()
                    print 'NOTE: file shall be have equals format!'
                    print 'Enter full path to folder, which will be store information:'
                    file_path = raw_input('Path:')
                    if not os.path.isdir(file_path):
                        file_path = ''
                    self.clear_console()

                src_file = os.path.normpath(file_path + '/' + filename)
                server_ip = str(server[0][0])
                server_port = str(server[0][1])
                json_file = os.path.normpath(tmp_dir + '/fsc_link_' + data['user_id'] + '_' + filename + '_' + str(randint(0, 100000)) + '.json')
                dumpConfigToJSON(json_file, "READU_FILE", data['user_id'], file_id, src_file, key)
                self.__SendInfoToFileServer(json_file, server_ip, server_port)
                print "Downloading file by link has complete..."
            else:
                print "ERROR: Link is broken or file has deteled!"
            del data['user_id']
            del data['file_info']
        else:
            print "ERROR: Link is broken or file has deteled!"
        raw_input('Press "Enter" key to continue...')
        return data
Ejemplo n.º 3
0
 def defferedDownloadByLink(user_id, save_in, filename, file_id, key, server):
     src_file = os.path.normpath(save_in + '/' + filename)
     server_ip = str(server[0][0])
     server_port = str(server[0][1])
     json_file = os.path.normpath(tmp_dir + '/fsc_link_' + self.login + '_' + filename + '_' + str(randint(0, 100000)) + '.json')
     dumpConfigToJSON(json_file, "READU_FILE", user_id, file_id, src_file, key)
     self.__SendInfoToFileServer(json_file, server_ip, server_port)
     wx.MessageBox("File downloading {0} has completed!".format(filename), "Message")
Ejemplo n.º 4
0
 def defferedWriteFile(user_id, cmd, name, path, file_id, servers):
     for server in servers:
         server_ip = str(server[0])
         server_port = str(server[1])
         src_file = os.path.normpath(path + '/' + name)
         json_file = os.path.normpath(tmp_dir + '/fsc_' + self.login + '_' + name + '_' + str(randint(0, 100000)) + '.json')
         dumpConfigToJSON(json_file, cmd, user_id, file_id, src_file, key, algorithm)
         self.__SendInfoToFileServer(json_file, server_ip, server_port)
Ejemplo n.º 5
0
 def defferedReadFile(user_id, name, path, file_id, servers):
     new_folders = os.path.normpath(user_folder + '/' + path)
     try:
         os.makedirs(new_folders)
     except OSError:
         pass
     for ip, port in servers:
         src_file = os.path.normpath(user_folder + '/' + path + '/' + name)
         server_ip = str(ip)
         server_port = str(port)
         json_file = os.path.normpath(tmp_dir + '/fsc_' + self.login + '_' + name + '_' + str(randint(0, 100000)) + '.json')
         dumpConfigToJSON(json_file, "READU_FILE", user_id, file_id, src_file, key, algorithm)
         self.__SendInfoToFileServer(json_file, server_ip, server_port)
         evt = UpdateFileListCtrlEvent()
         wx.PostEvent(self.gui, evt)