incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [41/42] git commit: [#6692] Added example script for project export API
Date Tue, 29 Oct 2013 22:23:42 GMT
[#6692] Added example script for project export API

Also removed errant verify=False from debugging

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


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

Branch: refs/heads/cj/6692
Commit: 8b7ad9c5f8a4f1f1c00d7cbfe1b8b14794f0dbb6
Parents: 7cf7360
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Tue Oct 29 18:39:17 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Tue Oct 29 18:44:41 2013 +0000

----------------------------------------------------------------------
 scripts/new_ticket.py     |  2 +-
 scripts/project_export.py | 46 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8b7ad9c5/scripts/new_ticket.py
----------------------------------------------------------------------
diff --git a/scripts/new_ticket.py b/scripts/new_ticket.py
index 26efe17..eda82e7 100755
--- a/scripts/new_ticket.py
+++ b/scripts/new_ticket.py
@@ -22,7 +22,7 @@ print '-----------------------------------------------'
 description = sys.stdin.read()
 print '-----------------------------------------------'
 
-r = requests.post(opts.url, verify=False, params={
+r = requests.post(opts.url, params={
         'access_token': access_token,
         'ticket_form.summary': summary,
         'ticket_form.description': description,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8b7ad9c5/scripts/project_export.py
----------------------------------------------------------------------
diff --git a/scripts/project_export.py b/scripts/project_export.py
new file mode 100755
index 0000000..a1946cc
--- /dev/null
+++ b/scripts/project_export.py
@@ -0,0 +1,46 @@
+#!/bin/env python
+
+import os
+import argparse
+import requests
+
+def get_opts():
+    parser = argparse.ArgumentParser(description='Initiate and download a project export
using the API')
+    parser.add_argument('project', help='Project shortname')
+    parser.add_argument('tools', nargs='+', help='Tool mount-points to export')
+    parser.add_argument('-H', '--host', default='sourceforge.net', help='Host name')
+    opts = parser.parse_args()
+    opts.url = 'https://{0}/rest/p/{1}/admin/'.format(opts.host, opts.project)
+    return opts
+
+opts = get_opts()
+access_token = raw_input('Access (bearer) token: ')
+username = raw_input('Username: ')
+
+r = requests.post(opts.url+'export', params={
+        'access_token': access_token,
+        'tools': opts.tools,
+    })
+assert r.status_code != 400, 'Invalid or missing tool mount-point'
+assert r.status_code != 503, 'Export already in progress'
+assert r.status_code == 200, 'Error [{0}]:\n{1}'.format(r.status_code, r.text)
+
+filename = r.json()['filename']
+
+print "Waiting for {0} to be ready...".format(filename)
+while True:
+    r = requests.get(opts.url+'export_status', params={'access_token': access_token})
+    assert r.status_code == 200, 'Error [{0}]:\n{1}'.format(r.status_code, r.text)
+    if r.json()['status'] == 'ready':
+        break
+
+print "Copying {0}...".format(filename)
+os.execv('/bin/env', [
+        'scp',
+        '{username}@web.sourceforge.net:/home/project-exports/{project}/{filename}'.format(
+            username=username,
+            project=opts.project,
+            filename=filename
+        ),
+        '.',
+    ])


Mime
View raw message