diff --git a/weboob/applications/pastoob/pastoob.py b/weboob/applications/pastoob/pastoob.py index a29c29d0..8c109eda 100644 --- a/weboob/applications/pastoob/pastoob.py +++ b/weboob/applications/pastoob/pastoob.py @@ -18,7 +18,9 @@ # along with weboob. If not, see . +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 diff --git a/weboob/backends/pastealacon/backend.py b/weboob/backends/pastealacon/backend.py index 0bbec78d..3a94b037 100644 --- a/weboob/backends/pastealacon/backend.py +++ b/weboob/backends/pastealacon/backend.py @@ -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) diff --git a/weboob/backends/pastebin/backend.py b/weboob/backends/pastebin/backend.py index aef969c3..8a5736cf 100644 --- a/weboob/backends/pastebin/backend.py +++ b/weboob/backends/pastebin/backend.py @@ -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) diff --git a/weboob/capabilities/paste.py b/weboob/capabilities/paste.py index 067bc876..7935305e 100644 --- a/weboob/capabilities/paste.py +++ b/weboob/capabilities/paste.py @@ -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()