Migrate2WinSSHTerm.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:Migrate2WinSSHTerm 作者: P-St 项目源码 文件源码
def read_superputty_xml(self):
        style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
        dialog = wx.FileDialog(self, message='Open Sessions.XML', wildcard='(*.XML)|*.XML', style=style)
        if dialog.ShowModal() == wx.ID_OK:
            file = dialog.GetPath()
        else:
            return False
        dialog.Destroy()
        try:
            tree = ET.parse(file)
            for item in tree.iter():
                if item.tag == "SessionData":
                    sessionPath = item.attrib.get('SessionId')
                    list = sessionPath.encode('utf-8').split('/')
                    tmp = self.root
                    res = Resolver('name')
                    counter = 1
                    for i in list:
                        pathB64 = base64.b64encode(i)
                        try:
                            if res.get(tmp, pathB64):
                                tmp = res.get(tmp, pathB64)
                                if counter >= len(list):
                                    print pathB64
                                    self.saveSessionData(
                                        node=tmp,
                                        name=str(item.attrib.get('SessionName').encode('utf-8')),
                                        username=str(item.attrib.get('Username').encode('utf-8')),
                                        privateKey='',
                                        hostname=str(item.attrib.get('Host').encode('utf-8')),
                                        port=str(item.attrib.get('Port').encode('utf-8'))
                                        )
                                    print pathB64
                        except ChildResolverError as e:
                            if counter < len(list):
                                tmp = Node(pathB64, parent=tmp, type="Container")
                            if counter >= len(list):
                                self.saveSessionData(
                                    node=tmp,
                                    name=str(item.attrib.get('SessionName').encode('utf-8')),
                                    username=str(item.attrib.get('Username').encode('utf-8')),
                                    privateKey='',
                                    hostname=str(item.attrib.get('Host').encode('utf-8')),
                                    port=str(item.attrib.get('Port').encode('utf-8'))
                                    )
                        counter = counter + 1
            return True
        except Exception as e:
            return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号