diff options
author | Steve Zesch <[email protected]> | 2013-09-06 21:12:27 -0400 |
---|---|---|
committer | Steve Zesch <[email protected]> | 2013-09-06 21:12:27 -0400 |
commit | 5c9553d4c7c2f1140ee2121a9973a163f442a91d (patch) | |
tree | 0d94fa4716ff2bf38431b99a3aac9b31375138f5 | |
parent | 87189aed6643f06e7e7090bfb61e01e614677886 (diff) | |
download | mate-desktop-5c9553d4c7c2f1140ee2121a9973a163f442a91d.tar.bz2 mate-desktop-5c9553d4c7c2f1140ee2121a9973a163f442a91d.tar.xz |
First mpaste commit.
-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 |