Esempio n. 1
0
 def updateFriendList(self, friendDict):
     # 拉取好友头像
     friend = json.loads(friendDict["friend_info"])
     ftp = Ftp()
     ftp.downloadfile("/home/meicorl/ChatServer/" + friend["portrait"],
                      friend["portrait"])
     ftp.quit()
     self.addFriend(friend["name"], friend["signature"], friend["portrait"])
     #  将新添加的好友信息存入本地文件
     file = open("user/" + self.userName.text() + "/friend_list.txt",
                 "a",
                 encoding="UTF-8")
     file.write(json.dumps(friend))
     file.close()
Esempio n. 2
0
 def __InitFriendList(self):
     #   初始化好友列表
     self.list.clear()
     self.friendList.clear()
     friendListPath = "./user/" + self.userName.text() + "/friend_list.txt"
     # 如果本地好友列表丢失,则从服务器拉取好友列表
     if not os.path.exists(friendListPath):
         ftp = Ftp()
         ftp.downloadfile(
             "/home/meicorl/ChatServer/user/" + self.userName.text() +
             "/friend_list.txt", friendListPath)
         ftp.quit()
     if os.path.exists(friendListPath):
         file = open(friendListPath, encoding='UTF-8')
         while 1:
             line = file.readline()
             if not line:
                 break
             friend = json.loads(line)
             self.addFriend(friend["name"], friend["signature"],
                            friend["portrait"])
         file.close()
Esempio n. 3
0
 def __login(self):
     self.__setEnabled(True)
     Room.user_name = self.userName.text()
     FriendWind.user_name = self.userName.text()
     # 更新窗口标题和Icon
     home_path = "user/" + self.userName.text() + "/self_info.txt"
     if not os.path.exists(home_path):
         ftp = Ftp()
         ftp.downloadfile(
             "/home/meicorl/ChatServer/user/" + self.userName.text() +
             "/self_info.txt", home_path)
         ftp.quit()
     file = open(home_path, encoding='UTF-8')
     line = file.readline()
     file.close()
     self_info = json.loads(line)
     self.setWindowTitle(self_info["name"] + "(" + self_info["signature"] +
                         ")")
     self.setWindowIcon(QIcon(self_info["portrait"]))
     # 初始化好友列表
     self.list.setEnabled(True)
     self.__InitFriendList()
Esempio n. 4
0
 def instauto(self):
     while True:
         status, cfg = self.read_status_cfg()
         if not status:
             logger.error("配置读取失败!")
         else:
             scheme = cfg.get("scheme")
             if tupdate1.status == tupdate1.ST_INIT or tupdate1.status == tupdate1.ST_INSTALLFINISH or tupdate1.status == tupdate1.ST_INSTALLFAIL or tupdate1.ST_DOWNFAILED:
                 try:
                     if scheme == "http" or scheme == "https":
                         res = self.compare_versions()
                         r = json.loads(res)
                         state = r.get("success", "")
                         if state == True:
                             tupdate()
                     elif scheme == "ftp":
                         print "------->ftp updata start"
                         ftp_ip = cfg.get("netloc")
                         ftp_port = int(cfg.get("port"))
                         ftp_user = cfg.get("user")
                         ftp_pass = cfg.get("pass")
                         ftp_path = "/td01/update"
                         if not os.path.exists(ftp_path):
                             os.makedirs(ftp_path)
                         filename = ""
                         ftp = Ftp()
                         ftp.connect_ftp(ftp_ip, ftp_port, ftp_user,
                                         ftp_pass)
                         for file in ftp.lst_file():
                             if os.path.splitext(file)[1] == '.pkt':
                                 filename = file
                                 break
                         else:
                             continue
                         filepath = ftp.downloadfile(ftp_path, filename)
                         ftp.delete(filename)
                         ftp.close()
                         self.packet_install(filepath)
                         print self.msg
                 except Exception as e:
                     logger.error(str(e))
         time.sleep(self.starttime * 30)