Hi,
Here are some patches for the copr-cli.
- Fix the exception generated when trying to read the copr_url from a non-existant configuration file - I rework the layout of the copr-cli list command, the table was not scaling with projects having large description - Add a man page for copr-cli to provide a little more documentation on where and how to set the configuration file and what it should contain
With the changes made, at the end I went for bumping the version number to 0.2.0.
We might want to use the same version in the CLI as in the server. We won't be able to import __version__ from the server as the CLI is independant from the server, so we'll have to do this by hand.
Hope this helps, Pierre
[PATCH 1/5] Fix parsing the copr_url from the configuration file [PATCH 2/5] Rework the layout of the list command [PATCH 3/5] Add a man page for copr-cli [PATCH 4/5] Refer to the man page for more information about the [PATCH 5/5] Bump the copr-cli release to 0.2.0 with all the changes
This was resulting in exceptions beeing thrown with a command as simple as: `copr_cli list pingou` --- copr_cli/subcommands.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/copr_cli/subcommands.py b/copr_cli/subcommands.py index 56b2d6d..dc2ddb0 100644 --- a/copr_cli/subcommands.py +++ b/copr_cli/subcommands.py @@ -33,11 +33,15 @@ def get_user():
def get_api_url(): """ Retrieve the user information from the config file. """ - config = ConfigParser.ConfigParser( - {'copr_url': 'http://copr-fe.cloud.fedoraproject.org%27%7D) - config.read(os.path.join(os.path.expanduser('~'), '.config', - 'copr')) - copr_url = config.get('copr-cli', 'copr_url') + config = ConfigParser.ConfigParser() + config.read( + os.path.join(os.path.expanduser('~'), '.config', 'copr') + ) + + # Default copr_url: + copr_url = 'http://copr-fe.cloud.fedoraproject.org/' + if config.has_section('copr-cli'): + copr_url = config.get('copr-cli', 'copr_url') return '%s/api' % copr_url
Instead of the table that was getting completely twisted by large description, use a more simpler tree/list type of layout. --- copr_cli/subcommands.py | 79 ++++++++++++++++--------------------------------- 1 file changed, 25 insertions(+), 54 deletions(-)
diff --git a/copr_cli/subcommands.py b/copr_cli/subcommands.py index dc2ddb0..57da934 100644 --- a/copr_cli/subcommands.py +++ b/copr_cli/subcommands.py @@ -17,8 +17,8 @@ import copr_exceptions def get_user(): """ Retrieve the user information from the config file. """ config = ConfigParser.ConfigParser() - if not config.read(os.path.join(os.path.expanduser('~'), '.config', - 'copr')): + if not config.read( + os.path.join(os.path.expanduser('~'), '.config', 'copr')): raise copr_exceptions.CoprCliNoConfException( 'No configuration file "~/.config/copr" found.') try: @@ -70,62 +70,33 @@ def listcoprs(username=None): return
output = json.loads(req.text) - columns = [] - values = [] + if 'repos' in output: if output['repos']: - columns = ['name', 'description', 'yum_repos', 'additional_repos', 'instructions'] - values = [] - for entry in output['repos']: - values.append([entry[key] for key in columns]) - else: - columns = ['output'] - values = ['No copr retrieved for user: "{0}"'.format( - user['username'])] - else: - columns = ['output'] - values = ['Wrong output format returned by the server'] - - def _list_to_row(values, widths): - ''' Return a print ready version of the provided list ''' - row = [] - cnt = 0 - for item in values: - max_width = widths[cnt] - cnt += 1 - if not item: - item = '' - if cnt < len(values): - row.append(item.ljust(max_width + 1)) - else: - row.append(item) - return row - - if len(columns) > 1: - widths = {} - cnt = 0 - for item in columns: - widths[cnt] = len(item) - cnt += 1 - for row in values: - cnt = 0 - for item in row: - if not item: - item = '' - widths[cnt] = max(widths[cnt], len(item)) - cnt += 1 - - headers = '|'.join(_list_to_row(columns, widths)) - print headers - print '-' * len(headers) - for row in values: - print "|".join(_list_to_row(row, widths)) + for repo in output['repos']: + print 'Name: {0}'.format(repo['name']) + + if 'description' in repo: + desc = repo['description'] + print ' ' * 5, 'Description: {0}'.format(desc)
+ if 'yum_repos' in repo: + yum_repos = repo['yum_repos'] + print ' ' * 5, 'Yum repo: {0}'.format(yum_repos) + + if 'additional_repos' in repo: + add_repos = repo['additional_repos'] + print ' ' * 5, 'Additional repos: {0}'.format(add_repos) + + if 'instructions' in repo: + instructions = repo['instructions'] + print ' ' * 5, 'Instructions: {0}'.format(instructions) + + else: + print 'No copr retrieved for user: "{0}"'.format( + user['username']) else: - headers = columns[0] - print headers - print "-"*len(headers) - print values[0] + print 'Un-expected data returned, please report this issue'
def create(name, chroots=[], description=None, instructions=None,
--- copr_cli/copr-cli.1 | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 copr_cli/copr-cli.1
diff --git a/copr_cli/copr-cli.1 b/copr_cli/copr-cli.1 new file mode 100644 index 0000000..f5f378f --- /dev/null +++ b/copr_cli/copr-cli.1 @@ -0,0 +1,70 @@ +.TH "copr-cli" 1 +.SH NAME +copr-cli - A command line interface to COPR. + +.SH SYNOPSIS +.B copr-cli +list [user name] +.br +.B copr-cli +create <name> +.br +.B copr-cli +build <copr> <url to srpm> + +.SH DESCRIPTION + +This tools allows using copr from the command line rather than going onto +the web application. + +.SH USAGE +.HP +copr-cli list [user name] + +It will return you the list and information of all the COPR made by the +specified user. If no user is precised it will rely on the configuration +file to extract your username and will return all your COPR. + +.HP +copr-cli create [copr name] + +This will create a new COPR with the specified name. It will rely on the +presence of the configuration file to extract your authentication +information. + +.HP +copr-cli build [copr name] [url to srpm] + +This will build the provided srpm into the specified COPR. It will rely on +the presence of the configuration file to extract your authentication +information. + + +.SH OPTIONS +.B -h / --help + Displays the generic help message or specific to an action. +.sp +.B -v / --version + Displays the version of copr-cli. +.sp + +.SH CONFIGURATION +.I $HOME/.conf/copr +.RS +In this configuration file, you may enter your authentication information. +These information contain the username and API token that can be used to +identify you to the COPR API and allow copr-cli to work as expected. +.PP +Your configuration file should look like: +.IP "" 4 + [copr-cli] + username = <insert here your API login> + token = <insert here your API token> +.RE + +.SH AUTHORS + Pierre-Yves Chibon pingou@pingoured.fr + +.sp +.sp +No known bugs at this time
--- copr_cli/subcommands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/copr_cli/subcommands.py b/copr_cli/subcommands.py index 57da934..28a761a 100644 --- a/copr_cli/subcommands.py +++ b/copr_cli/subcommands.py @@ -20,7 +20,8 @@ def get_user(): if not config.read( os.path.join(os.path.expanduser('~'), '.config', 'copr')): raise copr_exceptions.CoprCliNoConfException( - 'No configuration file "~/.config/copr" found.') + 'No configuration file "~/.config/copr" found. ' + 'See man copr-cli for more information') try: username = config.get('copr-cli', 'username', None) login = config.get('copr-cli', 'login', None)
--- copr_cli/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/copr_cli/main.py b/copr_cli/main.py index ca29017..e0e8cad 100644 --- a/copr_cli/main.py +++ b/copr_cli/main.py @@ -6,7 +6,7 @@ import sys import subcommands import copr_exceptions
-__version__ = '0.1.0' +__version__ = '0.2.0' __description__ = "CLI tool to run copr"
On 11/27/2013 08:42 PM, Pierre-Yves Chibon wrote:
Hi,
Here are some patches for the copr-cli.
- Fix the exception generated when trying to read the copr_url from a
non-existant configuration file
- I rework the layout of the copr-cli list command, the table was not scaling
with projects having large description
- Add a man page for copr-cli to provide a little more documentation on where
and how to set the configuration file and what it should contain
Just for the record - we already discuss it on IRC yesterday: copr-cli already have man page man/copr-cli.1.asciidoc everything if fine. I forgot that you have write access, so feel free to push it.
With the changes made, at the end I went for bumping the version number to 0.2.0.
We might want to use the same version in the CLI as in the server. We won't be able to import __version__ from the server as the CLI is independant from the server, so we'll have to do this by hand.
I do not like having version in code. I think that tracking of version is task of distribution: $ rpm -q copr-cli copr-cli-1.14-1.git.29.4ef718d.fc20.noarch is IMHO right approach. Hmm. I will look if I can use that new class FileVersionTagger from tito and leave this versions bumpups on Tito.
Mirek
On Thu, Nov 28, 2013 at 06:14:23AM +0100, Miroslav Suchy wrote:
On 11/27/2013 08:42 PM, Pierre-Yves Chibon wrote:
Hi,
Here are some patches for the copr-cli.
- Fix the exception generated when trying to read the copr_url from a
non-existant configuration file
- I rework the layout of the copr-cli list command, the table was not scaling
with projects having large description
- Add a man page for copr-cli to provide a little more documentation on where
and how to set the configuration file and what it should contain
Just for the record - we already discuss it on IRC yesterday: copr-cli already have man page man/copr-cli.1.asciidoc everything if fine. I forgot that you have write access, so feel free to push it.
With the changes made, at the end I went for bumping the version number to 0.2.0.
We might want to use the same version in the CLI as in the server. We won't be able to import __version__ from the server as the CLI is independant from the server, so we'll have to do this by hand.
So shall I push all of them? We can always fix the version later on :)
Thanks, Pierre
On 11/28/2013 11:46 AM, Pierre-Yves Chibon wrote:
So shall I push all of them? We can always fix the version later on
I pushed it on your behalf - I already had to solve huge conflict on that main commit. But better now, than later, when the conflict would be even bigger.
Thanks for contribution.
copr-devel@lists.fedorahosted.org