{"action":"created","comment":{"url":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments/136434448","pull_request_review_id":59974065,"id":136434448,"diff_hunk":"@@ -0,0 +1,214 @@\n+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-\n+#\n+# Copyright (C) 2017 Canonical Ltd\n+#\n+# This program is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License version 3 as\n+# published by the Free Software Foundation.\n+#\n+# This program is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+import contextlib\n+import logging\n+import sys\n+import urllib\n+from subprocess import check_call, check_output, CalledProcessError\n+\n+import requests_unixsocket\n+from requests import exceptions\n+\n+from . import errors\n+\n+\n+logger = logging.getLogger(__name__)\n+_SNAPD_URI_ROOT_TEMPLATE = 'http+unix://%2Frun%2Fsnapd.socket/v2/{}'\n+\n+\n+class SnapPackage:\n+    \"\"\"SnapPackage acts as a mediator to install or refresh a snap.\n+\n+    It uses information provided by snapd implicitly referring to the local\n+    and remote stores to obtain information about the snap, such as its\n+    confinment value and channel availability.\n+\n+    This information can also be used determine if a snap should be\n+    installed or refreshed.\n+\n+    There are risks of the data falling out of date between the query and the\n+    requested action given that it is not possible to hold a global lock on\n+    snapd and the store data can change in between validation and execution.\n+    \"\"\"\n+\n+    @classmethod\n+    def is_valid_snap(cls, snap):\n+        return cls(snap).is_valid()\n+\n+    @classmethod\n+    def is_snap_installed(cls, snap):\n+        return cls(snap).installed\n+\n+    def __init__(self, snap):\n+        \"\"\"Lifecycle handler for a snap of the format <snap-name>/<channel>.\"\"\"\n+        self.name, self.channel = _get_parsed_snap(snap)\n+        self._original_channel = self.channel\n+        if not self.channel or self.channel == 'stable':\n+            self.channel = 'latest/stable'\n+\n+        # This store information from a local request\n+        self._local_snap_info = None\n+        # And this stores information from a remote request\n+        self._store_snap_info = None\n+\n+        self._is_installed = None\n+        self._is_on_store = None\n+\n+    @property\n+    def installed(self):\n+        if self._is_installed is None:\n+            self._is_installed = self.get_local_snap_info() is not None\n+        return self._is_installed\n+\n+    @property\n+    def on_store(self):\n+        if self._is_on_store is None:\n+            self._is_on_store = self.get_store_snap_info() is not None\n+        return self._is_on_store\n+\n+    def get_local_snap_info(self):\n+        \"\"\"Returns a local payload for the snap.\n+\n+        Validity of the results are determined by checking self.installed.\"\"\"\n+        if self._is_installed is None:\n+            with contextlib.suppress(exceptions.HTTPError):\n+                self._local_snap_info = _get_local_snap_info(self.name)\n+        return self._local_snap_info\n+\n+    def get_store_snap_info(self):\n+        \"\"\"Returns a store payload for the snap.\n+\n+        Validity of the results are determined by checking self.remote.\"\"\"\n+        if self._is_on_store is None:\n+            with contextlib.suppress(exceptions.HTTPError):\n+                self._store_snap_info = _get_store_snap_info(self.name)\n+        return self._store_snap_info\n+\n+    def _get_store_channels(self):\n+        snap_store_info = self.get_store_snap_info()\n+        if not self.on_store:\n+            return dict()\n+\n+        return snap_store_info['channels']\n+\n+    def get_current_channel(self):\n+        current_channel = ''\n+        if self.installed:\n+            local_snap_info = self.get_local_snap_info()\n+            current_channel = local_snap_info['channel']\n+            if current_channel == 'stable':\n+                current_channel = 'latest/stable'\n+        return current_channel\n+\n+    def is_classic(self):\n+        store_channels = self._get_store_channels()\n+        return store_channels[self.channel]['confinement'] == 'classic'\n+\n+    def is_valid(self):\n+        \"\"\"Check if the snap is valid.\"\"\"\n+        if not self.on_store:\n+            return False\n+        store_channels = self._get_store_channels()\n+        return self.channel in store_channels.keys()\n+\n+    def install(self):\n+        \"\"\"Installs the snap onto the system.\"\"\"\n+        snap_install_cmd = []\n+        if _snap_command_requires_sudo():\n+            snap_install_cmd = ['sudo']\n+        snap_install_cmd.extend(['snap', 'install', self.name])","path":"snapcraft/internal/repo/snaps.py","position":132,"original_position":132,"commit_id":"b160719619e7e2f92effb23689565b76478ee01c","original_commit_id":"a650e3563fe20fa84639cd22a3d7919f6a90488b","user":{"login":"kyrofa","id":946674,"avatar_url":"https://avatars0.githubusercontent.com/u/946674?v=4","gravatar_id":"","url":"https://api.github.com/users/kyrofa","html_url":"https://github.com/kyrofa","followers_url":"https://api.github.com/users/kyrofa/followers","following_url":"https://api.github.com/users/kyrofa/following{/other_user}","gists_url":"https://api.github.com/users/kyrofa/gists{/gist_id}","starred_url":"https://api.github.com/users/kyrofa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kyrofa/subscriptions","organizations_url":"https://api.github.com/users/kyrofa/orgs","repos_url":"https://api.github.com/users/kyrofa/repos","events_url":"https://api.github.com/users/kyrofa/events{/privacy}","received_events_url":"https://api.github.com/users/kyrofa/received_events","type":"User","site_admin":false},"body":"Yeah, fair enough.","created_at":"2017-08-31T20:01:10Z","updated_at":"2017-08-31T20:01:10Z","html_url":"https://github.com/snapcore/snapcraft/pull/1518#discussion_r136434448","pull_request_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/1518","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments/136434448"},"html":{"href":"https://github.com/snapcore/snapcraft/pull/1518#discussion_r136434448"},"pull_request":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/1518"}},"in_reply_to_id":136370223},"pull_request":{"url":"https://api.github.com/repos/snapcore/snapcraft/pulls/1518","id":138509606,"html_url":"https://github.com/snapcore/snapcraft/pull/1518","diff_url":"https://github.com/snapcore/snapcraft/pull/1518.diff","patch_url":"https://github.com/snapcore/snapcraft/pull/1518.patch","issue_url":"https://api.github.com/repos/snapcore/snapcraft/issues/1518","number":1518,"state":"open","locked":false,"title":"project: introduce build-snaps","user":{"login":"sergiusens","id":1146853,"avatar_url":"https://avatars2.githubusercontent.com/u/1146853?v=4","gravatar_id":"","url":"https://api.github.com/users/sergiusens","html_url":"https://github.com/sergiusens","followers_url":"https://api.github.com/users/sergiusens/followers","following_url":"https://api.github.com/users/sergiusens/following{/other_user}","gists_url":"https://api.github.com/users/sergiusens/gists{/gist_id}","starred_url":"https://api.github.com/users/sergiusens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergiusens/subscriptions","organizations_url":"https://api.github.com/users/sergiusens/orgs","repos_url":"https://api.github.com/users/sergiusens/repos","events_url":"https://api.github.com/users/sergiusens/events{/privacy}","received_events_url":"https://api.github.com/users/sergiusens/received_events","type":"User","site_admin":false},"body":"Introduce build-snaps with support for advanced grammar.","created_at":"2017-08-30T19:34:26Z","updated_at":"2017-08-31T20:01:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"24a7e0ac0b530912c722583e96b4926078754bff","assignee":{"login":"sergiusens","id":1146853,"avatar_url":"https://avatars2.githubusercontent.com/u/1146853?v=4","gravatar_id":"","url":"https://api.github.com/users/sergiusens","html_url":"https://github.com/sergiusens","followers_url":"https://api.github.com/users/sergiusens/followers","following_url":"https://api.github.com/users/sergiusens/following{/other_user}","gists_url":"https://api.github.com/users/sergiusens/gists{/gist_id}","starred_url":"https://api.github.com/users/sergiusens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergiusens/subscriptions","organizations_url":"https://api.github.com/users/sergiusens/orgs","repos_url":"https://api.github.com/users/sergiusens/repos","events_url":"https://api.github.com/users/sergiusens/events{/privacy}","received_events_url":"https://api.github.com/users/sergiusens/received_events","type":"User","site_admin":false},"assignees":[{"login":"sergiusens","id":1146853,"avatar_url":"https://avatars2.githubusercontent.com/u/1146853?v=4","gravatar_id":"","url":"https://api.github.com/users/sergiusens","html_url":"https://github.com/sergiusens","followers_url":"https://api.github.com/users/sergiusens/followers","following_url":"https://api.github.com/users/sergiusens/following{/other_user}","gists_url":"https://api.github.com/users/sergiusens/gists{/gist_id}","starred_url":"https://api.github.com/users/sergiusens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergiusens/subscriptions","organizations_url":"https://api.github.com/users/sergiusens/orgs","repos_url":"https://api.github.com/users/sergiusens/repos","events_url":"https://api.github.com/users/sergiusens/events{/privacy}","received_events_url":"https://api.github.com/users/sergiusens/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/1518/commits","review_comments_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/1518/comments","review_comment_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments{/number}","comments_url":"https://api.github.com/repos/snapcore/snapcraft/issues/1518/comments","statuses_url":"https://api.github.com/repos/snapcore/snapcraft/statuses/b160719619e7e2f92effb23689565b76478ee01c","head":{"label":"sergiusens:build-snap","ref":"build-snap","sha":"b160719619e7e2f92effb23689565b76478ee01c","user":{"login":"sergiusens","id":1146853,"avatar_url":"https://avatars2.githubusercontent.com/u/1146853?v=4","gravatar_id":"","url":"https://api.github.com/users/sergiusens","html_url":"https://github.com/sergiusens","followers_url":"https://api.github.com/users/sergiusens/followers","following_url":"https://api.github.com/users/sergiusens/following{/other_user}","gists_url":"https://api.github.com/users/sergiusens/gists{/gist_id}","starred_url":"https://api.github.com/users/sergiusens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergiusens/subscriptions","organizations_url":"https://api.github.com/users/sergiusens/orgs","repos_url":"https://api.github.com/users/sergiusens/repos","events_url":"https://api.github.com/users/sergiusens/events{/privacy}","received_events_url":"https://api.github.com/users/sergiusens/received_events","type":"User","site_admin":false},"repo":{"id":45202272,"name":"snapcraft","full_name":"sergiusens/snapcraft","owner":{"login":"sergiusens","id":1146853,"avatar_url":"https://avatars2.githubusercontent.com/u/1146853?v=4","gravatar_id":"","url":"https://api.github.com/users/sergiusens","html_url":"https://github.com/sergiusens","followers_url":"https://api.github.com/users/sergiusens/followers","following_url":"https://api.github.com/users/sergiusens/following{/other_user}","gists_url":"https://api.github.com/users/sergiusens/gists{/gist_id}","starred_url":"https://api.github.com/users/sergiusens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergiusens/subscriptions","organizations_url":"https://api.github.com/users/sergiusens/orgs","repos_url":"https://api.github.com/users/sergiusens/repos","events_url":"https://api.github.com/users/sergiusens/events{/privacy}","received_events_url":"https://api.github.com/users/sergiusens/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sergiusens/snapcraft","description":"Snapcraft is a delightful packaging tool","fork":true,"url":"https://api.github.com/repos/sergiusens/snapcraft","forks_url":"https://api.github.com/repos/sergiusens/snapcraft/forks","keys_url":"https://api.github.com/repos/sergiusens/snapcraft/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sergiusens/snapcraft/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sergiusens/snapcraft/teams","hooks_url":"https://api.github.com/repos/sergiusens/snapcraft/hooks","issue_events_url":"https://api.github.com/repos/sergiusens/snapcraft/issues/events{/number}","events_url":"https://api.github.com/repos/sergiusens/snapcraft/events","assignees_url":"https://api.github.com/repos/sergiusens/snapcraft/assignees{/user}","branches_url":"https://api.github.com/repos/sergiusens/snapcraft/branches{/branch}","tags_url":"https://api.github.com/repos/sergiusens/snapcraft/tags","blobs_url":"https://api.github.com/repos/sergiusens/snapcraft/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sergiusens/snapcraft/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sergiusens/snapcraft/git/refs{/sha}","trees_url":"https://api.github.com/repos/sergiusens/snapcraft/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sergiusens/snapcraft/statuses/{sha}","languages_url":"https://api.github.com/repos/sergiusens/snapcraft/languages","stargazers_url":"https://api.github.com/repos/sergiusens/snapcraft/stargazers","contributors_url":"https://api.github.com/repos/sergiusens/snapcraft/contributors","subscribers_url":"https://api.github.com/repos/sergiusens/snapcraft/subscribers","subscription_url":"https://api.github.com/repos/sergiusens/snapcraft/subscription","commits_url":"https://api.github.com/repos/sergiusens/snapcraft/commits{/sha}","git_commits_url":"https://api.github.com/repos/sergiusens/snapcraft/git/commits{/sha}","comments_url":"https://api.github.com/repos/sergiusens/snapcraft/comments{/number}","issue_comment_url":"https://api.github.com/repos/sergiusens/snapcraft/issues/comments{/number}","contents_url":"https://api.github.com/repos/sergiusens/snapcraft/contents/{+path}","compare_url":"https://api.github.com/repos/sergiusens/snapcraft/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sergiusens/snapcraft/merges","archive_url":"https://api.github.com/repos/sergiusens/snapcraft/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sergiusens/snapcraft/downloads","issues_url":"https://api.github.com/repos/sergiusens/snapcraft/issues{/number}","pulls_url":"https://api.github.com/repos/sergiusens/snapcraft/pulls{/number}","milestones_url":"https://api.github.com/repos/sergiusens/snapcraft/milestones{/number}","notifications_url":"https://api.github.com/repos/sergiusens/snapcraft/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sergiusens/snapcraft/labels{/name}","releases_url":"https://api.github.com/repos/sergiusens/snapcraft/releases{/id}","deployments_url":"https://api.github.com/repos/sergiusens/snapcraft/deployments","created_at":"2015-10-29T18:19:58Z","updated_at":"2016-01-28T18:31:38Z","pushed_at":"2017-08-31T19:53:46Z","git_url":"git://github.com/sergiusens/snapcraft.git","ssh_url":"git@github.com:sergiusens/snapcraft.git","clone_url":"https://github.com/sergiusens/snapcraft.git","svn_url":"https://github.com/sergiusens/snapcraft","homepage":null,"size":7504,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"snapcore:master","ref":"master","sha":"82329d253221a0b14f32a90a0c863ddb559743cf","user":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars1.githubusercontent.com/u/19532717?v=4","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"repo":{"id":45199136,"name":"snapcraft","full_name":"snapcore/snapcraft","owner":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars1.githubusercontent.com/u/19532717?v=4","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/snapcore/snapcraft","description":"Snapcraft is a delightful packaging tool","fork":false,"url":"https://api.github.com/repos/snapcore/snapcraft","forks_url":"https://api.github.com/repos/snapcore/snapcraft/forks","keys_url":"https://api.github.com/repos/snapcore/snapcraft/keys{/key_id}","collaborators_url":"https://api.github.com/repos/snapcore/snapcraft/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/snapcore/snapcraft/teams","hooks_url":"https://api.github.com/repos/snapcore/snapcraft/hooks","issue_events_url":"https://api.github.com/repos/snapcore/snapcraft/issues/events{/number}","events_url":"https://api.github.com/repos/snapcore/snapcraft/events","assignees_url":"https://api.github.com/repos/snapcore/snapcraft/assignees{/user}","branches_url":"https://api.github.com/repos/snapcore/snapcraft/branches{/branch}","tags_url":"https://api.github.com/repos/snapcore/snapcraft/tags","blobs_url":"https://api.github.com/repos/snapcore/snapcraft/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/snapcore/snapcraft/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/snapcore/snapcraft/git/refs{/sha}","trees_url":"https://api.github.com/repos/snapcore/snapcraft/git/trees{/sha}","statuses_url":"https://api.github.com/repos/snapcore/snapcraft/statuses/{sha}","languages_url":"https://api.github.com/repos/snapcore/snapcraft/languages","stargazers_url":"https://api.github.com/repos/snapcore/snapcraft/stargazers","contributors_url":"https://api.github.com/repos/snapcore/snapcraft/contributors","subscribers_url":"https://api.github.com/repos/snapcore/snapcraft/subscribers","subscription_url":"https://api.github.com/repos/snapcore/snapcraft/subscription","commits_url":"https://api.github.com/repos/snapcore/snapcraft/commits{/sha}","git_commits_url":"https://api.github.com/repos/snapcore/snapcraft/git/commits{/sha}","comments_url":"https://api.github.com/repos/snapcore/snapcraft/comments{/number}","issue_comment_url":"https://api.github.com/repos/snapcore/snapcraft/issues/comments{/number}","contents_url":"https://api.github.com/repos/snapcore/snapcraft/contents/{+path}","compare_url":"https://api.github.com/repos/snapcore/snapcraft/compare/{base}...{head}","merges_url":"https://api.github.com/repos/snapcore/snapcraft/merges","archive_url":"https://api.github.com/repos/snapcore/snapcraft/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/snapcore/snapcraft/downloads","issues_url":"https://api.github.com/repos/snapcore/snapcraft/issues{/number}","pulls_url":"https://api.github.com/repos/snapcore/snapcraft/pulls{/number}","milestones_url":"https://api.github.com/repos/snapcore/snapcraft/milestones{/number}","notifications_url":"https://api.github.com/repos/snapcore/snapcraft/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/snapcore/snapcraft/labels{/name}","releases_url":"https://api.github.com/repos/snapcore/snapcraft/releases{/id}","deployments_url":"https://api.github.com/repos/snapcore/snapcraft/deployments","created_at":"2015-10-29T17:23:15Z","updated_at":"2017-08-28T18:55:19Z","pushed_at":"2017-08-31T19:53:48Z","git_url":"git://github.com/snapcore/snapcraft.git","ssh_url":"git@github.com:snapcore/snapcraft.git","clone_url":"https://github.com/snapcore/snapcraft.git","svn_url":"https://github.com/snapcore/snapcraft","homepage":null,"size":7515,"stargazers_count":387,"watchers_count":387,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":202,"mirror_url":null,"open_issues_count":64,"forks":202,"open_issues":64,"watchers":387,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/1518"},"html":{"href":"https://github.com/snapcore/snapcraft/pull/1518"},"issue":{"href":"https://api.github.com/repos/snapcore/snapcraft/issues/1518"},"comments":{"href":"https://api.github.com/repos/snapcore/snapcraft/issues/1518/comments"},"review_comments":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/1518/comments"},"review_comment":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/1518/commits"},"statuses":{"href":"https://api.github.com/repos/snapcore/snapcraft/statuses/b160719619e7e2f92effb23689565b76478ee01c"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"kyrofa"}}