def clearLogPushButtonPressed(self, button): f = Open(self.log_file, 'w') f.close() self.text = 'Log File:\n' self.text_edit.clear() self.text_edit.insertPlainText(self.text)
def afterCheckBoxToggled(self, checkBoxes): if self.after_checkBox.isChecked() == True: self.after_frame.setEnabled(True) else: self.after_frame.setEnabled(False) shutdown_file = os.path.join(persepolis_tmp, 'shutdown', self.gid) f = Open(shutdown_file, 'w') f.writelines('canceled') f.close()
def refreshLogPushButtonPressed(self, button): f = Open(self.log_file, 'r') f_lines = f.readlines() f.close() self.text = 'Log File:\n' for line in f_lines: self.text = self.text + str(line) + '\n' self.text_edit.clear() self.text_edit.insertPlainText(self.text)
def shutDown(gid, password=None): shutdown_notification_file = os.path.join(persepolis_tmp, 'shutdown', gid) f = Open(shutdown_notification_file, 'w') f.writelines('wait') f.close() shutdown_notification = "wait" while shutdown_notification == "wait": sleep(1) f = Open(shutdown_notification_file, 'r') shutdown_notification_file_lines = f.readlines() f.close() shutdown_notification = str( shutdown_notification_file_lines[0].strip()) osCommands.remove(shutdown_notification_file) if shutdown_notification == "shutdown": print("shutdown in 20 seconds") logger.sendToLog("Shutting down in 20 seconds", "INFO") sleep(20) if os_type == 'Linux': os.system('echo "' + password + '" |sudo -S poweroff') elif os_type == 'Darwin': os.system('echo "' + password + '" |sudo -S shutdown -h now ') elif os_type == 'Windows': CREATE_NO_WINDOW = 0x08000000 subprocess.Popen(['shutdown', '-S'], shell=False, creationflags=CREATE_NO_WINDOW) elif os_type == 'FreeBSD' or os_type == 'OpenBSD': os.system('echo "' + password + '" |sudo -S shutdown -p now ')
def __init__(self, persepolis_setting): super().__init__(persepolis_setting) self.persepolis_setting = persepolis_setting self.copy_log_pushButton.setEnabled(False) # log file address self.log_file = os.path.join(str(config_folder), 'persepolisdm.log') f = Open(self.log_file, 'r') f_lines = f.readlines() f.close() self.text = 'Log File:\n' for line in f_lines: self.text = self.text + str(line) + '\n' self.text_edit.insertPlainText(self.text) self.text_edit.copyAvailable.connect(self.copyAvailableSignalHandler) self.copy_log_pushButton.clicked.connect(self.copyPushButtonPressed) self.report_pushButton.clicked.connect(self.reportPushButtonPressed) self.close_pushButton.clicked.connect(self.closePushButtonPressed) self.refresh_log_pushButton.clicked.connect( self.refreshLogPushButtonPressed) self.clear_log_pushButton.clicked.connect( self.clearLogPushButtonPressed) # setting window size and position size = self.persepolis_setting.value('LogWindow/size', QSize(720, 300)) position = self.persepolis_setting.value('LogWindow/position', QPoint(300, 300)) self.resize(size) self.move(position) self.minimum_height = self.height()
def queueChanged(self, combo): if str(self.add_queue_comboBox.currentText()) == 'Create new queue': new_queue = self.parent.createQueue(combo) if new_queue != None: # clearing comboBox self.add_queue_comboBox.clear() # loading queue list again! f_queues_list = Open(queues_list_file) queues_list_file_lines = f_queues_list.readlines() f_queues_list.close() for queue in queues_list_file_lines: queue_strip = queue.strip() self.add_queue_comboBox.addItem(str(queue_strip)) self.add_queue_comboBox.addItem('Single Downloads') self.add_queue_comboBox.addItem( QIcon(icons + 'add_queue'), 'Create new queue') # finding index of new_queue and setting comboBox for it index = self.add_queue_comboBox.findText(str(new_queue)) self.add_queue_comboBox.setCurrentIndex(index) else: self.add_queue_comboBox.setCurrentIndex(0)
def __init__(self, parent, flashgot_lines, callback, persepolis_setting): super().__init__(persepolis_setting) self.persepolis_setting = persepolis_setting self.callback = callback self.parent = parent self.flashgot_lines = flashgot_lines global icons icons = ':/' + \ str(self.persepolis_setting.value('settings/icons')) + '/' self.flashgot_lines.reverse() k = 1 for i in range(len(self.flashgot_lines)): flashgot_add_link_dictionary_str = flashgot_lines[i].strip() flashgot_add_link_dictionary = ast.literal_eval( flashgot_add_link_dictionary_str) # adding row to links_table self.links_table.insertRow(0) # file_name if 'out' in flashgot_add_link_dictionary: file_name = str(flashgot_add_link_dictionary['out']) else: file_name = '***' # spider is finding file name new_spider = QueueSpiderThread(flashgot_add_link_dictionary) self.parent.threadPool.append(new_spider) self.parent.threadPool[len(self.parent.threadPool) - 1].start() self.parent.threadPool[len(self.parent.threadPool) - 1].QUEUESPIDERRETURNEDFILENAME.connect( partial(self.parent.queueSpiderCallBack, child=self, row_number=len(self.flashgot_lines) - k)) k = k + 1 item = QTableWidgetItem(file_name) # adding checkbox to the item item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) item.setCheckState(QtCore.Qt.Checked) # inserting file_name self.links_table.setItem(0, 0, item) # finding link link = str(flashgot_add_link_dictionary['link']) item = QTableWidgetItem(str(link)) # inserting link self.links_table.setItem(0, 1, item) # inserting add_link_dictionary item = QTableWidgetItem(flashgot_add_link_dictionary_str) self.links_table.setItem(0, 2, item) # finding queues name and adding them to add_queue_comboBox f_queues_list = Open(queues_list_file) queues_list_file_lines = f_queues_list.readlines() f_queues_list.close() for queue in queues_list_file_lines: queue_strip = queue.strip() self.add_queue_comboBox.addItem(str(queue_strip)) self.add_queue_comboBox.addItem('Single Downloads') self.add_queue_comboBox.addItem( QIcon(icons + 'add_queue'), 'Create new queue') # entry initialization global connections connections = int( self.persepolis_setting.value('settings/connections')) global download_path download_path = str( self.persepolis_setting.value('settings/download_path')) # initialization self.connections_spinBox.setValue(connections) self.download_folder_lineEdit.setText(download_path) self.download_folder_lineEdit.setEnabled(False) # ip_lineEdit initialization settings_ip = self.persepolis_setting.value( 'add_link_initialization/ip', None) if settings_ip: self.ip_lineEdit.setText(str(settings_ip)) # proxy user lineEdit initialization settings_proxy_user = self.persepolis_setting.value( 'add_link_initialization/proxy_user', None) if settings_proxy_user: self.proxy_user_lineEdit.setText(str(settings_proxy_user)) # port_spinBox initialization settings_port = self.persepolis_setting.value( 'add_link_initialization/port', 0) self.port_spinBox.setValue(int(int(settings_port))) # download UserName initialization settings_download_user = self.persepolis_setting.value( 'add_link_initialization/download_user', None) if settings_download_user: self.download_user_lineEdit.setText(str(settings_download_user)) # connect folder_pushButton self.folder_pushButton.clicked.connect(self.changeFolder) # connect OK and canel button self.cancel_pushButton.clicked.connect(self.close) self.ok_pushButton.clicked.connect(self.okButtonPressed) # connect select_all_pushButton deselect_all_pushButton self.select_all_pushButton.clicked.connect(self.selectAll) self.deselect_all_pushButton.clicked.connect(self.deselectAll) #frames and checkBoxes self.proxy_frame.setEnabled(False) self.proxy_checkBox.toggled.connect(self.proxyFrame) self.download_frame.setEnabled(False) self.download_checkBox.toggled.connect(self.downloadFrame) self.limit_frame.setEnabled(False) self.limit_checkBox.toggled.connect(self.limitFrame) # set focus to ok button self.ok_pushButton.setFocus() # add_queue_comboBox event self.add_queue_comboBox.currentIndexChanged.connect(self.queueChanged) # setting window size and position size = self.persepolis_setting.value('TextQueue/size', QSize(700, 500)) position = self.persepolis_setting.value( 'TextQueue/position', QPoint(300, 300)) self.resize(size) self.move(position)
def __init__(self, parent, callback, persepolis_setting, flashgot_add_link_dictionary={}): super().__init__(persepolis_setting) self.callback = callback self.flashgot_add_link_dictionary = flashgot_add_link_dictionary self.persepolis_setting = persepolis_setting self.parent = parent # entry initialization -> global connections connections = int( self.persepolis_setting.value('settings/connections')) global download_path download_path = str( self.persepolis_setting.value('settings/download_path')) # initialization -> self.connections_spinBox.setValue(connections) self.download_folder_lineEdit.setText(download_path) self.download_folder_lineEdit.setEnabled(False) self.ok_pushButton.setEnabled(False) self.download_later_pushButton.setEnabled(False) self.link_lineEdit.textChanged.connect(self.linkLineChanged) self.options_pushButton.clicked.connect(self.optionsButtonClicked) # AddLink - checking clipboard for link! -> if ('link' in self.flashgot_add_link_dictionary): self.link_lineEdit.setText( str(self.flashgot_add_link_dictionary['link'])) # spider is finding file size new_spider = AddLinkSpiderThread(self.flashgot_add_link_dictionary) self.parent.threadPool.append(new_spider) self.parent.threadPool[len(self.parent.threadPool) - 1].start() self.parent.threadPool[len(self.parent.threadPool) - 1].ADDLINKSPIDERSIGNAL.connect( partial( self.parent.addLinkSpiderCallBack, child=self)) else: clipboard = QApplication.clipboard() text = clipboard.text() if (("tp:/" in text[2:6]) or ("tps:/" in text[2:7])): self.link_lineEdit.setText(str(text)) # ip_lineEdit initialization -> settings_ip = self.persepolis_setting.value( 'add_link_initialization/ip', None) if (settings_ip): self.ip_lineEdit.setText(str(settings_ip)) # proxy user lineEdit initialization -> settings_proxy_user = self.persepolis_setting.value( 'add_link_initialization/proxy_user', None) if (settings_proxy_user): self.proxy_user_lineEdit.setText(str(settings_proxy_user)) # port_spinBox initialization -> settings_port = self.persepolis_setting.value( 'add_link_initialization/port', 0) self.port_spinBox.setValue(int(int(settings_port))) # download UserName initialization -> settings_download_user = self.persepolis_setting.value( 'add_link_initialization/download_user', None) if (settings_download_user): self.download_user_lineEdit.setText(str(settings_download_user)) # finding queues name and adding them to add_queue_comboBox -> self.add_queue_comboBox.addItem('Single Downloads') f_queues_list = Open(queues_list_file) queues_list_file_lines = f_queues_list.readlines() f_queues_list.close() for queue in queues_list_file_lines: queue_strip = queue.strip() self.add_queue_comboBox.addItem(str(queue_strip)) self.add_queue_comboBox.setCurrentIndex(0) # add_queue_comboBox event self.add_queue_comboBox.currentIndexChanged.connect(self.queueChanged) # connect folder_pushButton self.folder_pushButton.clicked.connect(self.changeFolder) # connect OK and canel download_later button -> self.cancel_pushButton.clicked.connect(self.close) self.ok_pushButton.clicked.connect( functools.partial(self.okButtonPressed, download_later='no')) self.download_later_pushButton.clicked.connect( functools.partial(self.okButtonPressed, download_later='yes')) # frames and checkBoxes -> self.proxy_frame.setEnabled(False) self.proxy_checkBox.toggled.connect(self.proxyFrame) self.download_frame.setEnabled(False) self.download_checkBox.toggled.connect(self.downloadFrame) self.limit_frame.setEnabled(False) self.limit_checkBox.toggled.connect(self.limitFrame) self.start_frame.setEnabled(False) self.start_checkBox.toggled.connect(self.startFrame) self.end_frame.setEnabled(False) self.end_checkBox.toggled.connect(self.endFrame) self.change_name_lineEdit.setEnabled(False) self.change_name_checkBox.toggled.connect(self.changeName) # set focus to ok button self.ok_pushButton.setFocus() # check name of flashgot link -> if ('out' in self.flashgot_add_link_dictionary): self.change_name_lineEdit.setText( str(self.flashgot_add_link_dictionary['out'])) self.change_name_checkBox.setChecked(True) # setting window size and position size = self.persepolis_setting.value('AddLinkWindow/size', QSize(520, 265)) position = self.persepolis_setting.value('AddLinkWindow/position', QPoint(300, 300)) self.resize(size) self.move(position) self.minimum_height = self.height() # more options widgets list self.more_options_widgets = [ self.proxy_checkBox, self.proxy_frame, self.download_checkBox, self.download_frame, self.folder_frame, self.start_checkBox, self.start_frame, self.end_checkBox, self.end_frame, self.limit_checkBox, self.limit_frame, self.connections_frame ] #hiding more_options_widgets for widgets in self.more_options_widgets: widgets.hide()
def browserIntegration(browser): # for GNU/Linux if os_type == 'Linux': # find Persepolis execution path # persepolis execution path exec_path = os.path.join(config_folder, 'persepolis_run_shell') # Native Messaging Hosts folder path for every browser if browser == 'chromium': native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts' elif browser == 'chrome': native_message_folder = home_address + \ '/.config/google-chrome/NativeMessagingHosts' elif browser == 'firefox': native_message_folder = home_address + \ '/.mozilla/native-messaging-hosts' elif browser == 'vivaldi': native_message_folder = home_address + \ '/.config/vivaldi/NativeMessagingHosts' elif browser == 'opera': native_message_folder = home_address + \ '/.config/opera/NativeMessagingHosts' # for FreeBSD and OpenBSD elif os_type == 'FreeBSD' or os_type == 'OpenBSD': # find Persepolis execution path # persepolis execution path exec_path = os.path.join(config_folder, 'persepolis_run_shell') # Native Messaging Hosts folder path for every browser if browser == 'chromium': native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts' elif browser == 'chrome': native_message_folder = home_address + \ '/.config/google-chrome/NativeMessagingHosts' elif browser == 'firefox': native_message_folder = home_address + \ '/.mozilla/native-messaging-hosts' elif browser == 'vivaldi': native_message_folder = home_address + \ '/.config/vivaldi/NativeMessagingHosts' elif browser == 'opera': native_message_folder = home_address + \ '/.config/opera/NativeMessagingHosts' # for Mac OSX elif os_type == 'Darwin': # find Persepolis execution path # persepolis execution path exec_path = os.path.join(config_folder, 'persepolis_run_shell') # Native Messaging Hosts folder path for every browser if browser == 'chromium': native_message_folder = home_address + \ '/Library/Application Support/Chromium/NativeMessagingHosts' elif browser == 'chrome': native_message_folder = home_address + \ '/Library/Application Support/Google/Chrome/NativeMessagingHosts' elif browser == 'firefox': native_message_folder = home_address + \ '/Library/Application Support/Mozilla/NativeMessagingHosts' elif browser == 'vivaldi': native_message_folder = home_address + \ '/Library/Application Support/Vivaldi/NativeMessagingHosts' elif browser == 'opera': native_message_folder = home_address + \ '/Library/Application Support/Opera/NativeMessagingHosts/' # for MicroSoft Windows os (windows 7 , ...) elif os_type == 'Windows': # finding Persepolis execution path cwd = sys.argv[0] current_directory = os.path.dirname(cwd) exec_path = os.path.join(current_directory, 'Persepolis Download Manager.exe') # the execution path in jason file for Windows must in form of # c:\\Users\\...\\Persepolis Download Manager.exe , so we need 2 # "\" in address exec_path = exec_path.replace('\\', r'\\') if browser in ['chrome', 'chromium', 'opera', 'vivaldi']: native_message_folder = os.path.join( home_address, 'AppData\Local\persepolis_download_manager', 'chrome') else: native_message_folder = os.path.join( home_address, 'AppData\Local\persepolis_download_manager', 'firefox') # WebExtension native hosts file prototype webextension_json_connector = { "name": "com.persepolis.pdmchromewrapper", "type": "stdio", "path": str(exec_path), "description": "Integrate Persepolis with %s using WebExtensions" % (browser) } # Add chrom* keys if browser in ['chrome', 'chromium', 'opera', 'vivaldi']: webextension_json_connector["allowed_origins"] = [ "chrome-extension://legimlagjjoghkoedakdjhocbeomojao/" ] # Add firefox keys elif browser == 'firefox': webextension_json_connector["allowed_extensions"] = [ "*****@*****.**", "*****@*****.**" ] # Build final path native_message_file = os.path.join(native_message_folder, 'com.persepolis.pdmchromewrapper.json') osCommands.makeDirs(native_message_folder) # Write NMH file f = open(native_message_file, 'w') f.write(str(webextension_json_connector).replace("'", "\"")) f.close() if os_type != 'Windows': os.system('chmod +x \"' + str(native_message_file) + '\"') else: import winreg # add the key to the windows registry if browser in ['chrome', 'chromium', 'opera', 'vivaldi']: try: # create pdmchromewrapper key under NativeMessagingHosts winreg.CreateKey( winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper" ) # open a connection to pdmchromewrapper key gintKey = winreg.OpenKey( winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS) # set native_message_file as key value winreg.SetValueEx(gintKey, '', 0, winreg.REG_SZ, native_message_file) # close connection to pdmchromewrapper winreg.CloseKey(gintKey) return True except WindowsError: return False elif browser == 'firefox': try: # create pdmchromewrapper key under NativeMessagingHosts for firefox winreg.CreateKey( winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper" ) # open a connection to pdmchromewrapper key for firefox fintKey = winreg.OpenKey( winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS) # set native_message_file as key value winreg.SetValueEx(fintKey, '', 0, winreg.REG_SZ, native_message_file) # close connection to pdmchromewrapper winreg.CloseKey(fintKey) return True except WindowsError: return False # create persepolis_run_shell file for gnu/linux and BSD and Mac # firefox and chromium and ... call persepolis with Native Messaging system. # json file calls persepolis_run_shell file. if os_type == 'Linux' or os_type == 'OpenBSD' or os_type == 'FreeBSD' or os_type == 'Darwin': # find available shell shell_list = [ '/bin/bash', '/usr/local/bin/bash', '/bin/sh', '/usr/local/bin/sh', '/bin/ksh', '/bin/tcsh' ] for shell in shell_list: if os.path.isfile(shell): # define shebang shebang = '#!' + shell break if os_type == 'Darwin': # finding Persepolis execution path cwd = sys.argv[0] current_directory = os.path.dirname(cwd) persepolis_path = os.path.join(current_directory, 'Persepolis Download Manager') else: persepolis_path = 'persepolis' persepolis_run_shell_contents = shebang + '\n' + '"' + persepolis_path + '" "$@"' f = Open(exec_path, 'w') f.writelines(persepolis_run_shell_contents) f.close() # make persepolis_run_shell executable os.system('chmod +x \"' + exec_path + '\"')
def __init__(self, callback, gid, persepolis_setting): super().__init__(persepolis_setting) self.persepolis_setting = persepolis_setting self.download_later_pushButton.hide( ) # hiding download_later_pushButton self.change_name_checkBox.hide() # hiding change_name_checkBox self.change_name_lineEdit.hide() # hiding change_name_lineEdit self.callback = callback self.gid = gid global connections connections = int( self.persepolis_setting.value('settings/connections')) # hiding options_pushButton self.options_pushButton.hide() # detect_proxy_pushButton self.detect_proxy_pushButton.clicked.connect(self.detectProxy) # connect folder_pushButton self.folder_pushButton.clicked.connect(self.changeFolder) self.download_folder_lineEdit.setEnabled(False) self.ok_pushButton.setEnabled(False) self.link_lineEdit.textChanged.connect(self.linkLineChanged) # connect OK and canel button self.cancel_pushButton.clicked.connect(self.close) self.ok_pushButton.clicked.connect(self.okButtonPressed) #frames and checkBoxes self.proxy_frame.setEnabled(False) self.proxy_checkBox.toggled.connect(self.proxyFrame) self.download_frame.setEnabled(False) self.download_checkBox.toggled.connect(self.downloadFrame) self.limit_frame.setEnabled(False) self.limit_checkBox.toggled.connect(self.limitFrame) self.start_frame.setEnabled(False) self.start_checkBox.toggled.connect(self.startFrame) self.end_frame.setEnabled(False) self.end_checkBox.toggled.connect(self.endFrame) # initialization self.connections_spinBox.setValue(connections) download_info_file = download_info_folder + "/" + self.gid download_info_file_list = readList(download_info_file) self.add_link_dictionary = download_info_file_list[9] # disable folder_frame when download is complete status = download_info_file_list[1] if status == 'complete': self.folder_frame.setEnabled(False) # link self.link_lineEdit.setText(self.add_link_dictionary['link']) # ip_lineEdit initialization if self.add_link_dictionary['ip'] != None: self.proxy_checkBox.setChecked(True) self.ip_lineEdit.setText(self.add_link_dictionary['ip']) # port_spinBox initialization try: self.port_spinBox.setValue( int(self.add_link_dictionary['port'])) except: pass # proxy user lineEdit initialization try: self.proxy_user_lineEdit.setText( self.add_link_dictionary['proxy_user']) except: pass # proxy pass lineEdit initialization try: self.proxy_pass_lineEdit.setText( self.add_link_dictionary['proxy_passwd']) except: pass # download UserName initialization if self.add_link_dictionary['download_user'] != None: self.download_checkBox.setChecked(True) self.download_user_lineEdit.setText( self.add_link_dictionary['download_user']) # download PassWord initialization try: self.download_pass_lineEdit.setText( self.add_link_dictionary['download_passwd']) except: pass # folder_path try: self.download_folder_lineEdit.setText( self.add_link_dictionary['download_path']) except: pass # connections try: self.connections_spinBox.setValue( int(self.add_link_dictionary['connections'])) except: pass # finding categories name and adding them to add_queue_comboBox self.add_queue_comboBox.addItem('Single Downloads') f_queues_list = Open(queues_list_file) queues_list_file_lines = f_queues_list.readlines() f_queues_list.close() for queue in queues_list_file_lines: queue_strip = queue.strip() self.add_queue_comboBox.addItem(str(queue_strip)) # finding current queue and setting it! self.current_category = str(download_info_file_list[12]) current_category_index = self.add_queue_comboBox.findText( self.current_category) self.add_queue_comboBox.setCurrentIndex(current_category_index) # add_queue_comboBox event self.add_queue_comboBox.currentIndexChanged.connect(self.queueChanged) # limit speed limit = str(self.add_link_dictionary['limit']) if limit != '0': self.limit_checkBox.setChecked(True) limit_number = limit[0:-1] limit_unit = limit[-1] self.limit_spinBox.setValue(float(limit_number)) if limit_unit == "K": self.limit_comboBox.setCurrentIndex(0) else: self.limit_comboBox.setCurrentIndex(1) # start_time if self.add_link_dictionary['start_hour'] != None: self.start_checkBox.setChecked(True) self.start_hour_spinBox.setValue( int(self.add_link_dictionary['start_hour'])) self.start_minute_spinBox.setValue( int(self.add_link_dictionary['start_minute'])) # end_time if self.add_link_dictionary['end_hour'] != None: self.end_checkBox.setChecked(True) self.end_hour_spinBox.setValue( int(self.add_link_dictionary['end_hour'])) self.end_minute_spinBox.setValue( int(self.add_link_dictionary['end_minute'])) # setting window size and position size = self.persepolis_setting.value('PropertiesWindow/size', QSize(700, 500)) position = self.persepolis_setting.value('PropertiesWindow/position', QPoint(300, 300)) self.resize(size) self.move(position)
def okButtonPressed(self, button): if self.proxy_checkBox.isChecked() == False: ip = None port = None proxy_user = None proxy_passwd = None else: ip = self.ip_lineEdit.text() if not (ip): ip = None port = str(self.port_spinBox.value()) if not (port): port = None proxy_user = self.proxy_user_lineEdit.text() if not (proxy_user): proxy_user = None proxy_passwd = self.proxy_pass_lineEdit.text() if not (proxy_passwd): proxy_passwd = None if self.download_checkBox.isChecked() == False: download_user = None download_passwd = None else: download_user = self.download_user_lineEdit.text() if not (download_user): download_user = None download_passwd = self.download_pass_lineEdit.text() if not (download_passwd): download_passwd = None if self.limit_checkBox.isChecked() == False: limit = 0 else: if self.limit_comboBox.currentText() == "KB/S": limit = str(self.limit_spinBox.value()) + str("K") else: limit = str(self.limit_spinBox.value()) + str("M") if self.start_checkBox.isChecked() == False: start_hour = None start_minute = None else: start_hour = str(self.start_hour_spinBox.value()) start_minute = str(self.start_minute_spinBox.value()) if self.end_checkBox.isChecked() == False: end_hour = None end_minute = None else: end_hour = str(self.end_hour_spinBox.value()) end_minute = str(self.end_minute_spinBox.value()) link = self.link_lineEdit.text() connections = self.connections_spinBox.value() download_path = self.download_folder_lineEdit.text() self.add_link_dictionary['start_hour'] = start_hour self.add_link_dictionary['start_minute'] = start_minute self.add_link_dictionary['end_hour'] = end_hour self.add_link_dictionary['end_minute'] = end_minute self.add_link_dictionary['link'] = link self.add_link_dictionary['ip'] = ip self.add_link_dictionary['port'] = port self.add_link_dictionary['proxy_user'] = proxy_user self.add_link_dictionary['proxy_passwd'] = proxy_passwd self.add_link_dictionary['download_user'] = download_user self.add_link_dictionary['download_passwd'] = download_passwd self.add_link_dictionary['download_path'] = download_path self.add_link_dictionary['limit'] = limit self.add_link_dictionary['connections'] = connections new_category = str(self.add_queue_comboBox.currentText()) if new_category != self.current_category: # it means category changed # first download must eliminated form former category # reading current_category current_category_file = os.path.join(category_folder, self.current_category) f = Open(current_category_file) f_list = f.readlines() f.close() # eliminating gid of download from current_category_file f = Open(current_category_file, 'w') for line in f_list: gid = line.strip() if gid != self.gid: f.writelines(gid + '\n') f.close() # adding download to the new category new_category_file = os.path.join(category_folder, str(new_category)) f = Open(new_category_file, 'a') f.writelines(self.gid + '\n') f.close() self.callback(self.add_link_dictionary, self.gid, new_category) self.close()
def compatibility(): if os.path.isdir(download_info_folder) == True: f = Open(download_list_file) download_list_file_lines = f.readlines() f.close() for line in download_list_file_lines: gid = line.strip() download_info_file = download_info_folder + "/" + gid f_download_info_file = Open(download_info_file) download_info_file_lines = f_download_info_file.readlines() f_download_info_file.close() if len(download_info_file_lines) == 10: list = [] for i in range(10): line_strip = download_info_file_lines[i].strip() if i == 9: line_strip = ast.literal_eval(line_strip) list.append(line_strip) dictionary = {'list': list} os.system('echo "' + str(dictionary) + '" > "' + str(download_info_file) + '"') f_download_info_file = Open(download_info_file, 'w') f_download_info_file.writelines(str(dictionary)) f_download_info_file.close() # compatibility between version 2.2 and version 2.3 date_list = [] for i in ['%Y', '%m', '%d', '%H', '%M', '%S']: date_list.append(time.strftime(i)) for line in download_list_file_lines: gid = line.strip() download_info_file = download_info_folder + "/" + gid f = Open(download_info_file, 'r') f_string = f.readline() f.close() dictionary = ast.literal_eval(f_string.strip()) list = dictionary['list'] if len(list) == 10: add_link_dictionary = list[9] add_link_dictionary['firs_try_date'] = date_list add_link_dictionary['last_try_date'] = date_list list[9] = add_link_dictionary try_date = str(date_list[0]) + '/' + str( date_list[1]) + '/' + str(date_list[2]) + ' , ' + str( date_list[3]) + ':' + str(date_list[4]) + ':' + str( date_list[5]) list.append(try_date) list.append(try_date) list.append('Single Downloads') dictionary = {'list': list} f = Open(download_info_file, 'w') f.writelines(str(dictionary)) f.close() print(str(dictionary)) f = Open(download_list_file) f_lines = f.readlines() f.close() f = Open(single_downloads_list_file, 'w') for line in f_lines: f.writelines(line) f.close() elif len(list) == 12: list.append('Single Downloads') dictionary = {'list': list} f = Open(download_info_file, 'w') f.writelines(str(dictionary)) f.close() f = Open(download_list_file) f_lines = f.readlines() f.close() f = Open(single_downloads_list_file, 'w') for line in f_lines: gid = line.strip() f.writelines(gid + '\n') f.close()