You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/07/13 12:44:14 UTC

[10/29] allura git commit: [#6373] add more client script documentation

[#6373] add more client script documentation


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/848355c6
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/848355c6
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/848355c6

Branch: refs/heads/ib/7685
Commit: 848355c61831a4e9a5d02f6964d867ab9fc80c3e
Parents: 3189602
Author: Dave Brondsema <da...@brondsema.net>
Authored: Wed Jul 8 15:59:52 2015 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Wed Jul 8 17:00:50 2015 -0400

----------------------------------------------------------------------
 Allura/docs/getting_started/administration.rst | 31 ++++++++++---
 scripts/new_ticket.py                          | 48 ++++++++++++---------
 scripts/wiki-copy.py                           |  3 +-
 scripts/wiki-post.py                           |  2 +-
 4 files changed, 54 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/848355c6/Allura/docs/getting_started/administration.rst
----------------------------------------------------------------------
diff --git a/Allura/docs/getting_started/administration.rst b/Allura/docs/getting_started/administration.rst
index 1a2084f..c0b23e2 100644
--- a/Allura/docs/getting_started/administration.rst
+++ b/Allura/docs/getting_started/administration.rst
@@ -233,16 +233,33 @@ Requires running: :command:`pip install suds` first. ::
 Client Scripts
 ==============
 
-Allura includes some client scripts that use Allura APIs and do not have to be run
-from an Allura server.  They do require various python packages to be installed
-and possibly a local Allura codebase set up.
+Allura includes some client scripts that demonstrate use of the Allura REST API and do not have to be run
+from an Allura environment.  They do require some python packages to be installed, though.
 
-One such script is `wiki-copy.py` which reads the wiki pages from one Allura wiki
-instance and uploads them to another Allura wiki instance.  It can be run as:
 
-.. code-block:: console
+wiki-copy.py
+------------
+
+.. program-output:: python ../../scripts/wiki-copy.py --help | sed 's/Usage: /Usage: python scripts\//'
+    :shell:
+
+
+new_ticket.py
+-------------
+
+Illustrates creating a new ticket, using the simple OAuth Bearer token.
+
+.. argparse::
+    :file: ../../scripts/new_ticket.py
+    :func: get_parser
+    :prog: python scripts/new_ticket.py
+
+
+wiki-post.py
+------------
 
-    $ python scripts/wiki-copy.py --help
+.. program-output:: python ../../scripts/wiki-post.py --help | sed 's/Usage: /Usage: python scripts\//'
+    :shell:
 
 
 Site Notifications

http://git-wip-us.apache.org/repos/asf/allura/blob/848355c6/scripts/new_ticket.py
----------------------------------------------------------------------
diff --git a/scripts/new_ticket.py b/scripts/new_ticket.py
index 9b23328..924f9d2 100755
--- a/scripts/new_ticket.py
+++ b/scripts/new_ticket.py
@@ -22,32 +22,38 @@ import requests
 from pprint import pprint
 
 
-def get_opts():
+def get_parser():
     parser = argparse.ArgumentParser(
         description='Post a new ticket using the API')
     parser.add_argument('project', help='Project shortname')
     parser.add_argument('mount_point', help='Tracker mount point')
-    parser.add_argument('-H', '--host', default='sourceforge.net')
-    opts = parser.parse_args()
+    parser.add_argument('-H', '--host', default='sourceforge.net', help='Base domain')
+    return parser
+
+
+def get_opts():
+    opts = get_parser().parse_args()
     opts.url = 'https://{}/rest/p/{}/{}/new'.format(opts.host,
                                                     opts.project, opts.mount_point)
     return opts
 
-opts = get_opts()
-access_token = raw_input('Access (bearer) token: ')
-summary = raw_input('Summary: ')
-print 'Description (C-d to end):'
-print '-----------------------------------------------'
-description = sys.stdin.read()
-print '-----------------------------------------------'
-
-r = requests.post(opts.url, params={
-    'access_token': access_token,
-    'ticket_form.summary': summary,
-    'ticket_form.description': description,
-})
-if r.status_code == 200:
-    print 'Ticket created at: %s' % r.url
-    pprint(r.json())
-else:
-    print 'Error [%s]:\n%s' % (r.status_code, r.text)
+
+if __name__ == '__main__':
+    opts = get_opts()
+    access_token = raw_input('Access (bearer) token: ')
+    summary = raw_input('Summary: ')
+    print 'Description (C-d to end):'
+    print '-----------------------------------------------'
+    description = sys.stdin.read()
+    print '-----------------------------------------------'
+
+    r = requests.post(opts.url, params={
+        'access_token': access_token,
+        'ticket_form.summary': summary,
+        'ticket_form.description': description,
+    })
+    if r.status_code == 200:
+        print 'Ticket created at: %s' % r.url
+        pprint(r.json())
+    else:
+        print 'Error [%s]:\n%s' % (r.status_code, r.text)

http://git-wip-us.apache.org/repos/asf/allura/blob/848355c6/scripts/wiki-copy.py
----------------------------------------------------------------------
diff --git a/scripts/wiki-copy.py b/scripts/wiki-copy.py
index 0692852..26304cb 100644
--- a/scripts/wiki-copy.py
+++ b/scripts/wiki-copy.py
@@ -30,7 +30,8 @@ import oauth2 as oauth
 
 
 def main():
-    op = OptionParser(usage='usage: %prog [options]')
+    op = OptionParser(usage='usage: %prog [options]',
+                      description='Reads the wiki pages from one Allura wiki instance and uploads them to another Allura wiki instance.')
     op.add_option('-f', '--from-wiki', action='store', dest='from_wiki',
                   help='URL of wiki API to copy from like http://fromserver.com/rest/p/test/wiki/')
     op.add_option('-t', '--to-wiki', action='store', dest='to_wiki',

http://git-wip-us.apache.org/repos/asf/allura/blob/848355c6/scripts/wiki-post.py
----------------------------------------------------------------------
diff --git a/scripts/wiki-post.py b/scripts/wiki-post.py
index 7e16bb1..2a6fb40 100755
--- a/scripts/wiki-post.py
+++ b/scripts/wiki-post.py
@@ -85,7 +85,7 @@ class Signer(object):
 
 def main():
     usage = 'usage: %prog [options] [PageName [file]]'
-    op = OptionParser(usage=usage)
+    op = OptionParser(usage=usage, description='Use a markdown file to create/update a wiki page')
     op.add_option('-c', '--config', metavar='CONFIG')
     op.add_option('-t', '--token', metavar='TOKEN')
     op.add_option('', '--anon', action='store_true')