Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit c9293f7fadfb01abe7b7a974b06873925bbd56aa
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Sun Mar 10 09:56:15 2013 +0100
Handle expired API token and rename list function to listcoprs
---------------------------------------------------------------
copr_cli/main.py | 2 +-
copr_cli/subcommands.py | 29 ++++++++++++++++++++++++-----
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/copr_cli/main.py b/copr_cli/main.py
index 8dc35e4..449a3fa 100644
--- a/copr_cli/main.py
+++ b/copr_cli/main.py
@@ -40,7 +40,7 @@ def action_list(args):
:param args: argparse arguments provided by the user
"""
- subcommands.list(args.username)
+ subcommands.listcoprs(args.username)
def setup_parser():
diff --git a/copr_cli/subcommands.py b/copr_cli/subcommands.py
index 2931ca6..dc76dfb 100644
--- a/copr_cli/subcommands.py
+++ b/copr_cli/subcommands.py
@@ -41,7 +41,7 @@ def get_api_url():
return '%s/api' % copr_url
-def list(username=None):
+def listcoprs(username=None):
""" List all the copr of a user. """
user = {}
if not username:
@@ -55,6 +55,16 @@ def list(username=None):
user['username'] = username
req = requests.get(url, params=user)
+
+ if '<title>Sign in Coprs</title>' in req.text:
+ print 'Invalid API token'
+ return
+
+ output = json.loads(req.text)
+ if req.status_code != 200:
+ print 'Something went wrong:\n {0}'.format(output['error'])
+ return
+
output = json.loads(req.text)
columns = []
values = []
@@ -140,11 +150,15 @@ def create(name, chroots=[], description=None, instructions=None,
req = requests.post(URL,
auth=(user['username'], user['token']),
data=data)
+ if '<title>Sign in Coprs</title>' in req.text:
+ print 'Invalid API token'
+ return
+
output = json.loads(req.text)
- if output['output'] == 'ok':
- print output['message']
+ if req.status_code != 200:
+ print 'Something went wrong:\n {0}'.format(output['error'])
else:
- print 'Something went wrong:\n {0}'.format(output['error'])
+ print output['message']
def build(copr, pkgs, memory, timeout):
@@ -164,8 +178,13 @@ def build(copr, pkgs, memory, timeout):
req = requests.post(URL,
auth=(user['username'], user['token']),
data=data)
+
+ if '<title>Sign in Coprs</title>' in req.text:
+ print 'Invalid API token'
+ return
+
output = json.loads(req.text)
if req.status_code != 200:
- print 'Something went wrong:\n {0}'.format(output['error'])
+ print 'Something went wrong:\n {0}'.format(output['error'])
else:
print output['message']