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

Issue251 cli init command #306

Merged
merged 10 commits into from
Aug 23, 2019
22 changes: 22 additions & 0 deletions annif/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,28 @@ def run_show_project(project_id):
click.echo(template.format('Access:', proj.access.name))


@cli.command('init')
@click.argument('project_id')
@common_options
def run_init_project(project_id):
"""
Remove the data files of a project.
juhoinkinen marked this conversation as resolved.
Show resolved Hide resolved
"""

proj = get_project(project_id)
datadir_path = proj.datadir
data_files = os.listdir(datadir_path)
if data_files:
for data_file in data_files:
juhoinkinen marked this conversation as resolved.
Show resolved Hide resolved
os.remove(os.path.join(datadir_path, data_file))
click.echo('Removed data files for project {}.'.format(project_id))
else:
click.echo(
'No data files to remove for project {}.'.format(project_id),
err=True)
sys.exit(1)


@cli.command('loadvoc')
@click.argument('project_id')
@click.argument('subjectfile', type=click.Path(dir_okay=False))
Expand Down
22 changes: 22 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@ def test_show_project_nonexistent():
assert failed_result.exception


def test_init_project(testdatadir):
dirpath = os.path.join(str(testdatadir), 'projects', 'dummy-fi')
fpath = os.path.join(str(dirpath), 'test_init_project_datafile')
os.makedirs(dirpath)
open(fpath, 'a').close()

assert runner.invoke(
annif.cli.cli,
['init', 'dummy-fi']).exit_code == 0
assert not os.path.exists(fpath)


def test_init_project_nonexistent(testdatadir):
runner.invoke(
osma marked this conversation as resolved.
Show resolved Hide resolved
annif.cli.cli,
['init', 'dummy-fi']).exit_code != 0
# Nonexistent project:
runner.invoke(
annif.cli.cli,
['init', TEMP_PROJECT]).exit_code != 0


def test_loadvoc_tsv(testdatadir):
with contextlib.suppress(FileNotFoundError):
os.remove(str(testdatadir.join('projects/tfidf-fi/subjects')))
Expand Down