Add basic support for pasting with pastoob
And fix the capability.
This commit is contained in:
parent
5c7eaa3151
commit
6c2d164883
4 changed files with 50 additions and 7 deletions
|
|
@ -18,7 +18,9 @@
|
|||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import os
|
||||
import sys
|
||||
from random import choice
|
||||
|
||||
from weboob.capabilities.paste import ICapPaste, PasteNotFound
|
||||
from weboob.tools.application.repl import ReplApplication
|
||||
|
|
@ -58,3 +60,30 @@ class Pastoob(ReplApplication):
|
|||
return 3
|
||||
output = sys.stdout
|
||||
output.write(paste.contents)
|
||||
|
||||
def do_post(self, filename):
|
||||
"""
|
||||
post [FILENAME]
|
||||
|
||||
Submit a new paste.
|
||||
The filename can be '-' for reading standard input (pipe).
|
||||
"""
|
||||
if not filename:
|
||||
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('get', short=True)
|
||||
return 1
|
||||
|
||||
if filename is None or filename == '-':
|
||||
contents = sys.stdin.read()
|
||||
else:
|
||||
with open(filename) as fp:
|
||||
contents = fp.read()
|
||||
|
||||
# chose a random backend from the ones able to satisfy our requirements
|
||||
accepted_backends = [backend for backend in self.weboob.iter_backends()]
|
||||
backend = choice(accepted_backends)
|
||||
|
||||
p = backend.new_paste()
|
||||
p.title = os.path.basename(filename)
|
||||
p.contents = contents
|
||||
backend.post_paste(p)
|
||||
print 'Successfuly posted paste: %s' % p.page_url
|
||||
|
|
|
|||
|
|
@ -38,6 +38,9 @@ class PastealaconBackend(BaseBackend, ICapPaste):
|
|||
LICENSE = 'AGPLv3+'
|
||||
BROWSER = PastealaconBrowser
|
||||
|
||||
def new_paste(self):
|
||||
return PastealaconPaste(None)
|
||||
|
||||
def get_paste(self, _id):
|
||||
with self.browser:
|
||||
return self.browser.get_paste(_id)
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ class PastebinBackend(BaseBackend, ICapPaste):
|
|||
Value('apikey', label='Optional API key', default='', masked=True),
|
||||
)
|
||||
|
||||
def new_paste(self):
|
||||
return PastebinPaste(None)
|
||||
|
||||
def get_paste(self, _id):
|
||||
with self.browser:
|
||||
return self.browser.get_paste(_id)
|
||||
|
|
|
|||
|
|
@ -50,23 +50,31 @@ class BasePaste(CapBaseObject):
|
|||
|
||||
class ICapPaste(IBaseCap):
|
||||
"""
|
||||
This capability represents the ability for a website backend to store text.
|
||||
This capability represents the ability for a website backend to store plain text.
|
||||
"""
|
||||
|
||||
def get_paste(self, _id):
|
||||
def new_paste(self):
|
||||
"""
|
||||
Get a Video from an ID.
|
||||
Get a new paste object for posting it with the backend.
|
||||
|
||||
@param _id the video id. It can be a numeric ID, or a page url, or so.
|
||||
@return a Video object
|
||||
@return a Paste object
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def post_message(self, paste):
|
||||
def get_paste(self, url):
|
||||
"""
|
||||
Get a Paste from an ID or URL.
|
||||
|
||||
@param _id the paste id. It can be an ID or a page URL.
|
||||
@return a Paste object
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def post_paste(self, _id):
|
||||
"""
|
||||
Post a paste.
|
||||
|
||||
@param paste Paste object
|
||||
@param paste Paste object
|
||||
@return
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue