def upload_media(self, sftp): try: name, file_path = self.get_first_row_data() self.start_upload_file_thread(sftp, name, file_path) except Exception as err: message_box(self, 'Error', str(err), QMessageBox.Critical) return False
def upload_done(self): self.remove_first_row() if self.row_count() > 0: self.ui.progress_bar.setValue(0) self.upload() else: # hide progress bar self.ui.progress_bar.hide() self.statusBar().showMessage('') self.ui.delete_button.setDisabled(True) message_box(self, 'OK', 'Upload successfully!', QMessageBox.Information)
def check_add(self): title = self.ui.movie_name_edit.text() if not title: message_box(self, 'Error', 'Movie name is required!', QMessageBox.Critical) return False file_path = self.ui.path_edit.text() if not file_path or not os.path.isfile(file_path): message_box(self, 'Error', 'Media file not found!', QMessageBox.Critical) return False return True
def create_directory(self, sftp): try: title, _ = self.get_first_row_data() if title: title = slugify(title, separator=" ") if not self.directory_exists(sftp, title): # create new directory sftp.connection.mkdir(title) sftp.connection.chdir(title) return True except Exception as err: message_box(self, 'Error', str(err), QMessageBox.Critical) return False
def login(self): host = self.ui.host_text_edit.text() port = int(self.ui.port_text_edit.text()) username = self.ui.username_text_edit.text() password = self.ui.password_text_edit.text() directory = self.ui.directory_text_edit.text() if self.check_login(host, port, username, password): try: sftp = SFTPClient(host, port, username, password, None, 'DSA') sftp.close() self.open_uploader_window(host, port, username, password, directory) return True except Exception as err: message_box(self, 'Error', str(err), QMessageBox.Critical) return False
def upload(self): if self.row_count() > 0: try: # Connect ftp sftp = SFTPClient(self.host, self.port, self.username, self.password, None, 'DSA') if self.directory: sftp.connection.chdir(self.directory) # create directory if not self.create_directory(sftp): return False # upload media self.upload_media(sftp) return True except Exception as err: message_box(self, 'Error', str(err), QMessageBox.Critical) return False
def check_login(self, host, port, username, password): """ :param host: host :param port: port :param username: username :param password: password :return: True or False """ field = '' if not host: field = 'host' elif not port: field = 'port' elif not username: field = 'username' elif not password: field = 'password' if field: message_box(self, 'Error', 'The %s is required' % field, QMessageBox.Critical) return False return True
message_box( title="Filter data", contents=[ html.Form( className='', children=[ html.Div( className='cf mv3', children=[ html.Div( className='', children=[ dcc.Input( id='status-search', placeholder='Search', type='text', className='w-100 pa2'), html. I(className='search icon'), ]), ]), html.Div(className='cf mv3', children=[ html.Label('Licence'), dcc.Dropdown( id='status-licence', multi=True, options=[]), ]), html.Div(className='cf mv3', children=[ html.Label('Currency'), dcc.Dropdown( id='status-currency', multi=True, options=[]), ]), html.Div(className='cf mv3', children=[ html.Label('File type'), dcc.Dropdown( id='status-file-type', multi=True, options=[]), ]), html.Div( className='cf mv3', children=[ html.Label('Last updated'), dcc.Dropdown( id='status-last-modified', options=[ { 'label': 'All publishers', 'value': '__all' }, { 'label': 'In the last month', 'value': 'lastmonth' }, { 'label': 'In the last 6 months', 'value': '6month' }, { 'label': 'In the last year', 'value': '12month' }, ]), ]), html.Div(className='cf mv3', children=[ html.Label('Fields'), dcc.Dropdown( id='status-fields', multi=True, options=[]), ]), ]), ]),