{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/comments/58545340","id":58545340,"diff_hunk":"@@ -0,0 +1,142 @@\n+import codecs\n+import json\n+import requests\n+import six\n+\n+from kinto_client import cli_utils\n+from six.moves.urllib.parse import urljoin\n+\n+from . import constants\n+from .amo import prepare_amo_records\n+from .kinto import get_kinto_records\n+from .logger import logger\n+from .synchronize import get_diff, push_changes\n+\n+\n+FIELDS = {\n+    'add-ons': ['blockID', 'os', 'guid', 'prefs', 'versionRange', 'details'],\n+    'certificates': ['serialNumber', 'issuerName', 'details'],\n+    'gfx': ['blockID', 'os', 'vendor', 'feature', 'featureStatus',\n+            'driverVersion', 'driverVersionmax', 'driverVersionComparator',\n+            'devices', 'details'],\n+    'plugins': ['blockID', 'os', 'xpcomabi', 'infoURL', 'versionRange',\n+                'matchName', 'matchFilename', 'matchDescription', 'details']\n+}\n+\n+\n+def sync_records(amo_records, fields,\n+                 kinto_client, bucket, collection, schema, permissions):\n+\n+    amo_records = prepare_amo_records(amo_records, fields)\n+    kinto_records = get_kinto_records(\n+        kinto_client=kinto_client,\n+        bucket=bucket,\n+        collection=collection,\n+        schema=schema,\n+        permissions=permissions)\n+\n+    to_create, to_delete = get_diff(amo_records, kinto_records)\n+\n+    push_changes((to_create, to_delete), kinto_client,\n+                 bucket=bucket, collection=collection)\n+\n+\n+def main(args=None):\n+    parser = cli_utils.add_parser_options(\n+        description='Import the blocklists for AMO into Kinto.',\n+        default_collection=None,\n+        default_bucket=None,\n+        default_server=constants.KINTO_SERVER,\n+        default_auth=constants.AUTH,\n+        include_bucket=False,\n+        include_collection=False)\n+\n+    parser.add_argument('-S', '--schema-file', help='JSON Schemas file',\n+                        type=str, default=constants.SCHEMA_FILE)\n+\n+    parser.add_argument('--no-schema', help='Should we handle schemas',","path":"kinto2xml/importer.py","position":57,"original_position":57,"commit_id":"37ec0308dc038ca0c6e245cbbb23f912e506ac6a","original_commit_id":"37ec0308dc038ca0c6e245cbbb23f912e506ac6a","user":{"login":"Natim","id":229453,"avatar_url":"https://avatars.githubusercontent.com/u/229453?v=3","gravatar_id":"","url":"https://api.github.com/users/Natim","html_url":"https://github.com/Natim","followers_url":"https://api.github.com/users/Natim/followers","following_url":"https://api.github.com/users/Natim/following{/other_user}","gists_url":"https://api.github.com/users/Natim/gists{/gist_id}","starred_url":"https://api.github.com/users/Natim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Natim/subscriptions","organizations_url":"https://api.github.com/users/Natim/orgs","repos_url":"https://api.github.com/users/Natim/repos","events_url":"https://api.github.com/users/Natim/events{/privacy}","received_events_url":"https://api.github.com/users/Natim/received_events","type":"User","site_admin":false},"body":"This option is useful in case we start to see that the schema doesn't handle the data we are importing.\r\n\r\nSchema is a experimental feature in kinto so we can also have cases where we are importing on a kinto server with deactivated schema.","created_at":"2016-04-05T14:17:04Z","updated_at":"2016-04-05T14:17:05Z","html_url":"https://github.com/mozilla-services/kinto2xml/pull/3#discussion_r58545340","pull_request_url":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/comments/58545340"},"html":{"href":"https://github.com/mozilla-services/kinto2xml/pull/3#discussion_r58545340"},"pull_request":{"href":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/3","id":64152887,"html_url":"https://github.com/mozilla-services/kinto2xml/pull/3","diff_url":"https://github.com/mozilla-services/kinto2xml/pull/3.diff","patch_url":"https://github.com/mozilla-services/kinto2xml/pull/3.patch","issue_url":"https://api.github.com/repos/mozilla-services/kinto2xml/issues/3","number":3,"state":"open","locked":false,"title":"Import from amo","user":{"login":"Natim","id":229453,"avatar_url":"https://avatars.githubusercontent.com/u/229453?v=3","gravatar_id":"","url":"https://api.github.com/users/Natim","html_url":"https://github.com/Natim","followers_url":"https://api.github.com/users/Natim/followers","following_url":"https://api.github.com/users/Natim/following{/other_user}","gists_url":"https://api.github.com/users/Natim/gists{/gist_id}","starred_url":"https://api.github.com/users/Natim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Natim/subscriptions","organizations_url":"https://api.github.com/users/Natim/orgs","repos_url":"https://api.github.com/users/Natim/repos","events_url":"https://api.github.com/users/Natim/events{/privacy}","received_events_url":"https://api.github.com/users/Natim/received_events","type":"User","site_admin":false},"body":"r? @magopian","created_at":"2016-03-25T11:03:53Z","updated_at":"2016-04-05T14:17:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"884b9237d35bed986e6629a340881fc619be693a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/3/commits","review_comments_url":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/3/comments","review_comment_url":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla-services/kinto2xml/issues/3/comments","statuses_url":"https://api.github.com/repos/mozilla-services/kinto2xml/statuses/37ec0308dc038ca0c6e245cbbb23f912e506ac6a","head":{"label":"mozilla-services:import-from-amo","ref":"import-from-amo","sha":"37ec0308dc038ca0c6e245cbbb23f912e506ac6a","user":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"repo":{"id":51925233,"name":"kinto2xml","full_name":"mozilla-services/kinto2xml","owner":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla-services/kinto2xml","description":"Generate the blocklists.xml file from Kinto collections.","fork":false,"url":"https://api.github.com/repos/mozilla-services/kinto2xml","forks_url":"https://api.github.com/repos/mozilla-services/kinto2xml/forks","keys_url":"https://api.github.com/repos/mozilla-services/kinto2xml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-services/kinto2xml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-services/kinto2xml/teams","hooks_url":"https://api.github.com/repos/mozilla-services/kinto2xml/hooks","issue_events_url":"https://api.github.com/repos/mozilla-services/kinto2xml/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-services/kinto2xml/events","assignees_url":"https://api.github.com/repos/mozilla-services/kinto2xml/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-services/kinto2xml/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-services/kinto2xml/tags","blobs_url":"https://api.github.com/repos/mozilla-services/kinto2xml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-services/kinto2xml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-services/kinto2xml/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-services/kinto2xml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-services/kinto2xml/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-services/kinto2xml/languages","stargazers_url":"https://api.github.com/repos/mozilla-services/kinto2xml/stargazers","contributors_url":"https://api.github.com/repos/mozilla-services/kinto2xml/contributors","subscribers_url":"https://api.github.com/repos/mozilla-services/kinto2xml/subscribers","subscription_url":"https://api.github.com/repos/mozilla-services/kinto2xml/subscription","commits_url":"https://api.github.com/repos/mozilla-services/kinto2xml/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-services/kinto2xml/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-services/kinto2xml/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-services/kinto2xml/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla-services/kinto2xml/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-services/kinto2xml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-services/kinto2xml/merges","archive_url":"https://api.github.com/repos/mozilla-services/kinto2xml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-services/kinto2xml/downloads","issues_url":"https://api.github.com/repos/mozilla-services/kinto2xml/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-services/kinto2xml/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-services/kinto2xml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-services/kinto2xml/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-services/kinto2xml/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla-services/kinto2xml/deployments","created_at":"2016-02-17T13:40:35Z","updated_at":"2016-02-17T13:44:22Z","pushed_at":"2016-04-05T12:57:24Z","git_url":"git://github.com/mozilla-services/kinto2xml.git","ssh_url":"git@github.com:mozilla-services/kinto2xml.git","clone_url":"https://github.com/mozilla-services/kinto2xml.git","svn_url":"https://github.com/mozilla-services/kinto2xml","homepage":null,"size":98,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"mozilla-services:master","ref":"master","sha":"c737a06039d6f94c9e964ae51ef71f8c6df1ceea","user":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"repo":{"id":51925233,"name":"kinto2xml","full_name":"mozilla-services/kinto2xml","owner":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla-services/kinto2xml","description":"Generate the blocklists.xml file from Kinto collections.","fork":false,"url":"https://api.github.com/repos/mozilla-services/kinto2xml","forks_url":"https://api.github.com/repos/mozilla-services/kinto2xml/forks","keys_url":"https://api.github.com/repos/mozilla-services/kinto2xml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-services/kinto2xml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-services/kinto2xml/teams","hooks_url":"https://api.github.com/repos/mozilla-services/kinto2xml/hooks","issue_events_url":"https://api.github.com/repos/mozilla-services/kinto2xml/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-services/kinto2xml/events","assignees_url":"https://api.github.com/repos/mozilla-services/kinto2xml/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-services/kinto2xml/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-services/kinto2xml/tags","blobs_url":"https://api.github.com/repos/mozilla-services/kinto2xml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-services/kinto2xml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-services/kinto2xml/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-services/kinto2xml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-services/kinto2xml/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-services/kinto2xml/languages","stargazers_url":"https://api.github.com/repos/mozilla-services/kinto2xml/stargazers","contributors_url":"https://api.github.com/repos/mozilla-services/kinto2xml/contributors","subscribers_url":"https://api.github.com/repos/mozilla-services/kinto2xml/subscribers","subscription_url":"https://api.github.com/repos/mozilla-services/kinto2xml/subscription","commits_url":"https://api.github.com/repos/mozilla-services/kinto2xml/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-services/kinto2xml/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-services/kinto2xml/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-services/kinto2xml/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla-services/kinto2xml/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-services/kinto2xml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-services/kinto2xml/merges","archive_url":"https://api.github.com/repos/mozilla-services/kinto2xml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-services/kinto2xml/downloads","issues_url":"https://api.github.com/repos/mozilla-services/kinto2xml/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-services/kinto2xml/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-services/kinto2xml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-services/kinto2xml/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-services/kinto2xml/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla-services/kinto2xml/deployments","created_at":"2016-02-17T13:40:35Z","updated_at":"2016-02-17T13:44:22Z","pushed_at":"2016-04-05T12:57:24Z","git_url":"git://github.com/mozilla-services/kinto2xml.git","ssh_url":"git@github.com:mozilla-services/kinto2xml.git","clone_url":"https://github.com/mozilla-services/kinto2xml.git","svn_url":"https://github.com/mozilla-services/kinto2xml","homepage":null,"size":98,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/3"},"html":{"href":"https://github.com/mozilla-services/kinto2xml/pull/3"},"issue":{"href":"https://api.github.com/repos/mozilla-services/kinto2xml/issues/3"},"comments":{"href":"https://api.github.com/repos/mozilla-services/kinto2xml/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla-services/kinto2xml/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla-services/kinto2xml/statuses/37ec0308dc038ca0c6e245cbbb23f912e506ac6a"}}}}