{"action":"created","comment":{"url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/comments/36857157","id":36857157,"diff_hunk":"@@ -198,12 +200,170 @@ def _pop_catalog(self):\n \n \n \n-class Repository:\n-    \"\"\" Abstract Wrapper around a CVMFS Repository representation \"\"\"\n+class Cache:\n+    def __init__(self, cache_dir, metadata_cleanup):\n+        if not os.path.exists(cache_dir):\n+            cache_dir = tempfile.mkdtemp(dir='/tmp', prefix='cache.')\n+        self._cache_dir = cache_dir\n+        self._create_cache_structure()\n+        if metadata_cleanup:\n+            self._cleanup_metadata()\n+\n+    def _cleanup_metadata(self):\n+        for f in glob.glob(self._cache_dir + '/' + '.cvmfs*'):\n+            os.remove(f)\n+\n+\n+    def _create_dir(self, path):\n+        cache_full_path = '/'.join([self._cache_dir, path])\n+        if not os.path.exists(cache_full_path):\n+            os.mkdir(cache_full_path, 0755)\n+\n+\n+    def _create_cache_structure(self):\n+        self._create_dir('data')\n+        for i in range(0x00, 0xff + 1):\n+            new_folder = '{0:#0{1}x}'.format(i, 4)[2:]\n+            self._create_dir('data' + '/' + new_folder)\n+\n+\n+    def cache_path(self):\n+        return str(self._cache_dir)\n+\n+\n+    def add(self, file_name):\n+        full_path = '/'.join([self._cache_dir, file_name])\n+        return open(full_path, 'w+')\n+\n+\n+    def get(self, file_name):\n+        full_path = '/'.join([self._cache_dir, file_name])\n+        if os.path.exists(full_path):\n+            return open(full_path, 'rb')\n+        return None\n+\n+\n+    def evict(self):\n+        for i in range(0x00, 0xff + 1):","path":"python/cvmfs/repository.py","position":66,"original_position":66,"commit_id":"df822ab7ba1536607ae6098070fdfa0e2c11ca03","original_commit_id":"df822ab7ba1536607ae6098070fdfa0e2c11ca03","user":{"login":"reneme","id":1562139,"avatar_url":"https://avatars.githubusercontent.com/u/1562139?v=3","gravatar_id":"","url":"https://api.github.com/users/reneme","html_url":"https://github.com/reneme","followers_url":"https://api.github.com/users/reneme/followers","following_url":"https://api.github.com/users/reneme/following{/other_user}","gists_url":"https://api.github.com/users/reneme/gists{/gist_id}","starred_url":"https://api.github.com/users/reneme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reneme/subscriptions","organizations_url":"https://api.github.com/users/reneme/orgs","repos_url":"https://api.github.com/users/reneme/repos","events_url":"https://api.github.com/users/reneme/events{/privacy}","received_events_url":"https://api.github.com/users/reneme/received_events","type":"User","site_admin":false},"body":"maybe just recursively clean out the whole directory and rebuild with `_create_cache_structure()`?","created_at":"2015-08-12T13:12:28Z","updated_at":"2015-08-12T13:12:28Z","html_url":"https://github.com/cvmfs/cvmfs/pull/1043#discussion_r36857157","pull_request_url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1043","_links":{"self":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/comments/36857157"},"html":{"href":"https://github.com/cvmfs/cvmfs/pull/1043#discussion_r36857157"},"pull_request":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1043"}}},"pull_request":{"url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1043","id":42235148,"html_url":"https://github.com/cvmfs/cvmfs/pull/1043","diff_url":"https://github.com/cvmfs/cvmfs/pull/1043.diff","patch_url":"https://github.com/cvmfs/cvmfs/pull/1043.patch","issue_url":"https://api.github.com/repos/cvmfs/cvmfs/issues/1043","number":1043,"state":"open","locked":false,"title":"Python new Repository class","user":{"login":"Moliholy","id":2722756,"avatar_url":"https://avatars.githubusercontent.com/u/2722756?v=3","gravatar_id":"","url":"https://api.github.com/users/Moliholy","html_url":"https://github.com/Moliholy","followers_url":"https://api.github.com/users/Moliholy/followers","following_url":"https://api.github.com/users/Moliholy/following{/other_user}","gists_url":"https://api.github.com/users/Moliholy/gists{/gist_id}","starred_url":"https://api.github.com/users/Moliholy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Moliholy/subscriptions","organizations_url":"https://api.github.com/users/Moliholy/orgs","repos_url":"https://api.github.com/users/Moliholy/repos","events_url":"https://api.github.com/users/Moliholy/events{/privacy}","received_events_url":"https://api.github.com/users/Moliholy/received_events","type":"User","site_admin":false},"body":"This pull request changes the Repository class in the python API. Before it was necessary to instantiate a sub-class of Repository, i.e., RemoteRepository or LocalRepository. The first one always downloaded everything and didn't use any permanent cache, while the second one only could work in local.\r\n\r\nIn this context, I thought it was better to have just a Repository class so that the user can specify the cache directory and the remote directory. This way he can abstract from the use of full-cached, full-remote and the combination of these two, which is the way the client actually works.\r\n\r\nCatalog class has been modified in consequence since it doesn't require a compressed file to be initialised, but an already decompressed one.\r\n\r\nUpdated example usage:\r\n```\r\nimport cvmfs\r\n\r\n   repo = cvmfs.Repository(\"/home/user/cvmfs_cache\", 'http://cvmfs-stratum-one.cern.ch/opt/boss')\r\n   print 'Last Revision:' , repo.manifest.revision , repo.manifest.last_modified\r\n   root_catalog = repo.retrieve_root_catalog()\r\n   print 'Catalog Schema:' , root_catalog.schema\r\n   for nested_catalog_ref in root_catalog.list_nested():\r\n       print 'Nested Catalog at:' , nested_catalog_ref.root_path\r\n   print 'Listing repository'\r\n   for full_path, dirent in repo:\r\n       print full_path\r\n```","created_at":"2015-08-12T12:43:56Z","updated_at":"2015-08-12T13:12:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b99e9faa58186b2a76ceb9c85f64f82462630423","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1043/commits","review_comments_url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1043/comments","review_comment_url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cvmfs/cvmfs/issues/1043/comments","statuses_url":"https://api.github.com/repos/cvmfs/cvmfs/statuses/df822ab7ba1536607ae6098070fdfa0e2c11ca03","head":{"label":"Moliholy:python-repository_new","ref":"python-repository_new","sha":"df822ab7ba1536607ae6098070fdfa0e2c11ca03","user":{"login":"Moliholy","id":2722756,"avatar_url":"https://avatars.githubusercontent.com/u/2722756?v=3","gravatar_id":"","url":"https://api.github.com/users/Moliholy","html_url":"https://github.com/Moliholy","followers_url":"https://api.github.com/users/Moliholy/followers","following_url":"https://api.github.com/users/Moliholy/following{/other_user}","gists_url":"https://api.github.com/users/Moliholy/gists{/gist_id}","starred_url":"https://api.github.com/users/Moliholy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Moliholy/subscriptions","organizations_url":"https://api.github.com/users/Moliholy/orgs","repos_url":"https://api.github.com/users/Moliholy/repos","events_url":"https://api.github.com/users/Moliholy/events{/privacy}","received_events_url":"https://api.github.com/users/Moliholy/received_events","type":"User","site_admin":false},"repo":{"id":32462131,"name":"cvmfs","full_name":"Moliholy/cvmfs","owner":{"login":"Moliholy","id":2722756,"avatar_url":"https://avatars.githubusercontent.com/u/2722756?v=3","gravatar_id":"","url":"https://api.github.com/users/Moliholy","html_url":"https://github.com/Moliholy","followers_url":"https://api.github.com/users/Moliholy/followers","following_url":"https://api.github.com/users/Moliholy/following{/other_user}","gists_url":"https://api.github.com/users/Moliholy/gists{/gist_id}","starred_url":"https://api.github.com/users/Moliholy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Moliholy/subscriptions","organizations_url":"https://api.github.com/users/Moliholy/orgs","repos_url":"https://api.github.com/users/Moliholy/repos","events_url":"https://api.github.com/users/Moliholy/events{/privacy}","received_events_url":"https://api.github.com/users/Moliholy/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Moliholy/cvmfs","description":"The CernVM File System","fork":true,"url":"https://api.github.com/repos/Moliholy/cvmfs","forks_url":"https://api.github.com/repos/Moliholy/cvmfs/forks","keys_url":"https://api.github.com/repos/Moliholy/cvmfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Moliholy/cvmfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Moliholy/cvmfs/teams","hooks_url":"https://api.github.com/repos/Moliholy/cvmfs/hooks","issue_events_url":"https://api.github.com/repos/Moliholy/cvmfs/issues/events{/number}","events_url":"https://api.github.com/repos/Moliholy/cvmfs/events","assignees_url":"https://api.github.com/repos/Moliholy/cvmfs/assignees{/user}","branches_url":"https://api.github.com/repos/Moliholy/cvmfs/branches{/branch}","tags_url":"https://api.github.com/repos/Moliholy/cvmfs/tags","blobs_url":"https://api.github.com/repos/Moliholy/cvmfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Moliholy/cvmfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Moliholy/cvmfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/Moliholy/cvmfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Moliholy/cvmfs/statuses/{sha}","languages_url":"https://api.github.com/repos/Moliholy/cvmfs/languages","stargazers_url":"https://api.github.com/repos/Moliholy/cvmfs/stargazers","contributors_url":"https://api.github.com/repos/Moliholy/cvmfs/contributors","subscribers_url":"https://api.github.com/repos/Moliholy/cvmfs/subscribers","subscription_url":"https://api.github.com/repos/Moliholy/cvmfs/subscription","commits_url":"https://api.github.com/repos/Moliholy/cvmfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/Moliholy/cvmfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/Moliholy/cvmfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/Moliholy/cvmfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/Moliholy/cvmfs/contents/{+path}","compare_url":"https://api.github.com/repos/Moliholy/cvmfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Moliholy/cvmfs/merges","archive_url":"https://api.github.com/repos/Moliholy/cvmfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Moliholy/cvmfs/downloads","issues_url":"https://api.github.com/repos/Moliholy/cvmfs/issues{/number}","pulls_url":"https://api.github.com/repos/Moliholy/cvmfs/pulls{/number}","milestones_url":"https://api.github.com/repos/Moliholy/cvmfs/milestones{/number}","notifications_url":"https://api.github.com/repos/Moliholy/cvmfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Moliholy/cvmfs/labels{/name}","releases_url":"https://api.github.com/repos/Moliholy/cvmfs/releases{/id}","created_at":"2015-03-18T14:00:48Z","updated_at":"2015-05-07T13:17:12Z","pushed_at":"2015-08-12T12:37:44Z","git_url":"git://github.com/Moliholy/cvmfs.git","ssh_url":"git@github.com:Moliholy/cvmfs.git","clone_url":"https://github.com/Moliholy/cvmfs.git","svn_url":"https://github.com/Moliholy/cvmfs","homepage":"http://cernvm.cern.ch/portal/filesystem","size":90856,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"devel"}},"base":{"label":"cvmfs:python-full_library","ref":"python-full_library","sha":"56f69b6bbcb56f14264e8df922de12f0409b3739","user":{"login":"cvmfs","id":1560859,"avatar_url":"https://avatars.githubusercontent.com/u/1560859?v=3","gravatar_id":"","url":"https://api.github.com/users/cvmfs","html_url":"https://github.com/cvmfs","followers_url":"https://api.github.com/users/cvmfs/followers","following_url":"https://api.github.com/users/cvmfs/following{/other_user}","gists_url":"https://api.github.com/users/cvmfs/gists{/gist_id}","starred_url":"https://api.github.com/users/cvmfs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cvmfs/subscriptions","organizations_url":"https://api.github.com/users/cvmfs/orgs","repos_url":"https://api.github.com/users/cvmfs/repos","events_url":"https://api.github.com/users/cvmfs/events{/privacy}","received_events_url":"https://api.github.com/users/cvmfs/received_events","type":"Organization","site_admin":false},"repo":{"id":3784908,"name":"cvmfs","full_name":"cvmfs/cvmfs","owner":{"login":"cvmfs","id":1560859,"avatar_url":"https://avatars.githubusercontent.com/u/1560859?v=3","gravatar_id":"","url":"https://api.github.com/users/cvmfs","html_url":"https://github.com/cvmfs","followers_url":"https://api.github.com/users/cvmfs/followers","following_url":"https://api.github.com/users/cvmfs/following{/other_user}","gists_url":"https://api.github.com/users/cvmfs/gists{/gist_id}","starred_url":"https://api.github.com/users/cvmfs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cvmfs/subscriptions","organizations_url":"https://api.github.com/users/cvmfs/orgs","repos_url":"https://api.github.com/users/cvmfs/repos","events_url":"https://api.github.com/users/cvmfs/events{/privacy}","received_events_url":"https://api.github.com/users/cvmfs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cvmfs/cvmfs","description":"The CernVM File System","fork":false,"url":"https://api.github.com/repos/cvmfs/cvmfs","forks_url":"https://api.github.com/repos/cvmfs/cvmfs/forks","keys_url":"https://api.github.com/repos/cvmfs/cvmfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cvmfs/cvmfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cvmfs/cvmfs/teams","hooks_url":"https://api.github.com/repos/cvmfs/cvmfs/hooks","issue_events_url":"https://api.github.com/repos/cvmfs/cvmfs/issues/events{/number}","events_url":"https://api.github.com/repos/cvmfs/cvmfs/events","assignees_url":"https://api.github.com/repos/cvmfs/cvmfs/assignees{/user}","branches_url":"https://api.github.com/repos/cvmfs/cvmfs/branches{/branch}","tags_url":"https://api.github.com/repos/cvmfs/cvmfs/tags","blobs_url":"https://api.github.com/repos/cvmfs/cvmfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cvmfs/cvmfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cvmfs/cvmfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/cvmfs/cvmfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cvmfs/cvmfs/statuses/{sha}","languages_url":"https://api.github.com/repos/cvmfs/cvmfs/languages","stargazers_url":"https://api.github.com/repos/cvmfs/cvmfs/stargazers","contributors_url":"https://api.github.com/repos/cvmfs/cvmfs/contributors","subscribers_url":"https://api.github.com/repos/cvmfs/cvmfs/subscribers","subscription_url":"https://api.github.com/repos/cvmfs/cvmfs/subscription","commits_url":"https://api.github.com/repos/cvmfs/cvmfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/cvmfs/cvmfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/cvmfs/cvmfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/cvmfs/cvmfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/cvmfs/cvmfs/contents/{+path}","compare_url":"https://api.github.com/repos/cvmfs/cvmfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cvmfs/cvmfs/merges","archive_url":"https://api.github.com/repos/cvmfs/cvmfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cvmfs/cvmfs/downloads","issues_url":"https://api.github.com/repos/cvmfs/cvmfs/issues{/number}","pulls_url":"https://api.github.com/repos/cvmfs/cvmfs/pulls{/number}","milestones_url":"https://api.github.com/repos/cvmfs/cvmfs/milestones{/number}","notifications_url":"https://api.github.com/repos/cvmfs/cvmfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cvmfs/cvmfs/labels{/name}","releases_url":"https://api.github.com/repos/cvmfs/cvmfs/releases{/id}","created_at":"2012-03-21T09:10:41Z","updated_at":"2015-08-05T22:08:44Z","pushed_at":"2015-08-12T12:43:56Z","git_url":"git://github.com/cvmfs/cvmfs.git","ssh_url":"git@github.com:cvmfs/cvmfs.git","clone_url":"https://github.com/cvmfs/cvmfs.git","svn_url":"https://github.com/cvmfs/cvmfs","homepage":"http://cernvm.cern.ch/portal/filesystem","size":97751,"stargazers_count":38,"watchers_count":38,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":42,"mirror_url":null,"open_issues_count":4,"forks":42,"open_issues":4,"watchers":38,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1043"},"html":{"href":"https://github.com/cvmfs/cvmfs/pull/1043"},"issue":{"href":"https://api.github.com/repos/cvmfs/cvmfs/issues/1043"},"comments":{"href":"https://api.github.com/repos/cvmfs/cvmfs/issues/1043/comments"},"review_comments":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1043/comments"},"review_comment":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1043/commits"},"statuses":{"href":"https://api.github.com/repos/cvmfs/cvmfs/statuses/df822ab7ba1536607ae6098070fdfa0e2c11ca03"}}}}