[PATCH 4/4] Move the URL to copr into the config file
Pierre-Yves Chibon
pingou at pingoured.fr
Sun Feb 17 19:57:44 UTC 2013
This way one can use another copr server than the one provided by the Fedora Project.
Additionnaly, we rename the function set_user to get_user, semantically more appropriate.
---
copr_cli/main.py | 13 +++++--------
copr_cli/subcommands.py | 31 ++++++++++++++++++++++---------
2 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/copr_cli/main.py b/copr_cli/main.py
index 5cc7e51..51da88e 100644
--- a/copr_cli/main.py
+++ b/copr_cli/main.py
@@ -9,9 +9,6 @@ __version__ = '0.1.0'
__description__ = "CLI tool to run copr"
-COPR_URL = 'http://copr-fe.cloud.fedoraproject.org/'
-COPR_API_URL = '{0}/api'.format(COPR_URL)
-
CMDLIST = ['create', 'build', 'list', 'info']
@@ -94,15 +91,15 @@ def main(argv=sys.argv[1:]):
args = action_parser.parse_args(arg.argument)
if action == "list":
- subcommands.list(COPR_API_URL, args.username)
+ subcommands.list(args.username)
elif action == "create":
- subcommands.create(COPR_API_URL, args.name, args.chroots,
- args.description, args.instructions,
- args.repos, args.initial_pkgs)
+ subcommands.create(args.name, args.chroots, args.description,
+ args.instructions, args.repos,
+ args.initial_pkgs)
elif action == "build":
- subcommands.build(COPR_API_URL, args.copr, args.pkgs,
+ subcommands.build(args.copr, args.pkgs,
args.memory, args.timeout)
diff --git a/copr_cli/subcommands.py b/copr_cli/subcommands.py
index f2cdd5b..ab494a1 100644
--- a/copr_cli/subcommands.py
+++ b/copr_cli/subcommands.py
@@ -7,7 +7,7 @@ import os
import sys
-def set_user():
+def get_user():
""" Retrieve the user information from the config file. """
config = ConfigParser.ConfigParser()
config.read(os.path.join(os.path.expanduser('~'), '.config',
@@ -17,14 +17,25 @@ def set_user():
return {'username': username, 'token': token}
-def list(copr_api_url, username=None):
+def get_api_url():
+ """ Retrieve the user information from the config file. """
+ config = ConfigParser.ConfigParser()
+ config.read(os.path.join(os.path.expanduser('~'), '.config',
+ 'copr'))
+ copr_url = config.get('copr-cli', 'copr_url',
+ 'http://copr-fe.cloud.fedoraproject.org/')
+ return '%s/api/' % copr_url
+
+
+def list(username=None):
""" List all the copr of a user. """
- user = set_user()
+ user = get_user()
+ copr_api_url = get_api_url()
+ URL = '{0}/owned/'.format(copr_api_url)
if username:
user['username'] = username
- URL = '{0}/owned/'.format(copr_api_url)
req = requests.get(URL, params=user)
output = json.loads(req.text)
if 'repos' in output:
@@ -45,10 +56,11 @@ def list(copr_api_url, username=None):
return (columns, [values])
-def create(copr_api_url, name, chroots=[],description=None,
- instructions=None, repos=None, initial_pkgs=None):
+def create(name, chroots=[],description=None, instructions=None,
+ repos=None, initial_pkgs=None):
""" Create a new copr. """
- user = set_user()
+ user = get_user()
+ copr_api_url = get_api_url()
URL = '{0}/copr/new/'.format(copr_api_url)
repos = None
@@ -76,9 +88,10 @@ def create(copr_api_url, name, chroots=[],description=None,
print 'Something went wrong:\n {0}'.format(output['error'])
-def build(copr_api_url, copr, pkgs, memory, timeout):
+def build(copr, pkgs, memory, timeout):
""" Build a new package into a given copr. """
- user = set_user()
+ user = get_user()
+ copr_api_url = get_api_url()
URL = '{0}/coprs/detail/{1}/{2}/new_build/'.format(
copr_api_url,
user['username'],
--
1.8.1.2
More information about the copr-devel
mailing list