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

Add CLI utilities to Kinto.py #34

Closed
wants to merge 12 commits into from
Closed

Add CLI utilities to Kinto.py #34

wants to merge 12 commits into from

Conversation

Natim
Copy link
Member

@Natim Natim commented Jan 18, 2016

The final aims is to let people easily create sync between a collection and a local data store (usually built from files)

class DummyImporter(KintoImporter):
collection_permissions = {'read': ["system.Everyone"]}
fields = ('name', 'protocol')
set_all = True
Copy link
Member

Choose a reason for hiding this comment

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

this option needs to be more explicit.

class DummyImporter(KintoImporter):
all_default_parameters = True
collection_permissions = {'read': ["system.Everyone"]}
fields = ('name', 'protocol')
Copy link
Member

Choose a reason for hiding this comment

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

record_fields then?

@Natim
Copy link
Member Author

Natim commented Jan 22, 2016

r? @leplatrem

@@ -0,0 +1,34 @@
#!/usr/bin/env python
Copy link
Member

Choose a reason for hiding this comment

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

I like the idea of having an example, but I feel that this will get out of date as soon as we start updating the importer. We probably should move this into a test case, and point the users there in the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: importation is rarely used in the context of importing data

all_default_parameters=None, remote_server=None,
authentication=None, files=None, verbosity=None,
*args, **kwargs):
"""Return an argparse.ArgumentParser pre-configured object."""
Copy link
Member

Choose a reason for hiding this comment

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

The docstring should contain some more information about the arguments it expects, and what it does with the extra args/kwargfs.

@@ -1,24 +1,24 @@
import unittest2 as unittest
import mock

from kinto_client.batch import Batch
from kinto_client.batch import Session
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: as BatchSession ?

@leplatrem
Copy link
Contributor

I didn't review the tests thoroughly.

My general feeling would be a friendly warning: do not forget the simplest use-cases like this one https://gist.github.com/leplatrem/a2d95b660820686eea35

@Natim Natim force-pushed the import_cli_utilities branch 2 times, most recently from 6ffc0b9 to 02c082b Compare January 28, 2016 17:25
@Natim
Copy link
Member Author

Natim commented Jan 29, 2016

I think something like that should work:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from kinto_client.importer import KintoImporter


class GuessSignImporter(KintoImporter):
    include_all_default_parameters = True

    default_remote_server = "https://kinto-leplatrem.herokuapp.com/v1"
    default_auth = 'admin:password'
    default_files = ["guessign/data/it.json"]

    collection_permissions = {'read': ["system.Everyone"]}
    record_fields = ('class', 'word', 'class:id', 'magnet',
                     'category', 'video', 'lang')

    delete = False

    def get_local_records(self):
        results = []
        with open(file) as f:
            results += json.load(f)
        return results


def main(args=None):
    importer = GuessSignImporter()
    importer.sync()


if __name__ == '__main__':  # pragma: nocover
    main()

"""Update out-of-date records."""
update = True
"""Delete records not present in local-files."""
delete = True
Copy link
Member Author

Choose a reason for hiding this comment

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

create_missing_locally
update_missing_locally
delete_missing_locally

@almet almet mentioned this pull request Feb 1, 2016
@Natim Natim mentioned this pull request Feb 11, 2016
@almet
Copy link
Member

almet commented Feb 11, 2016

I suppose we can close this then, since #59 is being worked out.

@almet almet closed this Feb 11, 2016
@almet almet removed the in progress label Feb 11, 2016
@Natim Natim deleted the import_cli_utilities branch March 8, 2016 13:28
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

3 participants