Switch to python based grml-paste by Gebi for new paste.grml.org service.
authorMichael Prokop <mika@grml.org>
Mon, 14 Jun 2010 12:26:41 +0000 (14:26 +0200)
committerMichael Prokop <mika@grml.org>
Mon, 14 Jun 2010 12:26:41 +0000 (14:26 +0200)
.hgtags [deleted file]
debian/control
debian/copyright
debian/rules
grml-paste
grml-paste.1.txt

diff --git a/.hgtags b/.hgtags
deleted file mode 100644 (file)
index b5ff7bc..0000000
--- a/.hgtags
+++ /dev/null
@@ -1,2 +0,0 @@
-f43c979447767fa9ee4bb628a10a8228a4be887d 0.1
-109eb1e2f4ffc4d472cc74128064e69b8a2c9410 0.2
index 48488d3..35b133a 100644 (file)
@@ -1,16 +1,17 @@
 Source: grml-paste
-Section: utils
+Section: grml
 Priority: extra
 Maintainer: Michael Prokop <mika@grml.org>
 Build-Depends: debhelper (>= 5)
-Standards-Version: 3.7.2
-Homepage: http://hg.grml.org/grml-paste/
-XS-Vcs-hg: http://hg.grml.org/grml-paste/
-XS-Vcs-Browser: http://hg.grml.org/grml-paste/
+Standards-Version: 3.8.4
+Homepage: http://git.grml.org/?p=grml-paste.git
+Vcs-git: git://git.grml.org/grml-paste.git
+Vcs-Browser: http://git.grml.org/?p=grml-paste.git
 
 Package: grml-paste
 Architecture: all
-Depends: ${shlibs:Depends}, ${misc:Depends}, ruby
+Depends: ${shlibs:Depends}, ${misc:Depends}, python
 Description: command line interface for paste.grml.org
- grml-paste is a command line interface for uploading
- plain text to  http://paste.grml.org/
+ This package provides a command line interface tool to upload
+ plain text to http://paste.grml.org/ - being the official paste
+ service for Grml.org.
index 641fc01..fe3b5ff 100644 (file)
@@ -3,16 +3,13 @@ Thu, 13 Dec 2007 11:17:35 +0100.
 
 It was downloaded from http://grml.org/
 
-Upstream Author: Nico Golde <nico@grml.org>
-
-Copyright: grml-team (grml.org), (c) 2007 Nico Golde <nico@grml.org>
+Copyright Holder: grml-team (grml.org), Michael Gebetsroither <gebi@grml.org>
 
 License:
 
    This package 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.
+   the Free Software Foundation; version 2 dated June, 1991.
 
    This package is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -24,7 +21,7 @@ License:
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
 On Debian systems, the complete text of the GNU General
-Public License can be found in `/usr/share/common-licenses/GPL'.
+Public License can be found in `/usr/share/common-licenses/GPL-2'.
 
-The Debian packaging is (C) 2007, Michael Prokop <mika@grml.org> and
+The Debian packaging is © 2007, 2010, Michael Prokop <mika@grml.org> and
 is licensed under the GPL, see above.
index 1344198..3174216 100755 (executable)
@@ -21,7 +21,7 @@ clean:
        dh_testroot
        rm -f build-stamp
 
-       -$(MAKE) clean
+       $(MAKE) clean
        dh_clean 
 
 install: build
@@ -32,12 +32,12 @@ install: build
 
        install -m 755 grml-paste debian/grml-paste/usr/bin/grml-paste
 
-# Build architecture-independent files here.
-binary-indep: build install
-# We have nothing to do by default.
-
 # Build architecture-dependent files here.
 binary-arch: build install
+# We have nothing to do by default.
+
+# Build architecture-independent files here.
+binary-indep: build install
        dh_testdir
        dh_testroot
        dh_installchangelogs 
index d4b7fb6..cba6108 100755 (executable)
-#!/usr/bin/env ruby
+#!/usr/bin/python
 # Filename:      grml-paste
-# Purpose:       paste files to the online grml paste bot
-# Authors:       grml-team (grml.org), (c) 2007 Nico Golde <nico@grml.org>
-# Bug-Reports:   see http://grml.org/bugs/
-# License:       This file is licensed under the GPL v2
-##########################################################################
-
-require 'uri'
-require 'net/http'
-
-url = URI.parse('http://paste.grml.org/paste')
-
-def usage
-       $stderr.puts "usage: #{$0} [-n nick] [-s summary] [-f source] [-h|--help]\n"
-       $stderr.puts "\t -n <nick>\tset your nickname (defaults to Anonymuos)"
-       $stderr.puts "\t -s <summary>\tspecify a summary of your paste (defaults to none)"
-       $stderr.puts "\t -f <source>\tsets the file to read from, you don't need this for reading from stdin"
-       $stderr.puts "\t --help\t\tprint this help"
-       Kernel.exit(1)
-end
-
-file    = nil
-summary = "none"
-nick    = "Anonymous"
-channel = "#grml"
-text    = ""
-
-ARGV.each_index do |i|
-       if ARGV[i] == '-h' or ARGV[i] == '--help' then
-               usage
-       elsif ARGV[i] == '-n' and ARGV[i+1] != nil then
-               nick = ARGV[i+1]
-       elsif ARGV[i] == '-s' and ARGV[i+1] != nil then
-               summary = ARGV[i+1]
-       elsif ARGV[i] == '-f' and ARGV[i+1] != nil then
-               file = ARGV[i+1]
-       end
-end
-
-if file == nil or file == "-"
-       f = STDIN
-else
-       begin
-               f = File.open(file)
-       rescue
-               $stderr.puts "Error: couldn't open file: #{file}"
-               Kernel.exit(1)
-       end
-end
-
-f.each_line do |line|
-       text << line
-end
-
-begin
-       res = Net::HTTP.post_form(url,{'Paste it' => 'Paste it', 'paste' => text, 'channel' => channel,  'summary' => summary, 'nick' => nick})
-rescue
-       $stderr.puts "Unable to post HTTP request"
-       Kernel.exit(1)
-end
-
-results = res.body.scan(/<a href='http:\/\/paste.grml.org\/[0-9]+'/)
-result = ""
-if results.size > 0 then
-       result = results[0].sub(/<a href='(http:\/\/paste.grml.org\/[0-9]+)'/, '\1')
-end
-
-if result == "" then
-       print "Failed to paste, please retry\n"
-else
-       print "You can find your paste on: " + result + "\n"
-end
-
-## END OF FILE #################################################################
+# Purpose:       XmlRpc interface client to paste.grml.org
+# Author:        Michael Gebetsroither <gebi@grml.org>
+# License:       This file is licensed under the GPL v2.
+################################################################################
+
+import sys
+import xmlrpclib
+import optparse
+from pprint import pprint
+import inspect
+
+
+class ActionFailedException(Exception):
+    '''Thrown if server returned an error'''
+    def __init__(self, errormsg, ret):
+        Exception.__init__(self, errormsg, ret)
+    def what(self):
+        '''Get errormessage'''
+        return self.args[0]
+    def dwhat(self):
+        '''Get more verbose errormessage'''
+        return self.args[1]
+
+
+class Action(object):
+    def __init__(self, args, opts):
+        self.args_ = args
+        self.opts_ = opts
+
+    def _createProxy(self):
+        return xmlrpclib.ServerProxy(self.opts_.server)
+
+    def _callProxy(self, functor, server=None):
+        '''Wrapper for xml-rpc calls to server which throws an
+           ActionFailedException on error'''
+        if server is None:
+            server = self._createProxy()
+        ret = functor(server)
+        if ret['rc'] != 0:
+            raise ActionFailedException(ret['statusmessage'], ret)
+        return ret
+
+    def call(self, method_name):
+        '''External Interface to call the appropriate action'''
+        return self.__getattribute__(method_name)()
+
+    def actionAddPaste(self):
+        '''Add paste to the server: <1.line> <2.line> ...
+
+        default     Read paste from stdin.
+        [text]      Every argument on the commandline will be interpreted as
+                    a seperate line of paste.
+        '''
+        server = self._createProxy()
+        o = self.opts_
+        code = self.args_
+        if len(self.args_) == 0:
+            code = [ i.strip() for i in sys.stdin.readlines() ]
+        code = '\n'.join(code)
+        result = self._callProxy(lambda s: s.paste.addPaste(code, o.name, o.expire * 3600, o.lang),
+                            server)
+        return (result['statusmessage'], result)
+
+    def actionDelPaste(self):
+        '''Delete paste from server: <digest>
+
+        <digest>    Digest of paste you want to remove.
+        '''
+        digest = self.args_.pop(0)
+
+        result = self._callProxy(lambda s: s.paste.deletePaste(digest))
+        return (result['statusmessage'], result)
+
+    def actionGetPaste(self):
+        '''Get paste from server: <id>
+
+        <id>        Id of paste you want to receive.
+        '''
+        id = self.args_.pop(0)
+
+        result = self._callProxy(lambda s: s.paste.getPaste(id))
+        return (result['code'], result)
+
+    def actionGetLangs(self):
+        '''Get supported language highlighting types from server'''
+        result = self._callProxy(lambda s: s.paste.getLanguages())
+        return ('\n'.join(result['langs']), result)
+
+    def actionHelp(self):
+        '''Print more verbose help about specific action: <action>
+
+        <action>    Topic on which you need more verbose help.
+        '''
+        alias = self.args_.pop(0)
+
+        fun = actions[alias]
+        print inspect.getdoc(self.__getattribute__(fun))
+        print "\naliase: " + " ".join([i for i in actions_r[fun] if i != alias])
+        sys.exit(0)
+
+
+# actionAddPaste -> [add, a]
+actions_r = {}
+
+# add -> actionAddPaste
+# a   -> actionAddPaste
+actions   = {}
+
+##
+# MAIN
+##
+if __name__ == "__main__":
+    action_spec = ['actionAddPaste add a',
+                   'actionDelPaste del d rm',
+                   'actionGetPaste get g',
+                   'actionGetLangs getlangs gl langs l',
+                   'actionHelp     help']
+    for i in action_spec:
+        tmp = i.split()
+        cmd = tmp.pop(0)
+        actions_r[cmd] = tmp
+    for (k,v) in actions_r.items():
+        for i in v:
+            actions[i] = k
+
+    usage = "usage: %prog [options] ACTION <args>\n\n" +\
+            "actions:\n" +\
+            "\n".join(["%12s\t%s" % (v[0], inspect.getdoc(getattr(Action, k)).split('\n')[0]) \
+                for (k,v) in actions_r.items()])
+    parser = optparse.OptionParser(usage=usage)
+    parser.add_option('-n', '--name', default='anonymous', help="Name of poster")
+    parser.add_option('-e', '--expire', type=int, default=72, metavar='HOURS',
+            help='Time at wich paste should expire')
+    parser.add_option('-l', '--lang', default='Plain', help='Type of language to highlight')
+    parser.add_option('-s', '--server', default='http://paste.grml.org/server.pl',
+            help='Paste server')
+    parser.add_option('-v', '--verbose', action='count', default=0, help='More output')
+    (opts, args) = parser.parse_args()
+
+    if len(args) == 0:
+        parser.error('Please provide me with an action')
+    elif args[0] in actions:
+        cmd = args.pop(0)
+        action = Action(args, opts)
+        try:
+            (msg, ret) = action.call(actions[cmd])
+            if opts.verbose == 0:
+                print msg
+            else:
+                pprint(ret)
+        except ActionFailedException, e:
+            sys.stderr.write('Server Error: %s\n' % e.what())
+            if opts.verbose >0:
+                pprint(e.dwhat())
+            sys.exit(1)
+    else:
+        parser.error('Unknown action: %s' % args[0])
index 4d5d960..aeaf588 100644 (file)
@@ -7,7 +7,7 @@ grml-paste - command line interface for paste.grml.org
 
 Synopsis
 --------
-grml-paste [-n nick] [-s summary] [-f source] [-h|--help]
+grml-paste [options] ACTION <args>
 
 Description
 -----------
@@ -17,26 +17,57 @@ grml-paste is a command line interface for uploading plain text to http://paste.
 Options
 -------
 
-  -n **nick**::
+  **-e 'hours', --expire='HOURS'**::
 
-Set your nickname (defaults to Anonymous).
+Time at wich paste should expire.
 
-  -s **summary**::
+  **-h, --help**::
 
-Specify a summary of your paste (defaults to none).
+Print help text.
 
-  -f **source**::
+  **-l 'lang', --lang='LANG'**::
 
-Sets the file to read from, use - to read from stdin.
+Type of language to highlight.
 
-  --help::
+  **-n 'name', --name='NAME'**::
 
-Print help text.
+Set your nickname (defaults to anonymous).
+
+  **-s 'server', --server='SERVER'**::
+
+Set URL of paste server (defaults to paste.grml.org).
+
+  **-v, --verbose**::
+
+More verbose output.
+
+Actions
+-------
+
+  **add**::
+
+Add paste to the server: <1.line> <2.line> ...
+
+  **del '<digest>'*::
+
+Delete paste from server.
+
+ **get '<id>'**::
+
+Get paste from server.
+
+  **getlangs**::
+
+Get supported language highlighting types from server.
+
+  **help <action>**::
+
+Print more verbose help about specified '<action>'.
 
 Bugs
 ----
-Please report feedback, link:http://grml.org/bugs/[bugreports] and wishes link:http://grml.org/contact/[to us]!
+Please report feedback, link:http://grml.org/bugs/[bugreports] and wishes link:http://grml.org/contact/[to the grml team].
 
 Authors
 -------
-Nico Golde <nico@grml.org>
+Michael Gebetsroither <gebi@grml.org>