Exemplo n.º 1
0
def writefile(mainframe, filename, siteno, text, user=None, password=None):
    if siteno >= len(mainframe.pref.ftp_sites):
        common.showerror(mainframe, tr("Can't find the FTP site."))
        return

    site = mainframe.pref.sites_info[mainframe.pref.ftp_sites[siteno]]
    if not user:
        user = site['user']
    if not password:
        password = site['password']

    flag, user, password = getuserpassword(mainframe, siteno)
    if not flag:
        common.setmessage(mainframe, tr('Connection canceled'))
        return

    ftp = FTP()
    #connect
    try:
        ftp.connect(site['ip'], site['port'])
        ftp.login(user, password)
        ftp.set_pasv(site['pasv'])
        import StringIO
        f = StringIO.StringIO(text)
        ftp.storbinary("STOR %s" % common.decode_string(filename), f)
        ftp.quit()
        ftp.close()
        return True
    except Exception, msg:
        error.traceback()
        common.showerror(mainframe, msg)
Exemplo n.º 2
0
def readfile(mainframe, filename, siteno, user=None, password=None):
    if siteno >= len(mainframe.pref.ftp_sites):
        common.showerror(mainframe, tr("Can't find the FTP site."))
        return

    site = mainframe.pref.sites_info[mainframe.pref.ftp_sites[siteno]]
    if not user:
        user = site['user']
    if not password:
        password = site['password']

    flag, user, password = getuserpassword(mainframe, siteno)
    if not flag:
        common.setmessage(mainframe, tr('Connection canceled'))
        return

    ftp = FTP()
    try:
        ftp.connect(site['ip'], site['port'])
        ftp.login(user, password)
        ftp.set_pasv(site['pasv'])
        data = []
        def getdata(d, data=data):
            data.append(d)
        ftp.retrbinary("RETR %s" % common.decode_string(filename), getdata)
        ftp.quit()
        ftp.close()
        text = ''.join(data)
        return text
    except Exception, msg:
        error.traceback()
        common.showerror(mainframe, msg)
Exemplo n.º 3
0
def writefile(mainframe, filename, siteno, text, user=None, password=None):
    if siteno >= len(mainframe.pref.ftp_sites):
        common.showerror(mainframe, tr("Can't find the FTP site."))
        return

    site = mainframe.pref.sites_info[mainframe.pref.ftp_sites[siteno]]
    if not user:
        user = site['user']
    if not password:
        password = site['password']

    flag, user, password = getuserpassword(mainframe, siteno)
    if not flag:
        common.setmessage(mainframe, tr('Connection canceled'))
        return

    ftp = FTP()
    #connect
    try:
        ftp.connect(site['ip'], site['port'])
        ftp.login(user, password)
        ftp.set_pasv(site['pasv'])
        import StringIO
        f = StringIO.StringIO(text)
        ftp.storbinary("STOR %s" % common.decode_string(filename), f)
        ftp.quit()
        ftp.close()
        return True
    except Exception, msg:
        error.traceback()
        common.showerror(mainframe, msg)
Exemplo n.º 4
0
    def delete(self, postid=''):
        if not postid:
            index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
            if index == -1:
                common.showmessage(self.mainframe, tr('You should select on entry first!'))
                return
            filename = self.data[index]
            tree = Tree()
            tree.read_from_xml(file(filename).read())
            data = tree['entry']

            postid = data['postid']

        common.setmessage(self.mainframe, tr('Deleting entry...'))
        site = self.pref.blog_sites_info[self.pref.blog_sites[self.cmbSite.GetSelection()]]
        try:
            server = xmlrpclib.ServerProxy(site['url'])
            result = server.blogger.deletePost('', postid, site['user'], site['password'], False)
            if result:
                common.showmessage(self.mainframe, tr('Delete is successful!'))
                self.list.DeleteItem(index)
            else:
                common.showerror(self.mainframe, tr('Delete error!'))

        except Exception, msg:
            error.traceback()
            common.showerror(self.mainframe, msg)
Exemplo n.º 5
0
def readfile(mainframe, filename, siteno, user=None, password=None):
    if siteno >= len(mainframe.pref.ftp_sites):
        common.showerror(mainframe, tr("Can't find the FTP site."))
        return

    site = mainframe.pref.sites_info[mainframe.pref.ftp_sites[siteno]]
    if not user:
        user = site['user']
    if not password:
        password = site['password']

    flag, user, password = getuserpassword(mainframe, siteno)
    if not flag:
        common.setmessage(mainframe, tr('Connection canceled'))
        return

    ftp = FTP()
    try:
        ftp.connect(site['ip'], site['port'])
        ftp.login(user, password)
        ftp.set_pasv(site['pasv'])
        data = []

        def getdata(d, data=data):
            data.append(d)

        ftp.retrbinary("RETR %s" % common.decode_string(filename), getdata)
        ftp.quit()
        ftp.close()
        text = ''.join(data)
        return text
    except Exception, msg:
        error.traceback()
        common.showerror(mainframe, msg)
Exemplo n.º 6
0
    def delete(self, postid=''):
        if not postid:
            index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
            if index == -1:
                common.showmessage(self.mainframe, tr('You should select on entry first!'))
                return
            filename = self.data[index]
            tree = Tree()
            tree.read_from_xml(file(filename).read())
            data = tree['entry']

            postid = data['postid']

        common.setmessage(self.mainframe, tr('Deleting entry...'))
        site = self.pref.blog_sites_info[self.pref.blog_sites[self.cmbSite.GetSelection()]]
        try:
            server = xmlrpclib.ServerProxy(site['url'])
            result = server.blogger.deletePost('', postid, site['user'], site['password'], False)
            if result:
                common.showmessage(self.mainframe, tr('Delete is successful!'))
                self.list.DeleteItem(index)
            else:
                common.showerror(self.mainframe, tr('Delete error!'))

        except Exception, msg:
            error.traceback()
            common.showerror(self.mainframe, msg)
Exemplo n.º 7
0
 def f():
     try:
         common.setmessage(win, 'Pylint syntax checking...')
         try:
             lint.Run([pyfile],
                      Report(win.pylintsyntaxcheckwindow.list))
         except:
             error.track()
     finally:
         common.setmessage(win, '')
         common.note(tr('Pylint syntax checking finished!'))
Exemplo n.º 8
0
 def f():
     common.setmessage(begin_msg)
     try:
         try:
             func()
             if callback:
                 callback()
         except Exception, e:
             error.traceback()
             common.showerror(str(e))
     finally:
         if result:
             wx.CallAfter(result.finish)
         common.setmessage(end_msg)
Exemplo n.º 9
0
    def getposts(self, number=1, postid=''):
        common.setmessage(self.mainframe, tr('Getting entries...'))
        site = self.pref.blog_sites_info[self.pref.blog_sites[
            self.cmbSite.GetSelection()]]
        try:
            server = xmlrpclib.ServerProxy(site['url'])
            if not postid:
                result = server.metaWeblog.getRecentPosts(
                    '', site['user'], site['password'], number)
            else:
                result = [
                    server.metaWeblog.getPost(postid, site['user'],
                                              site['password'])
                ]
            self.list.DeleteAllItems()
            self.data = []
            for i, entry in enumerate(result):
                tree = Tree()
                data = {}
                data['title'] = entry['title']
                data['dateCreated'] = getDateTime(entry['dateCreated'])
                data['guid'] = entry.get('guid', '')
                data['postid'] = entry.get('postid', '')
                data['permalink'] = entry['permaLink']
                data['description'] = entry['description']
                data['author'] = entry.get('author', '')
                data['categories'] = entry['categories']
                if not data['postid']:
                    pos = data['guid'].rfind('#')
                    data['postid'] = data['guid']

                tree['entry'] = data
                path = self.getpath(site['datapath'], site['name'])
                if path:
                    filename = os.path.join(path, data['dateCreated'] + '.xml')
                    file(filename, 'wb').write(tree.write_to_xml())

                    categories = self.mapCategories(data['categories'])

                    #write list
                    self.data.append(filename)
                    self.list.InsertStringItem(i, ','.join(categories))
                    self.list.SetStringItem(i, 1, data['title'])
                    self.list.SetStringItem(i, 2,
                                            formatDate(data['dateCreated']))
                    self.list.SetStringItem(i, 3, data['postid'])

        except Exception, msg:
            error.traceback()
            common.showerror(self.mainframe, msg)
Exemplo n.º 10
0
 def f():
     common.setmessage(begin_msg)
     try:
         try:
             func()
             if callback:
                 callback()
         except Exception, e:
             error.traceback()
             common.showerror(str(e))
     finally:
         if result:
             wx.CallAfter(result.finish)
         common.setmessage(end_msg)
Exemplo n.º 11
0
 def refresh(self, path=''):
     if not path:
         path = self.txtPath.GetValue()
     try:
         common.setmessage(self.mainframe, tr('Changing the current directory...'))
         self.ftp.cwd(common.encode_string(path))
         self.data = []
         self.ftp.retrlines('LIST', self.receivedData)
         self.curpath = common.decode_string(self.ftp.pwd())
         self.txtPath.SetValue(self.curpath)
         self.loadFile(self.data)
     except Exception, msg:
         common.showerror(self, msg)
         error.traceback()
         return
Exemplo n.º 12
0
    def OnDisconnect(self, event):
        def disconnect(self):
            try:
                if self.ftp and self.alive:
                    if self.running:
                        self.ftp.abort()
                    self.ftp.quit()
            except Exception, msg:
                error.traceback()
                common.showerror(self, msg)

            self.alive = False
            self.running = False
            self.ftp = None
            common.setmessage(self.mainframe, tr('Disconnected'))
            self.list.DeleteAllItems()
Exemplo n.º 13
0
 def refresh(self, path=''):
     if not path:
         path = self.txtPath.GetValue()
     try:
         common.setmessage(self.mainframe,
                           tr('Changing the current directory...'))
         self.ftp.cwd(common.encode_string(path))
         self.data = []
         self.ftp.retrlines('LIST', self.receivedData)
         self.curpath = common.decode_string(self.ftp.pwd())
         self.txtPath.SetValue(self.curpath)
         self.loadFile(self.data)
     except Exception, msg:
         common.showerror(self, msg)
         error.traceback()
         return
Exemplo n.º 14
0
    def OnDisconnect(self, event):
        def disconnect(self):
            try:
                if self.ftp and self.alive:
                    if self.running:
                        self.ftp.abort()
                    self.ftp.quit()
            except Exception, msg:
                error.traceback()
                common.showerror(self, msg)

            self.alive = False
            self.running = False
            self.ftp = None
            common.setmessage(self.mainframe, tr('Disconnected'))
            self.list.DeleteAllItems()
Exemplo n.º 15
0
    def download(self):
        index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL,
                                      wx.LIST_STATE_SELECTED)
        if index >= 0:
            flag = self.list.GetItemData(index)
            if flag == 2:
                return
            filename = self.list.GetItemText(index)
            dlg = DownloadFileEntry(self, filename)
            answer = dlg.ShowModal()
            if answer == wx.ID_OK:
                newfile, bin = dlg.GetValue()
                if not newfile:
                    common.showerror(self, tr("The filename can't be empty."))
                    return
            else:
                return

            common.setmessage(self.mainframe, tr('Downloading the file...'))
            try:
                try:
                    if bin:
                        f = file(newfile, 'wb')

                        def getdata(d, f=f):
                            f.write(d)

                        self.ftp.retrbinary(
                            "RETR %s" % common.decode_string(filename),
                            getdata)
                    else:
                        f = file(newfile, 'w')

                        def getdata(d, f=f):
                            f.write(d + "\n")

                        self.ftp.retrlines(
                            "RETR %s" % common.decode_string(filename),
                            getdata)
                except Exception, msg:
                    error.traceback()
                    common.showerror(self, msg)
                    return
            finally:
                f.close()
            common.setmessage(self.mainframe, tr('Downloading finished'))
Exemplo n.º 16
0
    def getposts(self, number=1, postid=''):
        common.setmessage(self.mainframe, tr('Getting entries...'))
        site = self.pref.blog_sites_info[self.pref.blog_sites[self.cmbSite.GetSelection()]]
        try:
            server = xmlrpclib.ServerProxy(site['url'])
            if not postid:
                result = server.metaWeblog.getRecentPosts('', site['user'], site['password'], number)
            else:
                result = [server.metaWeblog.getPost(postid, site['user'], site['password'])]
            self.list.DeleteAllItems()
            self.data = []
            for i, entry in enumerate(result):
                tree = Tree()
                data = {}
                data['title'] = entry['title']
                data['dateCreated'] = getDateTime(entry['dateCreated'])
                data['guid'] = entry.get('guid', '')
                data['postid'] = entry.get('postid', '')
                data['permalink'] = entry['permaLink']
                data['description'] = entry['description']
                data['author'] = entry.get('author', '')
                data['categories'] = entry['categories']
                if not data['postid']:
                    pos = data['guid'].rfind('#')
                    data['postid'] = data['guid']


                tree['entry'] = data
                path = self.getpath(site['datapath'], site['name'])
                if path:
                    filename = os.path.join(path, data['dateCreated']+'.xml')
                    file(filename, 'wb').write(tree.write_to_xml())

                    categories = self.mapCategories(data['categories'])

                    #write list
                    self.data.append(filename)
                    self.list.InsertStringItem(i , ','.join(categories))
                    self.list.SetStringItem(i, 1, data['title'])
                    self.list.SetStringItem(i, 2, formatDate(data['dateCreated']))
                    self.list.SetStringItem(i, 3, data['postid'])

        except Exception, msg:
            error.traceback()
            common.showerror(self.mainframe, msg)
Exemplo n.º 17
0
    def upload(self):
        dlg = UploadFileEntry(self)
        answer = dlg.ShowModal()
        if answer == wx.ID_OK:
            filename, newfile, bin = dlg.GetValue()
            if not filename:
                common.showerror(self, tr("The filename can't be empty."))
                return
            if not newfile:
                newfile = os.path.basename(filename)
            #check if the new name has existed
            index = self.list.FindItem(-1, newfile)
            if index > -1:
                dlg = wx.MessageDialog(
                    self,
                    tr("The filename already exists. Do you want to overwrite it?"
                       ), tr("Upload File"), wx.YES_NO | wx.ICON_QUESTION)
                answer = dlg.ShowModal()
                if answer == wx.ID_NO:
                    return

            common.setmessage(self.mainframe, tr('Uploading the file...'))
            #           if not self.setBin(bin):
            #               return
            from StringIO import StringIO
            try:
                if bin:
                    f = StringIO(file(filename, 'rb').read())
                    self.ftp.storbinary(
                        'STOR %s' % common.decode_string(newfile), f)
                else:
                    f = StringIO(file(filename, 'r').read())
                    self.ftp.storlines(
                        'STOR %s' % common.decode_string(newfile), f)
            except Exception, msg:
                error.traceback()
                common.showerror(self, msg)
                return

            self.setBin(True)
            if self.refresh(self.curpath):
                index = self.list.FindItem(-1, newfile)
                self.list.SetItemState(index, wx.LIST_STATE_SELECTED,
                                       wx.LIST_MASK_STATE)
            common.setmessage(self.mainframe, tr('Uploading finished'))
Exemplo n.º 18
0
 def OnEnter(self, event):
     common.setmessage(self.mainframe, tr('Retrieving the file...'))
     index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
     data = self.list.GetItemData(index)
     if data == 0:   #is directory
         self.refresh(self.getpath(self.list.GetItemText(index)))
     elif data == 2: #is parent denote
         self.refresh('..')
     elif data == 1: #is a file
         filename = "ftp(%d):%s" % (self.cmbSite.GetSelection(), self.getpath(os.path.join(self.curpath, self.list.GetItemText(index))))
         encoding = self.txtEncoding.GetValue()
         if encoding == 'Custom':
             dlg = MyTextEntry(self, tr("Encoding Input"), tr('Input an encoding:'), '')
             answer = dlg.ShowModal()
             if answer == wx.ID_OK:
                 encoding = dlg.GetValue()
         if encoding == 'Default':
             encoding = ''
         self.mainframe.editctrl.new(filename, encoding)
Exemplo n.º 19
0
    def OnRefresh(self, event):
        common.setmessage(self.mainframe, tr('Refreshing the current path...'))
        self.refresh()
        text = self.txtPath.GetValue()
        if text in self.pref.remote_paths:
            self.pref.remote_paths.remove(text)
            self.pref.remote_paths.insert(0, text)
        else:
            self.pref.remote_paths.insert(0, text)
        while len(self.pref.remote_paths) > self.pref.max_number:
            del self.pref.remote_paths[-1]

        self.pref.save()

        self.txtPath.Clear()
        for s in self.pref.remote_paths:
            self.txtPath.Append(s)

        self.txtPath.SetValue(text)
        self.txtPath.SetMark(0, len(text))
Exemplo n.º 20
0
    def OnRefresh(self, event):
        common.setmessage(self.mainframe, tr('Refreshing the current path...'))
        self.refresh()
        text = self.txtPath.GetValue()
        if text in self.pref.remote_paths:
            self.pref.remote_paths.remove(text)
            self.pref.remote_paths.insert(0, text)
        else:
            self.pref.remote_paths.insert(0, text)
        while len(self.pref.remote_paths) > self.pref.max_number:
            del self.pref.remote_paths[-1]

        self.pref.save()

        self.txtPath.Clear()
        for s in self.pref.remote_paths:
            self.txtPath.Append(s)

        self.txtPath.SetValue(text)
        self.txtPath.SetMark(0, len(text))
Exemplo n.º 21
0
        def connect(self):
            self.running = True

            site = self.pref.sites_info[self.pref.ftp_sites[
                self.cmbSite.GetSelection()]]
            self.ftp = FTP()

            #connect
            try:
                common.setmessage(
                    self.mainframe,
                    tr('Connecting to %s (%s:%s)...') %
                    (site['name'], site['ip'], site['port']))
                self.ftp.connect(site['ip'], site['port'])
                flag, user, password = self.getuserpassword(
                    self.cmbSite.GetSelection(), self.txtUser.GetValue(),
                    self.txtPassword.GetValue())
                if not flag:
                    common.setmessage(self.mainframe,
                                      tr('Connection canceled'))
                    self.ftp = None
                    self.alive = False
                    self.running = False
                    return
                common.setmessage(self.mainframe, tr('Logging in...'))
                self.ftp.login(user, password)
            except socket.error, msg:
                error.traceback()
                common.showerror(self, msg[1])
                self.ftp = None
                self.running = False
                return
Exemplo n.º 22
0
        def connect(self):
            self.running = True

            site = self.pref.sites_info[self.pref.ftp_sites[self.cmbSite.GetSelection()]]
            self.ftp = FTP()

            #connect
            try:
                common.setmessage(self.mainframe, tr('Connecting to %s (%s:%s)...') % (site['name'],site['ip'], site['port']))
                self.ftp.connect(site['ip'], site['port'])
                flag, user, password = self.getuserpassword(self.cmbSite.GetSelection(), self.txtUser.GetValue(), self.txtPassword.GetValue())
                if not flag:
                    common.setmessage(self.mainframe, tr('Connection canceled'))
                    self.ftp = None
                    self.alive = False
                    self.running = False
                    return
                common.setmessage(self.mainframe, tr('Logging in...'))
                self.ftp.login(user, password)
            except socket.error, msg:
                error.traceback()
                common.showerror(self, msg[1])
                self.ftp = None
                self.running = False
                return
Exemplo n.º 23
0
    def upload(self):
        dlg = UploadFileEntry(self)
        answer = dlg.ShowModal()
        if answer == wx.ID_OK:
            filename, newfile, bin = dlg.GetValue()
            if not filename:
                common.showerror(self, tr("The filename can't be empty."))
                return
            if not newfile:
                newfile = os.path.basename(filename)
            #check if the new name has existed
            index = self.list.FindItem(-1, newfile)
            if index > -1:
                dlg = wx.MessageDialog(self, tr("The filename already exists. Do you want to overwrite it?"), tr("Upload File"), wx.YES_NO | wx.ICON_QUESTION)
                answer = dlg.ShowModal()
                if answer == wx.ID_NO:
                    return

            common.setmessage(self.mainframe, tr('Uploading the file...'))
#           if not self.setBin(bin):
#               return
            from StringIO import StringIO
            try:
                if bin:
                    f = StringIO(file(filename, 'rb').read())
                    self.ftp.storbinary('STOR %s' % common.decode_string(newfile), f)
                else:
                    f = StringIO(file(filename, 'r').read())
                    self.ftp.storlines('STOR %s' % common.decode_string(newfile), f)
            except Exception, msg:
                error.traceback()
                common.showerror(self, msg)
                return

            self.setBin(True)
            if self.refresh(self.curpath):
                index = self.list.FindItem(-1, newfile)
                self.list.SetItemState(index, wx.LIST_STATE_SELECTED, wx.LIST_MASK_STATE)
            common.setmessage(self.mainframe, tr('Uploading finished'))
Exemplo n.º 24
0
    def download(self):
        index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
        if index >= 0:
            flag = self.list.GetItemData(index)
            if flag == 2:
                return
            filename = self.list.GetItemText(index)
            dlg = DownloadFileEntry(self, filename)
            answer = dlg.ShowModal()
            if answer == wx.ID_OK:
                newfile, bin = dlg.GetValue()
                if not newfile:
                    common.showerror(self, tr("The filename can't be empty."))
                    return
            else:
                return

            common.setmessage(self.mainframe, tr('Downloading the file...'))
            try:
                try:
                    if bin:
                        f = file(newfile, 'wb')
                        def getdata(d, f=f):
                            f.write(d)
                        self.ftp.retrbinary("RETR %s" % common.decode_string(filename), getdata)
                    else:
                        f = file(newfile, 'w')
                        def getdata(d, f=f):
                            f.write(d+"\n")
                        self.ftp.retrlines("RETR %s" % common.decode_string(filename), getdata)
                except Exception, msg:
                    error.traceback()
                    common.showerror(self, msg)
                    return
            finally:
                f.close()
            common.setmessage(self.mainframe, tr('Downloading finished'))
Exemplo n.º 25
0
 def OnEnter(self, event):
     common.setmessage(self.mainframe, tr('Retrieving the file...'))
     index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL,
                                   wx.LIST_STATE_SELECTED)
     data = self.list.GetItemData(index)
     if data == 0:  #is directory
         self.refresh(self.getpath(self.list.GetItemText(index)))
     elif data == 2:  #is parent denote
         self.refresh('..')
     elif data == 1:  #is a file
         filename = "ftp(%d):%s" % (
             self.cmbSite.GetSelection(),
             self.getpath(
                 os.path.join(self.curpath, self.list.GetItemText(index))))
         encoding = self.txtEncoding.GetValue()
         if encoding == 'Custom':
             dlg = MyTextEntry(self, tr("Encoding Input"),
                               tr('Input an encoding:'), '')
             answer = dlg.ShowModal()
             if answer == wx.ID_OK:
                 encoding = dlg.GetValue()
         if encoding == 'Default':
             encoding = ''
         self.mainframe.editctrl.new(filename, encoding)
Exemplo n.º 26
0
        common.setmessage(self.mainframe, tr('Deleting entry...'))
        site = self.pref.blog_sites_info[self.pref.blog_sites[self.cmbSite.GetSelection()]]
        try:
            server = xmlrpclib.ServerProxy(site['url'])
            result = server.blogger.deletePost('', postid, site['user'], site['password'], False)
            if result:
                common.showmessage(self.mainframe, tr('Delete is successful!'))
                self.list.DeleteItem(index)
            else:
                common.showerror(self.mainframe, tr('Delete error!'))

        except Exception, msg:
            error.traceback()
            common.showerror(self.mainframe, msg)
        common.setmessage(self.mainframe, tr('Done'))

class BlogSiteManageDialog(wx.Dialog):
    def __init__(self, *args, **kwargs):
        wx.Dialog.__init__(self, *args, **kwargs)

    def init(self, mainframe):
        self.mainframe = mainframe
        self.pref = self.mainframe.pref
        self.obj_ID_CLOSE.SetId(wx.ID_CANCEL)

        self.lastindex = self.pref.last_blog_site
        self.categories = {}
        self.load()

        wx.EVT_UPDATE_UI(self.obj_ID_DELETE, self.ID_DELETE, self.OnUpdateUI)
Exemplo n.º 27
0
class BlogManageWindow(wx.Panel, Mixin.Mixin):

    __mixinname__ = 'blogmanagewindow'
    popmenulist = []
    imagelist = {}

    def __init__(self, parent, mainframe):
        self.initmixin()
        self.parent = parent
        self.mainframe = mainframe
        self.pref = self.mainframe.pref
        wx.Panel.__init__(self, parent, -1)

        self.box = wx.BoxSizer(wx.VERTICAL)

        self.box1 = wx.BoxSizer(wx.HORIZONTAL)

        obj = wx.StaticText(self, -1, tr('Account:'))
        self.box1.Add(obj, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 2)
        self.ID_SITELIST = wx.NewId()
        self.cmbSite= wx.ComboBox(self, self.ID_SITELIST, "", choices=self.mainframe.pref.blog_sites, size=(100, 20), style=wx.CB_READONLY)
        self.box1.Add(self.cmbSite, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 2)

        #manage
        self.ID_MANAGE = wx.NewId()
        self.btnManage = wx.Button(self, self.ID_MANAGE, tr('Manage'), size=(50, -1))
        self.box1.Add(self.btnManage, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 2)

        #new button
        self.ID_NEW= wx.NewId()
        self.btnNew = wx.Button(self, self.ID_NEW, tr('New'), size=(40, -1))
        self.box1.Add(self.btnNew, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 2)

        #delete button
        self.ID_DELETE= wx.NewId()
        self.btnDelete = wx.Button(self, self.ID_DELETE, tr('Del'), size=(40, -1))
        self.box1.Add(self.btnDelete, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 2)

        #get last post
        self.ID_GETPOSTS = wx.NewId()
        self.btnGetposts = wx.Button(self, self.ID_GETPOSTS, tr('Get Post'), size=(65, -1))
        self.box1.Add(self.btnGetposts, 0, wx.ALIGN_CENTER_VERTICAL)

        #get posts more
        self.ID_GETPOSTSMORE = wx.NewId()
        self.btnGetpostsMore = wx.Button(self, self.ID_GETPOSTSMORE, tr('>'), size=(15, -1))
        self.box1.Add(self.btnGetpostsMore, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 2)

        #get posts more
        self.ID_CACHE = wx.NewId()
        self.btnCache = wx.Button(self, self.ID_CACHE, tr('Cache'), size=(40, -1))
        self.box1.Add(self.btnCache, 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 2)

        self.box.Add(self.box1, 0, wx.ALL|wx.EXPAND, 2)

        self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT | wx.LC_SINGLE_SEL)
        self.box.Add(self.list, 1, wx.EXPAND)

        self.SetSizer(self.box)
        self.SetAutoLayout(True)

        self.load()
        self.data = []
        self.initlist()

        wx.EVT_UPDATE_UI(self.btnDelete, self.ID_DELETE, self.OnUpdateUI)
        wx.EVT_BUTTON(self.btnManage, self.ID_MANAGE, self.OnManage)
        wx.EVT_BUTTON(self.btnNew, self.ID_NEW, self.OnNew)
        wx.EVT_BUTTON(self.btnDelete, self.ID_DELETE, self.OnDelete)
        wx.EVT_BUTTON(self.btnGetposts, self.ID_GETPOSTS, self.OnGetPosts)
        wx.EVT_BUTTON(self.btnGetpostsMore, self.ID_GETPOSTSMORE, self.OnGetPostsMore)
        wx.EVT_BUTTON(self.btnCache, self.ID_CACHE, self.OnCache)
        wx.EVT_LIST_ITEM_ACTIVATED(self.list, self.list.GetId(), self.OnEntryEntered)
        wx.EVT_COMBOBOX(self.cmbSite, self.ID_SITELIST, self.OnSiteChanged)

        if self.popmenulist:
            self.popmenu = makemenu.makepopmenu(self, self.popmenulist, self.imagelist)
            wx.EVT_LIST_ITEM_RIGHT_CLICK(self.list, self.list.GetId(), self.OnRClick)
            wx.EVT_RIGHT_UP(self.list, self.OnRClick)

        self.callplugin('init', self)

    def canClose(self):
        return True

    def OnUpdateUI(self, event):
        eid = event.GetId()
        if eid == self.ID_DELETE:
            index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
            event.Enable(index > -1)

    def OnManage(self, event):
        filename = i18n.makefilename(self.mainframe.blog_resfile, self.mainframe.app.i18n.lang)
        dlg = Resource.loadfromresfile(filename, self.mainframe, BlogSiteManageDialog, 'BlogSiteManageDialog', self.mainframe)
        dlg.ShowModal()
        self.load()

    def OnRClick(self, event):
        self.list.PopupMenu(self.popmenu, event.GetPosition())

    def OnSiteChanged(self, event):
        self.pref.last_blog_site = self.cmbSite.GetSelection()
        self.pref.save()
        self.load()

    def OnNew(self, event):
        self.new()

    def OnGetPosts(self, event):
        self.getposts()

    def OnGetPostsMore(self, event):
        from modules import Entry

        dlg = Entry.MyTextEntry(self, tr("Get Recent Posts"), tr("Enter the number from the lastest one:"), '1')
        answer = dlg.ShowModal()
        if answer == wx.ID_OK:
            try:
                number = int(dlg.GetValue())
                self.getposts(number)
            except:
                return

    def getposts(self, number=1, postid=''):
        common.setmessage(self.mainframe, tr('Getting entries...'))
        site = self.pref.blog_sites_info[self.pref.blog_sites[self.cmbSite.GetSelection()]]
        try:
            server = xmlrpclib.ServerProxy(site['url'])
            if not postid:
                result = server.metaWeblog.getRecentPosts('', site['user'], site['password'], number)
            else:
                result = [server.metaWeblog.getPost(postid, site['user'], site['password'])]
            self.list.DeleteAllItems()
            self.data = []
            for i, entry in enumerate(result):
                tree = Tree()
                data = {}
                data['title'] = entry['title']
                data['dateCreated'] = getDateTime(entry['dateCreated'])
                data['guid'] = entry.get('guid', '')
                data['postid'] = entry.get('postid', '')
                data['permalink'] = entry['permaLink']
                data['description'] = entry['description']
                data['author'] = entry.get('author', '')
                data['categories'] = entry['categories']
                if not data['postid']:
                    pos = data['guid'].rfind('#')
                    data['postid'] = data['guid']


                tree['entry'] = data
                path = self.getpath(site['datapath'], site['name'])
                if path:
                    filename = os.path.join(path, data['dateCreated']+'.xml')
                    file(filename, 'wb').write(tree.write_to_xml())

                    categories = self.mapCategories(data['categories'])

                    #write list
                    self.data.append(filename)
                    self.list.InsertStringItem(i , ','.join(categories))
                    self.list.SetStringItem(i, 1, data['title'])
                    self.list.SetStringItem(i, 2, formatDate(data['dateCreated']))
                    self.list.SetStringItem(i, 3, data['postid'])

        except Exception, msg:
            error.traceback()
            common.showerror(self.mainframe, msg)
        common.setmessage(self.mainframe, tr('Done'))
Exemplo n.º 28
0
        common.setmessage(self.mainframe, tr('Deleting entry...'))
        site = self.pref.blog_sites_info[self.pref.blog_sites[self.cmbSite.GetSelection()]]
        try:
            server = xmlrpclib.ServerProxy(site['url'])
            result = server.blogger.deletePost('', postid, site['user'], site['password'], False)
            if result:
                common.showmessage(self.mainframe, tr('Delete is successful!'))
                self.list.DeleteItem(index)
            else:
                common.showerror(self.mainframe, tr('Delete error!'))

        except Exception, msg:
            error.traceback()
            common.showerror(self.mainframe, msg)
        common.setmessage(self.mainframe, tr('Done'))

class BlogSiteManageDialog(wx.Dialog):
    def __init__(self, *args, **kwargs):
        wx.Dialog.__init__(self, *args, **kwargs)

    def init(self, mainframe):
        self.mainframe = mainframe
        self.pref = self.mainframe.pref
        self.obj_ID_CLOSE.SetId(wx.ID_CANCEL)

        self.lastindex = self.pref.last_blog_site
        self.categories = {}
        self.load()

        wx.EVT_UPDATE_UI(self.obj_ID_DELETE, self.ID_DELETE, self.OnUpdateUI)