Ejemplo n.º 1
0
    def cancle_task_by_link(self, detail_link):

        find = False
        task_all = self.tree.get_children()
        for item in task_all:
            link = self.tree.item(item, 'values')[0]
            if link == detail_link:
                self.tree.delete(item)
                find = True
                break
        if find:
            chosen_task = self.task_dict[detail_link]
            hash_info = chosen_task.get_hash_info()
            if chosen_task.get_statu() != '发布成功' and hash_info:
                self.qb.delete_permanently(hash_info)
            else:
                return '任务还未开始或已经完成'
            try:
                commen_component.stop_thread(chosen_task)
            except ValueError:
                return '未知错误'
            except SystemError:
                return '未知错误'
            self.task_list.remove(detail_link)
            self.task_dict.pop(detail_link)
            if detail_link in self.onduty_list:
                self.onduty_list.remove(detail_link)

            return '取消成功'
        else:
            return '没找到任务'
Ejemplo n.º 2
0
 def refresh_task(self):
     task_all = self.tree.get_children()
     for item in task_all:
         value_link = self.tree.item(item, 'values')[0]
         value_addtime = self.tree.item(item, 'values')[1]
         value_statu = self.tree.item(item, 'values')[2]
         if value_link in self.task_dict.keys():
             value_statu_now = self.task_dict[value_link].get_statu()
             if not value_statu == value_statu_now:
                 self.tree.item(item,
                                values=(value_link, value_addtime,
                                        value_statu_now))
                 if value_statu_now == '发布成功' or value_statu_now == '任务丢失':
                     try:
                         commen_component.stop_thread(
                             self.task_dict[value_link])
                     except ValueError:
                         pass
                     except SystemError:
                         pass
                     self.onduty_list.remove(value_link)
                     self.task_dict.pop(value_link)
                     if len(self.onduty_list) == 0:
                         try:
                             commen_component.stop_thread(self.refresh_t)
                         except ValueError:
                             pass
                         except SystemError:
                             pass
Ejemplo n.º 3
0
 def reopen_rss(self):
     try:
         commen_component.stop_thread(self.t)
     except ValueError:
         pass
     except SystemError:
         pass
     self.t = threading.Thread(target=self.add_rss_task, args=())
     self.t.start()
     self.is_rss_mode = True
     tk.messagebox.showinfo('提示', 'RSS模式已经重启')
Ejemplo n.º 4
0
 def call_back(self):
     self.frames['AutoUploadPage'].bak_task()
     self.config_dl['server_open'] = False
     self.check_remote_server()
     self.frames['AutoUploadPage'].close_rss()
     try:
         commen_component.stop_thread(self.frames['AutoUploadPage'].refresh_t)
     except ValueError:
         pass
     except SystemError:
         pass
     except Exception:
         pass
     self.destroy()
Ejemplo n.º 5
0
    def bak_task(self):
        self.refresh_task()
        bak_task = []  # 以列表的形式保存未完成的种子
        task_all = self.tree.get_children()
        for item in task_all:
            value_link = self.tree.item(item, 'values')[0]
            value_statu = self.tree.item(item, 'values')[2]
            if value_statu not in ['发布成功', '任务丢失']:
                task = self.task_dict[value_link]
                bak_task.append(task.get_origin_url())
                try:
                    commen_component.stop_thread(task)
                except ValueError:
                    pass
                except SystemError:
                    pass

        with open(USER_BAK_TASK_PATH,
                  "wb") as bak_file:  # with open with语句可以自动关闭资源
            pickle.dump(bak_task, bak_file)
Ejemplo n.º 6
0
    def check_remote_server(self):
        if not self.is_server_open:
            if self.config_dl['server_open']:
                try:
                    ip = self.config_dl['server_ip']
                    port = self.config_dl['server_port']
                    self.t = threading.Thread(target=self.open_server, args=(ip, int(port)))
                    self.t.start()
                    self.is_server_open = True

                    # tk.messagebox.showinfo('提示', '服务器开启成功')
                except Exception as ecx:
                    tk.messagebox.showerror('错误', '服务器模式开启失败%s ' % ecx)
        else:
            if not self.config_dl['server_open']:
                try:
                    commen_component.stop_thread(self.t)
                except ValueError:
                    pass
                except SystemError:
                    pass
                # tk.messagebox.showinfo('提示', '服务器模式已经关闭')
                self.is_server_open = False
Ejemplo n.º 7
0
 def check_rss_mode(self):
     if self.config_dl['rss_open']:
         if not self.is_rss_mode:
             self.t = threading.Thread(target=self.add_rss_task, args=())
             self.t.start()
             self.is_rss_mode = True
             # tk.messagebox.showinfo('提示', 'RSS模式已经开启')
             return 'opened'
         else:
             return 'opened_already'
     else:
         if self.is_rss_mode:
             try:
                 commen_component.stop_thread(self.t)
             except ValueError:
                 pass
             except SystemError:
                 pass
             # tk.messagebox.showinfo('提示', 'RSS模式已经关闭')
             self.is_rss_mode = False
             return 'closed'
         else:
             return 'closed_already'
Ejemplo n.º 8
0
    def delete_task(self):
        if not self.tree.selection():
            tk.messagebox.showerror('抱歉', '你还没有选择,不能删除')
            return
        for item in self.tree.selection():
            detail_link = self.tree.item(item, 'values')[0]
            statu = self.tree.item(item, 'values')[2]
            if statu not in ['发布成功', '任务丢失']:
                chosen_task = self.task_dict[detail_link]

                hash_info = chosen_task.get_hash_info()
                if chosen_task.get_statu() != '发布成功' and hash_info:
                    # 判断有没有下载完
                    torrent = self.qb.get_torrent(infohash=hash_info)
                    if torrent['completion_date'] == -1:
                        self.qb.delete_permanently(hash_info)
                try:
                    commen_component.stop_thread(chosen_task)
                except ValueError:
                    pass
                except SystemError:
                    pass
                self.task_dict.pop(detail_link)
            self.task_list.remove(detail_link)

            if len(self.onduty_list) == 0:
                try:
                    commen_component.stop_thread(self.refresh_t)
                except ValueError:
                    pass
                except SystemError:
                    pass

            if detail_link in self.onduty_list:
                self.onduty_list.remove(detail_link)
            self.tree.delete(item)