def double_click(self, item):
     # 双击事件
     where = self.waiting_tasks.currentRow()
     task_id = item.text()[4:12]  # 取出任务号,应该进行修改,防止文本变更时引起程序更改
     # 状态验证
     status_code = data_sqlite.task_list(
         "SELECT status_code FROM task WHERE task_ID='%s'" % task_id)
     print(status_code[0][0], "OK")
     if not status_code[0][0] == 'received':
         QMessageBox.information(self, "提示!", "本任务还没有下载好或者已经处理!")
         return False
     local_path = task_dict[task_id]["local_path"]
     print(WHERE, local_path)
     if CONFIG["os"] == "Windows":
         import bin.my_lib.printer2 as printer
     else:
         print(WHERE, "暂不支持非Windows系统")
         return False
     if printer.print_files(local_path,
                            self.printer_name.currentText()):  # 处理一个任务
         data_sqlite.execute(
             "UPDATE task SET status_code='printing' WHERE task_ID='%s'" %
             task_id)
         self.printed_tasks.addItem(item.text())
     else:
         data_sqlite.execute(
             "UPDATE task SET status_code='warning' WHERE task_ID='%s'" %
             task_id)
     self.waiting_tasks.takeItem(where)
     try:
         url = CONFIG[
             "site"] + "/update_task/?task_ID=%s&status=20" % task_id
         urlopen(url)
     except:
         print(WHERE, "修改任务在服务器的状态为20失败")
 def update_settings(self):
     for i in self.fields.keys():
         value = self.fields[i].text()
         # 执行更新操作
         db.execute("UPDATE KEY_VALUE SET VALUE='%s' WHERE KEY='%s'" %
                    (value, i))
     self.fields['password'].setText('******')
 def recent_printer_changed(self):
     res = data_sqlite.execute(
         "UPDATE KEY_VALUE SET VALUE='%s' WHERE KEY='recent_printer'" %
         self.printer_name.currentText())
     if not res:
         return False
     return True
Пример #4
0
def load_config():
    print(__file__, "当前操作系统--", OS)
    if OS == "Linux":
        home = os.environ['HOME']
        config_path = os.path.join(home, 'printer/config.json')

    elif OS == "Windows":
        config_path = "c:/printer/config.json"
        import win32print
        for printer in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL):
            PRINTER_LIST.append(printer[2])
    else:
        print(__file__, "不支持的平台")
        return False
    # config 是一个字典
    config = {}
    res = db.execute('SELECT * FROM KEY_VALUE')
    if not res:
        return False
    for i in res:
        config[i[0]] = i[1]
    # 并对参数进行检查
    config["os"] = OS
    config["config_path"] = config_path
    return config
 def auto_download_toggle(self):
     if self.auto_download.text() == "开":
         res = db.execute(
             "UPDATE KEY_VALUE SET VALUE='False' WHERE KEY='auto_download_tasks'"
         )
         if not res:
             print(__file__, 'failed to save')
             return False
         self.auto_download.setText('关')
         return True
     else:
         res = db.execute(
             "UPDATE KEY_VALUE SET VALUE='True' WHERE KEY='auto_download_tasks'"
         )
         if not res:
             print(__file__, 'failed to save')
             return False
         self.auto_download.setText('开')
         return True
Пример #6
0
import win32api
import win32print

printer_name = win32print.GetDefaultPrinter()
print("默认打印机", printer_name)
handle_printer = win32print.OpenPrinter(printer_name)  # 获取打印机句柄
printer_info = win32print.GetPrinter(handle_printer, 2)  # 调用相关函数进行信息查询
for k in printer_info:
    print(k, printer_info[k])
task_list = win32print.EnumJobs(handle_printer, 0, 10)  # 参数(句柄,编文档号,枚举条数)
print(task_list)

import bin.my_lib.data_sqlite as db
res = db.execute('SELECT * FROM KEY_VALUE')
print('res:', res)
def get_files():
    tasks = data_sqlite.task_list(
        "SELECT info FROM task "
        "WHERE status_code='server_received' or status_code='receiving'")
    # 状态为receiving的是上次下载出错遗留的任务
    if tasks == []:
        print(WHERE, "没有等待下载的任务", tasks)
    else:
        print(WHERE, "等待下载的任务", tasks)
        for info in tasks:
            info = info[0]
            fragment = info.split("/")
            tel = fragment[-3]
            task_ID = fragment[-2]
            files = fragment[-1].split(",")
            task_path = os.path.join(RECEIVED_PATH, tel, task_ID)
            # 任务号,json文件路径,状态码,返回的info信息
            try:
                # data_sqlite.execute("INSERT INTO task VALUES('%s','%s','receiving','%s')" % (task_ID, task_path, info))
                # cursor.execute("INSERT INTO task VALUES('task_test','path_test','code_test')")
                data_sqlite.execute(
                    "UPDATE task SET status_code='receiving' WHERE task_ID='%s'"
                    % task_ID)
            except:
                # print("insert task ERROR or the task have exist")
                print(WHERE, "修改任务状态为receiving失败")
            # os.makedirs(task_path, 0o777, True)
            try:
                os.makedirs(task_path)
            except:
                print(WHERE, "文件夹已存在")
            for file in files:
                url = file_url(tel, task_ID) + "/" + file
                print(WHERE, url)
                try:
                    with open(os.path.join(task_path, file), "wb") as f:
                        try:
                            file_stream = urlopen(url)
                        except:
                            print(WHERE, "从服务器下载文件失败")
                            return False
                        f.write(file_stream.read())
                except:
                    print(WHERE, "保存文件失败")
                    return False
            '''
            # 修改info.json任务状态
            info_path = os.path.join(task_path, "info.json")
            info = json_read_write.read(info_path)
            if info:
                print(WHERE, "修改info状态成功", info)
                info["user"]["status"] = "received"
                if not json_read_write.write(info_path, info):
                    print(WHERE, "修改info.json任务状态失败")
                    return False
                    '''
            # 读取info.json
            info = json_read_write.read(
                os.path.join(RECEIVED_PATH, tel, task_ID, "info.json"))
            if info:
                print(WHERE, "DEBUG")
                user, name, nick_name, address = '', '', '', ''
                try:
                    user = info['user']
                    name = user['user_name']
                    nick_name = user['nick_name']
                    # nick_name = ''  # 等待服务端info.json文件修改
                    address = user['address']
                    # address = ''
                except:
                    print(WHERE, "info.json文件内容不匹配")
            else:
                print(WHERE, "读取info.json文件失败")
                return False
            # 修改数据库
            if data_sqlite.execute("UPDATE task SET "
                                   "status_code='received',"
                                   "name='%s',"
                                   "nick_name='%s',"
                                   "address='%s'"
                                   " WHERE task_ID='%s'" %
                                   (name, nick_name, address, task_ID)):
                print(WHERE, "修改任务的状态为received成功")
            else:
                print(WHERE, "修改任务的状态为received失败")
                return False