new application 'webcontentedit'
This commit is contained in:
parent
66335a52c8
commit
8b6a08f212
3 changed files with 121 additions and 0 deletions
25
scripts/webcontentedit
Executable file
25
scripts/webcontentedit
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
||||
|
||||
# Copyright(C) 2010 Romain Bignon
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
from weboob.applications.webcontentedit import WebContentEdit
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
WebContentEdit.run()
|
||||
21
weboob/applications/webcontentedit/__init__.py
Normal file
21
weboob/applications/webcontentedit/__init__.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010 Romain Bignon
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
from .webcontentedit import WebContentEdit
|
||||
|
||||
__all__ = ['WebContentEdit']
|
||||
75
weboob/applications/webcontentedit/webcontentedit.py
Normal file
75
weboob/applications/webcontentedit/webcontentedit.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010 Romain Bignon
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from weboob.capabilities.content import ICapContent
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
|
||||
|
||||
__all__ = ['WebContentEdit']
|
||||
|
||||
|
||||
class WebContentEdit(ReplApplication):
|
||||
APPNAME = 'webcontentedit'
|
||||
VERSION = '0.3'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
||||
CAPS = ICapContent
|
||||
|
||||
def do_edit(self, id):
|
||||
_id, backend_name = self.parse_id(id)
|
||||
backend_names = (backend_name,) if backend_name is not None else self.enabled_backends
|
||||
|
||||
contents = [content for backend, content in self.do('get_content', _id, backends=backend_names) if content]
|
||||
|
||||
if len(contents) == 0:
|
||||
print >>sys.stderr, 'No content for the ID "%s"' % id
|
||||
return 1
|
||||
elif len(contents) > 1:
|
||||
print >>sys.stderr, 'Too much replies'
|
||||
return 1
|
||||
|
||||
content = contents[0]
|
||||
|
||||
tmpdir = os.path.join(tempfile.gettempdir(), "weboob")
|
||||
if not os.path.isdir(tmpdir):
|
||||
os.makedirs(tmpdir)
|
||||
fd, path = tempfile.mkstemp(prefix="webcontentedit", dir=tmpdir)
|
||||
with os.fdopen(fd, 'w') as f:
|
||||
data = content.content
|
||||
if isinstance(data, unicode):
|
||||
data = data.encode('utf-8')
|
||||
f.write(data)
|
||||
os.system("$EDITOR %s" % path)
|
||||
|
||||
with open(path, 'r') as f:
|
||||
data = f.read().decode('utf-8')
|
||||
|
||||
if data == content.content:
|
||||
print 'No changes. Abort.'
|
||||
return
|
||||
|
||||
if not self.ask('Do you want to push?', default=True):
|
||||
return
|
||||
|
||||
message = self.ask('Enter a commit message', default='')
|
||||
|
||||
content.content = data
|
||||
backend = self.weboob.get_backend(content.backend)
|
||||
backend.push_content(content, message)
|
||||
Loading…
Add table
Add a link
Reference in a new issue