Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4730010F68 for ; Tue, 17 Sep 2013 19:13:09 +0000 (UTC) Received: (qmail 10139 invoked by uid 500); 17 Sep 2013 19:12:18 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 9882 invoked by uid 500); 17 Sep 2013 19:12:09 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 9599 invoked by uid 99); 17 Sep 2013 19:12:00 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Sep 2013 19:12:00 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id CD82BA495; Tue, 17 Sep 2013 19:11:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: brondsem@apache.org To: allura-commits@incubator.apache.org Date: Tue, 17 Sep 2013 19:12:11 -0000 Message-Id: In-Reply-To: <4aab4676f6694722aef845f79aa45d5b@git.apache.org> References: <4aab4676f6694722aef845f79aa45d5b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [13/20] git commit: [#5966] remove SF-internal references; PEP-8 cleanup; determine base_url automatically [#5966] remove SF-internal references; PEP-8 cleanup; determine base_url automatically Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/21b2c16d Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/21b2c16d Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/21b2c16d Branch: refs/heads/db/5822 Commit: 21b2c16d6e4438d441ee72b3b20a8ac5537e7ae6 Parents: 1b62fd9 Author: Dave Brondsema Authored: Wed Sep 11 22:12:59 2013 +0000 Committer: Cory Johns Committed: Tue Sep 17 17:00:13 2013 +0000 ---------------------------------------------------------------------- scripts/wiki-copy.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/21b2c16d/scripts/wiki-copy.py ---------------------------------------------------------------------- diff --git a/scripts/wiki-copy.py b/scripts/wiki-copy.py index bca726d..35e0077 100644 --- a/scripts/wiki-copy.py +++ b/scripts/wiki-copy.py @@ -17,7 +17,6 @@ # specific language governing permissions and limitations # under the License. -import re import os import sys import urllib @@ -31,20 +30,16 @@ import oauth2 as oauth def main(): - cp = ConfigParser() - cp.read('/var/local/allura/Allura/production.ini') - op = OptionParser(usage='usage: %prog [options]') - op.add_option('-u', '--base-url', action='store', dest='base_url', - default=cp.get('app:main', 'base_url'), help='URL of API to upload to [default: %default]') - op.add_option('-D', '--debug', action='store_true', dest='debug', default=False) op.add_option('-f', '--from-wiki', action='store', dest='from_wiki', - help='URL of wiki to copy from like http://fromserver.com/rest/p/test/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', - help='URL of wiki to copy to like http://toserver.com/rest/p/test/wiki/') + help='URL of wiki API to copy to like http://toserver.com/rest/p/test/wiki/') + op.add_option('-D', '--debug', action='store_true', dest='debug', default=False) (options, args) = op.parse_args(sys.argv[1:]) - oauth_client = make_oauth_client(options.base_url) + base_url = options.to_wiki.split('/rest/')[0] + oauth_client = make_oauth_client(base_url) wiki_data = urllib.urlopen(options.from_wiki).read() wiki_json = json.loads(wiki_data)['pages'] @@ -67,20 +62,18 @@ def main(): print "Error processing " + p raise + def make_oauth_client(base_url): """ Build an oauth.Client with which callers can query Allura. - - Based on Allura, sfpy, and sfx push scripts """ - + config_file = os.path.join(os.environ['HOME'], '.allurarc') cp = ConfigParser() - cp.read(os.path.join(os.environ['HOME'], '.convertrc')) + cp.read(config_file) - # https://sourceforge.net/p/forge/documentation/API%20-%20Beta/ REQUEST_TOKEN_URL = base_url+'/rest/oauth/request_token' - AUTHORIZE_URL = base_url+'/rest/oauth/authorize' - ACCESS_TOKEN_URL = base_url+'/rest/oauth/access_token' + AUTHORIZE_URL = base_url+'/rest/oauth/authorize' + ACCESS_TOKEN_URL = base_url+'/rest/oauth/access_token' oauth_key = option(cp, base_url, 'oauth_key', 'Forge API OAuth Key (%s/auth/oauth/): ' % base_url) oauth_secret = option(cp, base_url, 'oauth_secret', 'Forge API Oauth Secret: ') consumer = oauth.Consumer(oauth_key, oauth_secret) @@ -114,14 +107,16 @@ def make_oauth_client(base_url): cp.set(base_url, 'oauth_token_secret', oauth_token_secret) # save oauth token for later use - cp.write(open(os.path.join(os.environ['HOME'], '.convertrc'), 'w')) + cp.write(open(config_file, 'w')) + print 'Saving oauth tokens in {} for later re-use'.format(config_file) + print access_token = oauth.Token(oauth_token, oauth_token_secret) oauth_client = oauth.Client(consumer, access_token) return oauth_client + def option(cp, section, key, prompt=None): - """ shared (copy/paste) between Allura & sfpy """ if not cp.has_section(section): cp.add_section(section) if cp.has_option(section, key):