{"action":"created","comment":{"url":"https://api.github.com/repos/ccbrown/needy/pulls/comments/70173699","id":70173699,"diff_hunk":"@@ -0,0 +1,55 @@\n+import tarfile\n+import os\n+from datetime import datetime, timedelta\n+\n+from ..cache import Cache\n+\n+\n+class DirectoryCache(Cache):\n+    def __init__(self, configuration):\n+        Cache.__init__(self, configuration)\n+\n+    @staticmethod\n+    def type():\n+        return 'directory'\n+\n+    def description(self):\n+        return self.__path\n+\n+    def archive(self, source, key):\n+        destination_path = self.__archive_path(key)\n+        parent_path = os.path.dirname(destination_path)\n+        if not os.path.exists(parent_path):\n+            os.makedirs(parent_path)\n+        if os.path.exists(destination_path):\n+            os.remove(destination_path)\n+        tar = tarfile.open(destination_path, 'w:gz')\n+        tar.add(source, arcname='.')\n+        tar.close()\n+        self.__garbage_collect()\n+\n+    def unarchive(self, destination, key):\n+        tar = tarfile.open(self.__archive_path(key), 'r:gz')\n+        tar.extractall(path=destination)\n+        tar.close()\n+        os.utime(self.__archive_path(key), None)\n+\n+    def exists(self, key):\n+        return os.path.exists(self.__archive_path(key))\n+\n+    def __garbage_collect(self, min_date=datetime.now()+timedelta(weeks=-2)):\n+        for root, directories, filenames in os.walk(self.__archive_path()):\n+            for filename in filenames:\n+                path = os.path.join(root, filename)\n+                try:\n+                    mtime = os.path.getmtime(path)\n+                except OSError:\n+                    mtime = 0\n+                last_modified_date = datetime.fromtimestamp(mtime)\n+                if last_modified_date < min_date:\n+                    logging.debug('Removing older cache item {}'.format(path))\n+                    os.remove(path)","path":"needy/caches/directorycache.py","position":51,"original_position":51,"commit_id":"980724b38aeba5552a77518ce7c7b79e52ed2e72","original_commit_id":"980724b38aeba5552a77518ce7c7b79e52ed2e72","user":{"login":"vmrob","id":622110,"avatar_url":"https://avatars.githubusercontent.com/u/622110?v=3","gravatar_id":"","url":"https://api.github.com/users/vmrob","html_url":"https://github.com/vmrob","followers_url":"https://api.github.com/users/vmrob/followers","following_url":"https://api.github.com/users/vmrob/following{/other_user}","gists_url":"https://api.github.com/users/vmrob/gists{/gist_id}","starred_url":"https://api.github.com/users/vmrob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmrob/subscriptions","organizations_url":"https://api.github.com/users/vmrob/orgs","repos_url":"https://api.github.com/users/vmrob/repos","events_url":"https://api.github.com/users/vmrob/events{/privacy}","received_events_url":"https://api.github.com/users/vmrob/received_events","type":"User","site_admin":false},"body":"Yes... That's definitely a concern.\r\n\r\nI might just not know, but I was under the impression I'm touching the modified time in the last line of unarchive which is then used for gc, right? I haven't tested this yet.","created_at":"2016-07-09T23:37:11Z","updated_at":"2016-07-09T23:37:11Z","html_url":"https://github.com/ccbrown/needy/pull/67#discussion_r70173699","pull_request_url":"https://api.github.com/repos/ccbrown/needy/pulls/67","_links":{"self":{"href":"https://api.github.com/repos/ccbrown/needy/pulls/comments/70173699"},"html":{"href":"https://github.com/ccbrown/needy/pull/67#discussion_r70173699"},"pull_request":{"href":"https://api.github.com/repos/ccbrown/needy/pulls/67"}}},"pull_request":{"url":"https://api.github.com/repos/ccbrown/needy/pulls/67","id":76842046,"html_url":"https://github.com/ccbrown/needy/pull/67","diff_url":"https://github.com/ccbrown/needy/pull/67.diff","patch_url":"https://github.com/ccbrown/needy/pull/67.patch","issue_url":"https://api.github.com/repos/ccbrown/needy/issues/67","number":67,"state":"open","locked":false,"title":"Add build artifact caching","user":{"login":"vmrob","id":622110,"avatar_url":"https://avatars.githubusercontent.com/u/622110?v=3","gravatar_id":"","url":"https://api.github.com/users/vmrob","html_url":"https://github.com/vmrob","followers_url":"https://api.github.com/users/vmrob/followers","following_url":"https://api.github.com/users/vmrob/following{/other_user}","gists_url":"https://api.github.com/users/vmrob/gists{/gist_id}","starred_url":"https://api.github.com/users/vmrob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmrob/subscriptions","organizations_url":"https://api.github.com/users/vmrob/orgs","repos_url":"https://api.github.com/users/vmrob/repos","events_url":"https://api.github.com/users/vmrob/events{/privacy}","received_events_url":"https://api.github.com/users/vmrob/received_events","type":"User","site_admin":false},"body":"This patch introduces caching that can be made available with `needy cache-path set [path]` and acts as a key/value store to archive the contents of the build directory after builds. When the cache contains artifacts for a particular build, they are used instead of going through the build process.","created_at":"2016-07-09T08:38:33Z","updated_at":"2016-07-09T23:37:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d20068f8b591e9241a328a89f3b8a2a551f32af7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ccbrown/needy/pulls/67/commits","review_comments_url":"https://api.github.com/repos/ccbrown/needy/pulls/67/comments","review_comment_url":"https://api.github.com/repos/ccbrown/needy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ccbrown/needy/issues/67/comments","statuses_url":"https://api.github.com/repos/ccbrown/needy/statuses/980724b38aeba5552a77518ce7c7b79e52ed2e72","head":{"label":"vmrob:directory-cache","ref":"directory-cache","sha":"980724b38aeba5552a77518ce7c7b79e52ed2e72","user":{"login":"vmrob","id":622110,"avatar_url":"https://avatars.githubusercontent.com/u/622110?v=3","gravatar_id":"","url":"https://api.github.com/users/vmrob","html_url":"https://github.com/vmrob","followers_url":"https://api.github.com/users/vmrob/followers","following_url":"https://api.github.com/users/vmrob/following{/other_user}","gists_url":"https://api.github.com/users/vmrob/gists{/gist_id}","starred_url":"https://api.github.com/users/vmrob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmrob/subscriptions","organizations_url":"https://api.github.com/users/vmrob/orgs","repos_url":"https://api.github.com/users/vmrob/repos","events_url":"https://api.github.com/users/vmrob/events{/privacy}","received_events_url":"https://api.github.com/users/vmrob/received_events","type":"User","site_admin":false},"repo":{"id":39359329,"name":"needy","full_name":"vmrob/needy","owner":{"login":"vmrob","id":622110,"avatar_url":"https://avatars.githubusercontent.com/u/622110?v=3","gravatar_id":"","url":"https://api.github.com/users/vmrob","html_url":"https://github.com/vmrob","followers_url":"https://api.github.com/users/vmrob/followers","following_url":"https://api.github.com/users/vmrob/following{/other_user}","gists_url":"https://api.github.com/users/vmrob/gists{/gist_id}","starred_url":"https://api.github.com/users/vmrob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmrob/subscriptions","organizations_url":"https://api.github.com/users/vmrob/orgs","repos_url":"https://api.github.com/users/vmrob/repos","events_url":"https://api.github.com/users/vmrob/events{/privacy}","received_events_url":"https://api.github.com/users/vmrob/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vmrob/needy","description":"A c++ library dependency helper.","fork":true,"url":"https://api.github.com/repos/vmrob/needy","forks_url":"https://api.github.com/repos/vmrob/needy/forks","keys_url":"https://api.github.com/repos/vmrob/needy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vmrob/needy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vmrob/needy/teams","hooks_url":"https://api.github.com/repos/vmrob/needy/hooks","issue_events_url":"https://api.github.com/repos/vmrob/needy/issues/events{/number}","events_url":"https://api.github.com/repos/vmrob/needy/events","assignees_url":"https://api.github.com/repos/vmrob/needy/assignees{/user}","branches_url":"https://api.github.com/repos/vmrob/needy/branches{/branch}","tags_url":"https://api.github.com/repos/vmrob/needy/tags","blobs_url":"https://api.github.com/repos/vmrob/needy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vmrob/needy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vmrob/needy/git/refs{/sha}","trees_url":"https://api.github.com/repos/vmrob/needy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vmrob/needy/statuses/{sha}","languages_url":"https://api.github.com/repos/vmrob/needy/languages","stargazers_url":"https://api.github.com/repos/vmrob/needy/stargazers","contributors_url":"https://api.github.com/repos/vmrob/needy/contributors","subscribers_url":"https://api.github.com/repos/vmrob/needy/subscribers","subscription_url":"https://api.github.com/repos/vmrob/needy/subscription","commits_url":"https://api.github.com/repos/vmrob/needy/commits{/sha}","git_commits_url":"https://api.github.com/repos/vmrob/needy/git/commits{/sha}","comments_url":"https://api.github.com/repos/vmrob/needy/comments{/number}","issue_comment_url":"https://api.github.com/repos/vmrob/needy/issues/comments{/number}","contents_url":"https://api.github.com/repos/vmrob/needy/contents/{+path}","compare_url":"https://api.github.com/repos/vmrob/needy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vmrob/needy/merges","archive_url":"https://api.github.com/repos/vmrob/needy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vmrob/needy/downloads","issues_url":"https://api.github.com/repos/vmrob/needy/issues{/number}","pulls_url":"https://api.github.com/repos/vmrob/needy/pulls{/number}","milestones_url":"https://api.github.com/repos/vmrob/needy/milestones{/number}","notifications_url":"https://api.github.com/repos/vmrob/needy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vmrob/needy/labels{/name}","releases_url":"https://api.github.com/repos/vmrob/needy/releases{/id}","deployments_url":"https://api.github.com/repos/vmrob/needy/deployments","created_at":"2015-07-20T02:45:42Z","updated_at":"2016-03-02T23:08:06Z","pushed_at":"2016-07-09T08:41:44Z","git_url":"git://github.com/vmrob/needy.git","ssh_url":"git@github.com:vmrob/needy.git","clone_url":"https://github.com/vmrob/needy.git","svn_url":"https://github.com/vmrob/needy","homepage":null,"size":312,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"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":"ccbrown:master","ref":"master","sha":"36a5f199f5df9a5762148f75bae35880d0cb7528","user":{"login":"ccbrown","id":1731074,"avatar_url":"https://avatars.githubusercontent.com/u/1731074?v=3","gravatar_id":"","url":"https://api.github.com/users/ccbrown","html_url":"https://github.com/ccbrown","followers_url":"https://api.github.com/users/ccbrown/followers","following_url":"https://api.github.com/users/ccbrown/following{/other_user}","gists_url":"https://api.github.com/users/ccbrown/gists{/gist_id}","starred_url":"https://api.github.com/users/ccbrown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccbrown/subscriptions","organizations_url":"https://api.github.com/users/ccbrown/orgs","repos_url":"https://api.github.com/users/ccbrown/repos","events_url":"https://api.github.com/users/ccbrown/events{/privacy}","received_events_url":"https://api.github.com/users/ccbrown/received_events","type":"User","site_admin":false},"repo":{"id":36656387,"name":"needy","full_name":"ccbrown/needy","owner":{"login":"ccbrown","id":1731074,"avatar_url":"https://avatars.githubusercontent.com/u/1731074?v=3","gravatar_id":"","url":"https://api.github.com/users/ccbrown","html_url":"https://github.com/ccbrown","followers_url":"https://api.github.com/users/ccbrown/followers","following_url":"https://api.github.com/users/ccbrown/following{/other_user}","gists_url":"https://api.github.com/users/ccbrown/gists{/gist_id}","starred_url":"https://api.github.com/users/ccbrown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccbrown/subscriptions","organizations_url":"https://api.github.com/users/ccbrown/orgs","repos_url":"https://api.github.com/users/ccbrown/repos","events_url":"https://api.github.com/users/ccbrown/events{/privacy}","received_events_url":"https://api.github.com/users/ccbrown/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ccbrown/needy","description":"A C++ library dependency helper.","fork":false,"url":"https://api.github.com/repos/ccbrown/needy","forks_url":"https://api.github.com/repos/ccbrown/needy/forks","keys_url":"https://api.github.com/repos/ccbrown/needy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ccbrown/needy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ccbrown/needy/teams","hooks_url":"https://api.github.com/repos/ccbrown/needy/hooks","issue_events_url":"https://api.github.com/repos/ccbrown/needy/issues/events{/number}","events_url":"https://api.github.com/repos/ccbrown/needy/events","assignees_url":"https://api.github.com/repos/ccbrown/needy/assignees{/user}","branches_url":"https://api.github.com/repos/ccbrown/needy/branches{/branch}","tags_url":"https://api.github.com/repos/ccbrown/needy/tags","blobs_url":"https://api.github.com/repos/ccbrown/needy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ccbrown/needy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ccbrown/needy/git/refs{/sha}","trees_url":"https://api.github.com/repos/ccbrown/needy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ccbrown/needy/statuses/{sha}","languages_url":"https://api.github.com/repos/ccbrown/needy/languages","stargazers_url":"https://api.github.com/repos/ccbrown/needy/stargazers","contributors_url":"https://api.github.com/repos/ccbrown/needy/contributors","subscribers_url":"https://api.github.com/repos/ccbrown/needy/subscribers","subscription_url":"https://api.github.com/repos/ccbrown/needy/subscription","commits_url":"https://api.github.com/repos/ccbrown/needy/commits{/sha}","git_commits_url":"https://api.github.com/repos/ccbrown/needy/git/commits{/sha}","comments_url":"https://api.github.com/repos/ccbrown/needy/comments{/number}","issue_comment_url":"https://api.github.com/repos/ccbrown/needy/issues/comments{/number}","contents_url":"https://api.github.com/repos/ccbrown/needy/contents/{+path}","compare_url":"https://api.github.com/repos/ccbrown/needy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ccbrown/needy/merges","archive_url":"https://api.github.com/repos/ccbrown/needy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ccbrown/needy/downloads","issues_url":"https://api.github.com/repos/ccbrown/needy/issues{/number}","pulls_url":"https://api.github.com/repos/ccbrown/needy/pulls{/number}","milestones_url":"https://api.github.com/repos/ccbrown/needy/milestones{/number}","notifications_url":"https://api.github.com/repos/ccbrown/needy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ccbrown/needy/labels{/name}","releases_url":"https://api.github.com/repos/ccbrown/needy/releases{/id}","deployments_url":"https://api.github.com/repos/ccbrown/needy/deployments","created_at":"2015-06-01T11:26:57Z","updated_at":"2016-07-08T17:39:47Z","pushed_at":"2016-07-09T08:41:45Z","git_url":"git://github.com/ccbrown/needy.git","ssh_url":"git@github.com:ccbrown/needy.git","clone_url":"https://github.com/ccbrown/needy.git","svn_url":"https://github.com/ccbrown/needy","homepage":"https://ccbrown.github.com/needy","size":320,"stargazers_count":47,"watchers_count":47,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":3,"mirror_url":null,"open_issues_count":14,"forks":3,"open_issues":14,"watchers":47,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ccbrown/needy/pulls/67"},"html":{"href":"https://github.com/ccbrown/needy/pull/67"},"issue":{"href":"https://api.github.com/repos/ccbrown/needy/issues/67"},"comments":{"href":"https://api.github.com/repos/ccbrown/needy/issues/67/comments"},"review_comments":{"href":"https://api.github.com/repos/ccbrown/needy/pulls/67/comments"},"review_comment":{"href":"https://api.github.com/repos/ccbrown/needy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ccbrown/needy/pulls/67/commits"},"statuses":{"href":"https://api.github.com/repos/ccbrown/needy/statuses/980724b38aeba5552a77518ce7c7b79e52ed2e72"}}}}
{"actor":{"display_login":"vmrob"}}