def __RNME(self, data): """ Rename file handler for RNME operation """ if self.__files is None: data = constructDataClient('AUTH', data['user'], data['password'], True, "WARNING: Please, use LIST to get last cashe of your files from server...") else: self.__filenumber = '' lst_file_numbers = [str(number+1) for number, file_fs in enumerate(self.__files)] while self.__filenumber not in lst_file_numbers: self.clear_console() self.print_storage_files() self.__filenumber = self.inputFileNumber() self.__filenumber = int(self.__filenumber) - 1 # get file info (id and original name) file_id = self.__files[self.__filenumber].id file_original_name = self.__files[self.__filenumber].original_name file_format_db = file_original_name.split('.')[-1] new_name = '' # checking entered path by user while new_name == '': self.clear_console() print 'NOTE: file shall be have equals format!' print 'Enter new name for file, which replaced previous name:' new_name = raw_input('New name:') file_format = new_name.split('/')[-1].split('.')[-1] if len(file_format[0]) == 0: new_name = '' if file_format != file_format_db: new_name = '' data = constructDataClient('RNME', data['user'], data['password'], True, file_id=file_id, new_name=new_name) return data
def __LINK(self, data): """ Send request for download file by link """ link = raw_input("Link on file: ") data = constructDataClient('LINK', data['user'], '', True, error='', url=link) return data
def __LIST(self, data): """ Processing for LIST command """ data = constructDataClient('LIST', data['user'], data['password'], True) self.__clearCashe() return data
def __LINK(self, event): """ Send request for download file by link """ dlg = InputLink(self.gui.FileManager, -1, "Enter shared link", self.gui.FileManager.ico_folder) if dlg.ShowModal() == wx.ID_OK: data = constructDataClient('LINK', self.login, '', True, error='', url=dlg.result) self.sendMessage(data)
def __AUTH(self, data): """ Processing for AUTH command """ self.__clearCashe() self.counterAttemptsLogin = 3 login, password = self.inputData() data = constructDataClient('AUTH', login, password, False) return data
def __CRLN(self, data): """ Create link on file """ if self.__files is None: data = constructDataClient('AUTH', data['user'], data['password'], True, "WARNING: Please, use LIST to get last cashe of your files from server...") else: self.__filenumber = '' lst_file_numbers = [str(number+1) for number, file_fs in enumerate(self.__files)] # get file number while self.__filenumber not in lst_file_numbers: self.clear_console() self.print_storage_files() self.__filenumber = self.inputFileNumber() self.__filenumber = int(self.__filenumber) - 1 # prepare data from JSON request file_id = str(self.__files[self.__filenumber].original_name) # get path to file file_path = '' file_format_db = file_id.split('.')[-1] # checking entered path by user while file_path == '': self.clear_console() print 'NOTE: file shall be have equals format!' print 'Enter full path to file, which stored information:' file_path = raw_input('Path:') file_format = file_path.split('/')[-1].split('.')[-1] if len(file_format) == 0: file_path = '' if file_format != file_format_db: file_path = '' if not os.path.exists(file_path): file_path = '' self.clear_console() relative_path = str(self.__files[self.__filenumber].user_path) file_hash, size = md5_for_file(file_path) key = self.__input_password() file_info = (file_id, file_hash, relative_path, key) data = constructDataClient('CRLN', data['user'], '', True, error='', file_info=file_info, description='') return data
def __SYNC(self, data): """ Processing for SYNC command """ if self.__files is None: data = constructDataClient('AUTH', data['user'], data['password'], True, "WARNING: Please, use LIST to get last cashe of your files from server...") else: self.__filenumber = '' lst_file_numbers = [str(number+1) for number, file_fs in enumerate(self.__files)] while self.__filenumber not in lst_file_numbers: self.clear_console() self.print_storage_files() self.__filenumber = self.inputFileNumber() self.__filenumber = int(self.__filenumber) - 1 op_type = 'Unknown' while op_type not in ('WSYNC', 'RSYNC'): self.clear_console() self.print_sync_operations() op_type = raw_input('Command:').upper() op_type += '_FILE' # checking entered path by user file_original_name = self.__files[self.__filenumber].original_name file_format_db = file_original_name.split('.')[-1] file_path_src = '' while file_path_src == '': self.clear_console() print 'NOTE: file shall be have equals format!' print 'Enter path to file, which using to store information' file_path_src = raw_input('Path to %s:' % (file_original_name)) file_format = file_path_src.split('/')[-1].split('.')[-1] if len(file_format[0]) == 0: file_path_src = '' if file_format != file_format_db: file_path_src = '' if not os.path.exists(file_path_src): file_path_src = '' new_hash = md5_for_file(file_path_src) files = [(self.__files[self.__filenumber].original_name, self.__files[self.__filenumber].server_name, self.__files[self.__filenumber].file_hash, new_hash)] data = constructDataClient('SYNC', data['user'], data['password'], True, files_u=files, sync_type=op_type, file_path_src=file_path_src) return data
def __READ(self, data): """ Processing for READ command (read some file from FS) """ if self.__files is None: data = constructDataClient('AUTH', data['user'], data['password'], True, "WARNING: Please, use LIST to get last cashe of your files from server...") else: self.__filenumber = '' lst_file_numbers = [str(number+1) for number, file_fs in enumerate(self.__files)] while self.__filenumber not in lst_file_numbers: self.clear_console() self.print_storage_files() self.__filenumber = self.inputFileNumber() self.__filenumber = int(self.__filenumber) - 1 file_hash = self.__files[self.__filenumber].file_hash data = constructDataClient('READ', data['user'], data['password'], True, file_path='', file_size=0, file_hash=file_hash) return data
def __StartAuth(self, event): """ Event on 'Enter' button, which start auth procedure with server """ self.gui.ClearErrorsLabels() if self.gui.login_input.GetValidator().Validate(self.gui.login_input) and \ self.gui.pass_input.GetValidator().Validate(self.gui.pass_input): self.gui.PreloaderPlay() login = self.gui.login_input.GetValue().strip() password = self.gui.pass_input.GetValue().strip() data = constructDataClient('AUTH', login, password, False) self.sendMessage(data, sync=True)
def __WRTE(self, data): """ Processing for WRTE (write file) command """ file_path = unicode('') while not os.path.isfile(file_path): self.clear_console() print 'Please, enter correct path to your FILE' file_path = unicode(raw_input('Path:')) file_hash, file_size = md5_for_file(file_path) data = constructDataClient('WRTE', data['user'], data['password'], True, file_path=file_path, file_size=file_size, file_hash=file_hash, gui=False) return data
def __RAUT(self, data): """ Processing for RAUTH command """ if self.counterAttemptsLogin > 0: for error in data['error']: print error print 'Attempts left: %d\n' % self.counterAttemptsLogin self.counterAttemptsLogin -= 1 login, password = self.inputData() data = constructDataClient('AUTH', login, password, False) else: print '\nTrying to hacking account or DDoS server? I will stop YOU!' reactor.stop() return data
def __CRLN(self, event): """ Create link on file """ selectedItems = self.gui.FileManager.files_folder.getSelectedItems() if len(selectedItems) != 1: wx.MessageBox("For creating shared link necessary choose file!", "Error") else: key = self.gui.FileManager.options_frame.getCryptoKey() defaultDir = self.gui.FileManager.files_folder.defaultDir currentDir = self.gui.FileManager.files_folder.currentDir path = os.path.normpath(currentDir + selectedItems[0]) if os.path.isfile(path): relative_path = currentDir.replace(defaultDir, "") file_hash, size = md5_for_file(path) file_info = (selectedItems[0], file_hash, relative_path, key) data = constructDataClient('CRLN', self.login, '', True, error='', file_info=file_info, description='') self.sendMessage(data) else: wx.MessageBox("For creating shared link necessary choose file!", "Error")