diff options
author | Stefano Karapetsas <[email protected]> | 2013-10-14 10:28:53 +0200 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2013-10-14 10:28:53 +0200 |
commit | 3c3f3ae078db5a521fc12eda2a5ebd5f955ad645 (patch) | |
tree | a8caff7016bdcbddc95725dc0b2691df6453e493 /mpaste | |
parent | 8220a7703e2f0f0caac7b99e995bfdef14a2d624 (diff) | |
parent | 5c9553d4c7c2f1140ee2121a9973a163f442a91d (diff) | |
download | mate-desktop-3c3f3ae078db5a521fc12eda2a5ebd5f955ad645.tar.bz2 mate-desktop-3c3f3ae078db5a521fc12eda2a5ebd5f955ad645.tar.xz |
Merge branch 'dev-mpaste'
Diffstat (limited to 'mpaste')
-rwxr-xr-x | mpaste/mpaste | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/mpaste/mpaste b/mpaste/mpaste new file mode 100755 index 0000000..901623b --- /dev/null +++ b/mpaste/mpaste @@ -0,0 +1,64 @@ +#!/usr/bin/python + +# Pastes input from stdin to paste.mate-desktop.org + +# Copyright (C) 2013 Steve Zesch + +# 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; either version 2 +# of the License, or (at your option) any later version. + +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +import urllib +import urllib2 +import optparse +import sys + +def write_paste(values): + url = 'http://paste.mate-desktop.org/api/create' + data = urllib.urlencode(values) + request = urllib2.Request(url, data) + response = urllib2.urlopen(request) + page = response.read() + + return page + +def build_values(options, text): + values = {} + + for opt, val in options.__dict__.items(): + if val: + values[opt] = val + + values['text'] = text + + if values.has_key('private') and values['private'] == True: + values['private'] = 1 + + return values + +if __name__ == '__main__': + parser = optparse.OptionParser() + parser.add_option('-t', '--title', dest='title', help='title of this paste') + parser.add_option('-n', '--name', dest='name', help='author of this paste') + parser.add_option('-p', '--private', dest='private', action='store_true', + help='should this paste be private') + parser.add_option('-l', '--language', dest='lang', + help='language this paste is in') + parser.add_option('-e', '--expire', dest='expire', help='paste expiration in minutes') + parser.add_option('-r', '--reply', dest='reply', help='reply to existing paste') + + (options, args) = parser.parse_args() + + text = sys.stdin.read() + returned_url = write_paste(build_values(options, text)) + print returned_url |