Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement project admin commands. Fixes #8 #26

Merged
merged 19 commits into from
Oct 11, 2017
Merged

Implement project admin commands. Fixes #8 #26

merged 19 commits into from
Oct 11, 2017

Conversation

tvirolai
Copy link
Contributor

@tvirolai tvirolai commented Oct 9, 2017

A basic implementation for project administration commands. The annif init command also now checks for orphaned indexes and removes them if necessary.

@tvirolai tvirolai requested a review from osma October 9, 2017 16:21
Copy link
Member

@osma osma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good. However, I'm not sure that the commands use the optimal output format. Especially the show-project output looks messy.

How about using a multiple column format similar to the virsh tool that is used for managing KVM virtual machines? See https://www.centos.org/docs/5/html/5.2/Virtualization/sect-Virtualization-Commands_for_Red_Hat_Virtualization-virsh_the_command_line_interface_tool_for_virtualization.html for some examples.

The show-project command could use a key-value output format similar to the virsh dominfo command.

@tvirolai
Copy link
Contributor Author

Very true. I'll look into this.

@tvirolai
Copy link
Contributor Author

tvirolai commented Oct 10, 2017

Now show-project produces output formatted like this:

$ annif show-project herttilei
details about project 'herttilei':

project name:        herttilei
project language:  en
project analyzer:   english
index:                    annif
score:                    0.2876821

list-projects works like this:

(annif_env) ➜  annif git:(issue8) annif list-projects                                               
Currently available projects:

1. herttilei (language: en, analyzer: english)
2. jaahas (language: armenian, analyzer: armenia)

What do you think?

@osma
Copy link
Member

osma commented Oct 10, 2017

Much better now. In show-project output, score is completely useless and index is probably redundant too.

@tvirolai
Copy link
Contributor Author

Ok, I'll remove 'em.

@osma
Copy link
Member

osma commented Oct 10, 2017

How about this mocked up output style:

$ annif list-projects
Project ID     Language   Analyzer
----------------------------------
herttilei      en         english
jaahas         armenian   armenia
$ annif show-project herttilei
Project ID: herttilei
Language:   en
Analyzer:   english

@tvirolai
Copy link
Contributor Author

I also tweaked the test so that running them doesn't affect any other indices that may be in the database.

@tvirolai
Copy link
Contributor Author

Ok, looks nice. I'll update.

@osma
Copy link
Member

osma commented Oct 10, 2017

list-projects now fails for me with this error:

  File "/home/ozone/git/Annif/annif/annif.py", line 87, in listprojects
    parsed += parseRow(p['name'], p['language'], p['analyzer'])
  File "/home/ozone/git/Annif/annif/annif.py", line 81, in parseRow
    return "{0: <15}{1: <15}{2: <15}\n".format(col1, col2, col3)
TypeError: non-empty format string passed to object.__format__

@tvirolai
Copy link
Contributor Author

Weird. The only way I managed to reproduce this error was to first create a project with insufficient arguments (e.g. provide only a name but not language or analyzer information) and then try to list the available projects.

Creating projects with insufficient arguments is no longer possible but it seems that the code analyzers now deem the createProject function too complex. I'll refactor.

@osma
Copy link
Member

osma commented Oct 10, 2017

That's probably the reason. I had created the project without specifying all the parameters.

annif/annif.py Outdated
# Create an index for the project
index.create(index=proj_indexname)
if not projectid or not language or not analyzer:
print('Usage: annif create-project <projectId> --language <lang>'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a space after <lang>

annif/annif.py Outdated
projects = [x['_source'] for x in results['hits']['hits']]

def parseRow(col1, col2, col3):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick on naming: I would call this function formatRow, not parseRow. What it does is the opposite of parsing...

annif/annif.py Outdated
@@ -32,10 +33,15 @@
}


def parseIndexname(projectid):
def parse_indexname(projectid):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be format_indexname or even better format_index_name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, fixing.

assert not index.exists(annif.parse_indexname(FAILED_PROJECT))


def test_showproject():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to test_show_project?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes.



def test_dropProject():
result = runner.invoke(annif.dropProject, [TEMP_PROJECT])
def test_dropproject():
Copy link
Member

@osma osma Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, test_drop_project

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest commit.

@@ -25,31 +30,51 @@ def test_start():

def test_init():
result = runner.invoke(annif.init)
assert index.exists('annif')
assert index.exists(annif.annif.config['INDEX_NAME'])
assert result.exit_code == 0


def test_listprojects():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to test_list_projects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest commit.

@tvirolai tvirolai merged commit 29db2c6 into master Oct 11, 2017
@tvirolai tvirolai deleted the issue8 branch October 11, 2017 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants