def refresh_tenants(self):
        self.item_root_favourite_tenants.takeChildren()
        self.item_root_all_tenants.takeChildren()
        self.tenants['常用商户'].clear()
        self.tenants['所有商户'].clear()
        if self.kos:
            try:
                curr_env = self.combobox_env.currentText()
                all_tenants = self.kos.root.get_tenants(
                    curr_env, self.session_id, self.token)
                if isinstance(all_tenants, list):
                    # 初始化favourite_tenants
                    favourite_tenants = dict()
                    for tt in localdb.list_favourite_tenants(
                            curr_env, all_tenants):
                        favourite_tenants[tt[0]] = None

                    for t in all_tenants:
                        item_all_tenants = QtWidgets.QTreeWidgetItem()
                        item_all_tenants.setText(
                            0, t['name'][:18] +
                            ('...' if len(t['name']) > 18 else ''))
                        item_all_tenants.setToolTip(0, t['name'])
                        self.item_root_all_tenants.addChild(item_all_tenants)
                        self.tenants['所有商户'].append(Tenant(t['id'], t['name']))
                        # 填充初始化favourite_tenants
                        if t['id'] in favourite_tenants:
                            favourite_tenants[t['id']] = Tenant(
                                t['id'], t['name'])
                    self.item_root_all_tenants.setText(
                        0, '所有商户 ({})'.format(
                            self.item_root_all_tenants.childCount()))

                    for id, t in favourite_tenants.items():
                        item_favourite_tenants = QtWidgets.QTreeWidgetItem()
                        item_favourite_tenants.setText(0, t.name)
                        item_favourite_tenants.setToolTip(0, t.name)
                        self.item_root_favourite_tenants.addChild(
                            item_favourite_tenants)
                        self.tenants['常用商户'].append(t)
                    self.item_root_favourite_tenants.setText(
                        0, '常用商户 ({})'.format(
                            self.item_root_favourite_tenants.childCount()))
                    self.label_message.setVisible(False)  # 成功
                elif all_tenants == -1:
                    # 锁定界面,要求重新登录
                    self.setEnabled(False)
                    self.login_window.show()
                elif all_tenants == 1:
                    # 环境无效,请刷新
                    self.show_message('当前环境无效, 请刷新环境配置后重试!')
                else:
                    # 未知错误
                    self.show_message('未知错误!')
            except Exception as e:
                self.show_message('服务器连接失败!')
                logger.error("{} occured".format(type(e).__name__),
                             exc_info=True)
        else:
            self.show_message('服务器连接失败!')
 def refresh_env(self):
     self.combobox_env.clear()
     if self.kos:
         try:
             enviroments = self.kos.root.get_environments(
                 self.session_id, self.token)
             if isinstance(enviroments, list):
                 localdb.refresh_favourite_tenants(envs=enviroments)
                 self.enviroments.clear()
                 for env in enviroments:
                     self.combobox_env.addItem(env['name'])
                     self.enviroments.append(env['name'])
                 self.combobox_env.addItem('<刷新环境配置......>')
                 self.combobox_env_initiated = True
             elif isinstance(enviroments, tuple) and not enviroments:
                 pass
             else:
                 # 锁定界面,要求重新登录
                 self.setEnabled(False)
                 self.login_window.show()
         except Exception as e:
             self.show_message('服务器连接失败!')
             logger.error("{} occured".format(type(e).__name__),
                          exc_info=True)
     else:
         self.show_message('服务器连接失败!')
Example #3
0
 def login(self, account, pwd):
     if self.kos:
         if not (account and pwd):
             self.label_info.setText('用户名和密码不能为空!')
         else:
             token = None
             try:
                 token, username, role = self.kos.root.login(
                     self.session_id, account, pwd)
             except Exception as e:
                 self.label_info.setText('服务器连接失败!')
                 logger.error("{} occured".format(type(e).__name__),
                              exc_info=True)
                 return
             if token:
                 if token == 'DISABLED':
                     self.label_info.setText('此账户已被禁用!请联系管理员!')
                 else:
                     # 登录成功
                     self.line_edit_passwd.clear()
                     self.hide()
                     if self.window_main:
                         self.window_main.renew_token(token)
                         self.window_main.refresh_env()
                         self.window_main.refresh_user(username, role)
                         self.window_main.setEnabled(True)
                         self.window_main.set_enabled_cascade(True)
                     else:
                         self.window_main = WindowMain(
                             self.session_id, token, self.kos, self,
                             username, role)
                         self.window_main.show()
             else:
                 # 登录失败
                 self.label_info.setText('用户名密码不正确!')
 def close_main(self):
     if self.kos:
         try:
             self.kos.root.logout(self.session_id)
         except Exception as e:
             logger.error("{} occured".format(type(e).__name__),
                          exc_info=True)
     QtWidgets.qApp.quit()
Example #5
0
def test(host, user, passwd, db='mysql'):
    result = 0
    try:
        conn = torch.connect(host, user, passwd, db)
        conn.close()
    except Exception as e:
        result = 1
        logger.error("{} occured".format(type(e).__name__), exc_info=True)
    return result
Example #6
0
def query_with_param(conn, sql, params):
    results = None
    try:
        with conn.cursor(pymysql.cursors.DictCursor) as c:
            c.execute(sql, params)
            results = c.fetchall()
    except Exception as e:
        logger.error("{} occured".format(type(e).__name__), exc_info=True)
    finally:
        conn.close()
    return results
Example #7
0
def update_local_db(sql):
    try:
        conn = connect_local_db()
        c = conn.cursor()
        c.execute(sql)
        conn.commit()
    except Exception as e:
        conn.rollback()
        logger.error("{} occured".format(type(e).__name__), exc_info=True)
    finally:
        conn.close()
Example #8
0
def execute_many(conn, sql, params):
    try:
        with conn.cursor() as c:
            c.executemany(sql, params)
        conn.commit()
        return 0
    except Exception as e:
        conn.rollback()
        logger.error("{} occured".format(type(e).__name__), exc_info=True)
        return 1
    finally:
        conn.close()
Example #9
0
def query_local_db(sql):
    results = None
    try:
        conn = connect_local_db()
        c = conn.cursor()
        c.execute(sql)
        results = c.fetchall()
    except Exception as e:
        logger.error("{} occured".format(type(e).__name__), exc_info=True)
    finally:
        conn.close()
    return results
Example #10
0
def call_proc_with_resultset(conn, sql):
    try:
        with conn.cursor() as c:
            c.execute(sql)
            resultset = c.fetchall()
        conn.commit()
        return 0, resultset
    except Exception as e:
        conn.rollback()
        logger.error("{} occured".format(type(e).__name__), exc_info=True)
        return 1, None
    finally:
        conn.close()
Example #11
0
def execute_list_with_param(conn, list_sql):
    try:
        with conn.cursor() as c:
            for sql, param in list_sql:
                c.execute(sql, param)
        conn.commit()
        return 0
    except Exception as e:
        conn.rollback()
        logger.error("{} occured".format(type(e).__name__), exc_info=True)
        return 1
    finally:
        conn.close()
Example #12
0
def main():
    app = QtWidgets.QApplication(sys.argv)

    # 获取屏幕大小
    screen_resolution = app.desktop().screenGeometry()
    width, height = screen_resolution.width(), screen_resolution.height()

    session_id = str(uuid.uuid4())
    kos = None
    try:
        kos = rpyc.connect("localhost", 18861)
    except Exception as e:
        logger.error("{} occured".format(type(e).__name__), exc_info=True)

    window_login = WindowLogin(session_id, kos, width, height)
    window_login.show()
    sys.exit(app.exec_())
Example #13
0
     thread_reset_option.start()
     thread_reset_option.join(6)  # 等待用户输入(10秒)
     if special == 'Hera':
         while True:
             passwd1 = getpass.getpass('请重置主宰的密令: ')
             passwd2 = getpass.getpass('请再次确认您的密令: ')
             if passwd1 == passwd2:
                 try:
                     dominated_name = torch.reset_hera(
                         host, user, passwd, passwd1
                     )
                     print('主宰{}的密令已重置!'.format(dominated_name))
                 except Exception as e:
                     print('重置过程发生了一些问题...请查阅日志')
                     logger.error(
                         "{} occured".format(type(e).__name__),
                         exc_info=True
                     )
                 finally:
                     break
             else:
                 print('分配的密令似乎有些问题...请重新输入')
     run(host, user, passwd)
 else:
     name = input('请为新世界的主宰命名: ')
     while True:
         passwd1 = getpass.getpass('请分配密令给新世界的主宰: ')
         passwd2 = getpass.getpass('请再次确认您分配的密令: ')
         if passwd1 == passwd2:
             try:
                 torch.set_fire(
                     host, user, passwd, name, passwd1