{"action":"created","comment":{"url":"https://api.github.com/repos/scalability-llnl/spack/pulls/comments/38036724","id":38036724,"diff_hunk":"@@ -0,0 +1,290 @@\n+##############################################################################\n+# Copyright (c) 2013, Lawrence Livermore National Security, LLC.\n+# Produced at the Lawrence Livermore National Laboratory.\n+#\n+# This file is part of Spack.\n+# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.\n+# LLNL-CODE-647188\n+#\n+# For details, see https://scalability-llnl.github.io/spack\n+# Please also see the LICENSE file for our notice and the LGPL.\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 (as published by\n+# the Free Software Foundation) version 2.1 dated February 1999.\n+#\n+# This program is distributed in the hope that it will be useful, but\n+# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and\n+# conditions of the GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU Lesser General Public License\n+# along with this program; if not, write to the Free Software Foundation,\n+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n+##############################################################################\n+import os\n+import sys\n+import inspect\n+import glob\n+import imp\n+\n+import time\n+import copy\n+import errno\n+\n+from external import yaml\n+from external.yaml.error import MarkedYAMLError\n+\n+import llnl.util.tty as tty\n+from llnl.util.filesystem import join_path\n+from llnl.util.lang import *\n+\n+import spack.error\n+import spack.spec\n+from spack.spec import Spec\n+from spack.error import SpackError\n+from spack.virtual import ProviderIndex\n+from spack.util.naming import mod_to_class, validate_module_name\n+\n+\n+def _autospec(function):\n+    \"\"\"Decorator that automatically converts the argument of a single-arg\n+       function to a Spec.\"\"\"\n+    def converter(self, spec_like, **kwargs):\n+        if not isinstance(spec_like, spack.spec.Spec):\n+            spec_like = spack.spec.Spec(spec_like)\n+        return function(self, spec_like, **kwargs)\n+    return converter\n+\n+\n+class Database(object):\n+    def __init__(self,root,file_name=\"specDB.yaml\"):\n+        \"\"\"\n+        Create an empty Database\n+        Location defaults to root/specDB.yaml\n+        The individual data are dicts containing\n+        spec: the top level spec of a package\n+        path: the path to the install of that package\n+        dep_hash: a hash of the dependence DAG for that package\n+        \"\"\"\n+        self.root = root\n+        self.file_name = file_name\n+        self.file_path = join_path(self.root,self.file_name)\n+\n+        self.lock_name = \"db_lock\"\n+        self.lock_path = join_path(self.root,self.lock_name)\n+\n+        self.data = []\n+        self.last_write_time = 0\n+\n+\n+    def from_yaml(self,stream):\n+        \"\"\"\n+        Fill database from YAML, do not maintain old data\n+        Translate the spec portions from node-dict form to spec from\n+        \"\"\"\n+        try:\n+            file = yaml.load(stream)\n+        except MarkedYAMLError, e:\n+            raise SpackYAMLError(\"error parsing YAML database:\", str(e))\n+\n+        if file==None:\n+            return\n+\n+        data = {}\n+        for index, sp in file['database'].items():\n+            spec = Spec.from_node_dict(sp['spec'])\n+            deps = sp['dependency_indices']\n+            path = sp['path']\n+            dep_hash = sp['hash']\n+            db_entry = {'deps':deps, 'spec': spec, 'path': path, 'hash':dep_hash}\n+            data[index] = db_entry\n+\n+        for sph in data.values():\n+            for idx in sph['deps']:\n+                sph['spec'].dependencies[data[idx]['spec'].name] = data[idx]['spec']\n+\n+        self.data = data.values()\n+\n+\n+    def read_database(self):\n+        \"\"\"\n+        Re-read Database from the data in the set location\n+        If the cache is fresh, return immediately.\n+        Implemented with mkdir locking for the database file.\n+        \"\"\"\n+        if not self.is_dirty():\n+            return\n+\n+        lock=0\n+        while lock==0:\n+            try:\n+                os.mkdir(self.lock_path)\n+                lock=1\n+            except OSError as err:\n+                pass\n+\n+        #The try statement ensures that a failure won't leave the\n+        #database locked to other processes.\n+        try:\n+            if os.path.isfile(self.file_path):\n+                with open(self.file_path,'r') as f:\n+                    self.from_yaml(f)\n+            else:\n+            #The file doesn't exist, construct empty data.\n+                self.data = []\n+        except:\n+            os.rmdir(self.lock_path)\n+            raise\n+\n+        os.rmdir(self.lock_path)","path":"lib/spack/spack/database.py","position":140,"original_position":140,"commit_id":"9345e7877983d1bde8a4aefbecdc4a8cab181186","original_commit_id":"9345e7877983d1bde8a4aefbecdc4a8cab181186","user":{"login":"becker33","id":13971568,"avatar_url":"https://avatars.githubusercontent.com/u/13971568?v=3","gravatar_id":"","url":"https://api.github.com/users/becker33","html_url":"https://github.com/becker33","followers_url":"https://api.github.com/users/becker33/followers","following_url":"https://api.github.com/users/becker33/following{/other_user}","gists_url":"https://api.github.com/users/becker33/gists{/gist_id}","starred_url":"https://api.github.com/users/becker33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/becker33/subscriptions","organizations_url":"https://api.github.com/users/becker33/orgs","repos_url":"https://api.github.com/users/becker33/repos","events_url":"https://api.github.com/users/becker33/events{/privacy}","received_events_url":"https://api.github.com/users/becker33/received_events","type":"User","site_admin":false},"body":"Will do.","created_at":"2015-08-26T21:23:35Z","updated_at":"2015-08-26T21:23:35Z","html_url":"https://github.com/scalability-llnl/spack/pull/100#discussion_r38036724","pull_request_url":"https://api.github.com/repos/scalability-llnl/spack/pulls/100","_links":{"self":{"href":"https://api.github.com/repos/scalability-llnl/spack/pulls/comments/38036724"},"html":{"href":"https://github.com/scalability-llnl/spack/pull/100#discussion_r38036724"},"pull_request":{"href":"https://api.github.com/repos/scalability-llnl/spack/pulls/100"}}},"pull_request":{"url":"https://api.github.com/repos/scalability-llnl/spack/pulls/100","id":43349136,"html_url":"https://github.com/scalability-llnl/spack/pull/100","diff_url":"https://github.com/scalability-llnl/spack/pull/100.diff","patch_url":"https://github.com/scalability-llnl/spack/pull/100.patch","issue_url":"https://api.github.com/repos/scalability-llnl/spack/issues/100","number":100,"state":"open","locked":false,"title":"Database","user":{"login":"becker33","id":13971568,"avatar_url":"https://avatars.githubusercontent.com/u/13971568?v=3","gravatar_id":"","url":"https://api.github.com/users/becker33","html_url":"https://github.com/becker33","followers_url":"https://api.github.com/users/becker33/followers","following_url":"https://api.github.com/users/becker33/following{/other_user}","gists_url":"https://api.github.com/users/becker33/gists{/gist_id}","starred_url":"https://api.github.com/users/becker33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/becker33/subscriptions","organizations_url":"https://api.github.com/users/becker33/orgs","repos_url":"https://api.github.com/users/becker33/repos","events_url":"https://api.github.com/users/becker33/events{/privacy}","received_events_url":"https://api.github.com/users/becker33/received_events","type":"User","site_admin":false},"body":"This does not include database verification, will add later as discussed.","created_at":"2015-08-25T23:32:35Z","updated_at":"2015-08-26T21:23:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dc1cee2a0aeffc459ee326fd4f679ee3dffa1b77","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scalability-llnl/spack/pulls/100/commits","review_comments_url":"https://api.github.com/repos/scalability-llnl/spack/pulls/100/comments","review_comment_url":"https://api.github.com/repos/scalability-llnl/spack/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scalability-llnl/spack/issues/100/comments","statuses_url":"https://api.github.com/repos/scalability-llnl/spack/statuses/9345e7877983d1bde8a4aefbecdc4a8cab181186","head":{"label":"becker33:database","ref":"database","sha":"9345e7877983d1bde8a4aefbecdc4a8cab181186","user":{"login":"becker33","id":13971568,"avatar_url":"https://avatars.githubusercontent.com/u/13971568?v=3","gravatar_id":"","url":"https://api.github.com/users/becker33","html_url":"https://github.com/becker33","followers_url":"https://api.github.com/users/becker33/followers","following_url":"https://api.github.com/users/becker33/following{/other_user}","gists_url":"https://api.github.com/users/becker33/gists{/gist_id}","starred_url":"https://api.github.com/users/becker33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/becker33/subscriptions","organizations_url":"https://api.github.com/users/becker33/orgs","repos_url":"https://api.github.com/users/becker33/repos","events_url":"https://api.github.com/users/becker33/events{/privacy}","received_events_url":"https://api.github.com/users/becker33/received_events","type":"User","site_admin":false},"repo":{"id":41391686,"name":"spack","full_name":"becker33/spack","owner":{"login":"becker33","id":13971568,"avatar_url":"https://avatars.githubusercontent.com/u/13971568?v=3","gravatar_id":"","url":"https://api.github.com/users/becker33","html_url":"https://github.com/becker33","followers_url":"https://api.github.com/users/becker33/followers","following_url":"https://api.github.com/users/becker33/following{/other_user}","gists_url":"https://api.github.com/users/becker33/gists{/gist_id}","starred_url":"https://api.github.com/users/becker33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/becker33/subscriptions","organizations_url":"https://api.github.com/users/becker33/orgs","repos_url":"https://api.github.com/users/becker33/repos","events_url":"https://api.github.com/users/becker33/events{/privacy}","received_events_url":"https://api.github.com/users/becker33/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/becker33/spack","description":"A flexible package manager designed to support multiple versions, configurations, platforms, and compilers.","fork":true,"url":"https://api.github.com/repos/becker33/spack","forks_url":"https://api.github.com/repos/becker33/spack/forks","keys_url":"https://api.github.com/repos/becker33/spack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/becker33/spack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/becker33/spack/teams","hooks_url":"https://api.github.com/repos/becker33/spack/hooks","issue_events_url":"https://api.github.com/repos/becker33/spack/issues/events{/number}","events_url":"https://api.github.com/repos/becker33/spack/events","assignees_url":"https://api.github.com/repos/becker33/spack/assignees{/user}","branches_url":"https://api.github.com/repos/becker33/spack/branches{/branch}","tags_url":"https://api.github.com/repos/becker33/spack/tags","blobs_url":"https://api.github.com/repos/becker33/spack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/becker33/spack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/becker33/spack/git/refs{/sha}","trees_url":"https://api.github.com/repos/becker33/spack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/becker33/spack/statuses/{sha}","languages_url":"https://api.github.com/repos/becker33/spack/languages","stargazers_url":"https://api.github.com/repos/becker33/spack/stargazers","contributors_url":"https://api.github.com/repos/becker33/spack/contributors","subscribers_url":"https://api.github.com/repos/becker33/spack/subscribers","subscription_url":"https://api.github.com/repos/becker33/spack/subscription","commits_url":"https://api.github.com/repos/becker33/spack/commits{/sha}","git_commits_url":"https://api.github.com/repos/becker33/spack/git/commits{/sha}","comments_url":"https://api.github.com/repos/becker33/spack/comments{/number}","issue_comment_url":"https://api.github.com/repos/becker33/spack/issues/comments{/number}","contents_url":"https://api.github.com/repos/becker33/spack/contents/{+path}","compare_url":"https://api.github.com/repos/becker33/spack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/becker33/spack/merges","archive_url":"https://api.github.com/repos/becker33/spack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/becker33/spack/downloads","issues_url":"https://api.github.com/repos/becker33/spack/issues{/number}","pulls_url":"https://api.github.com/repos/becker33/spack/pulls{/number}","milestones_url":"https://api.github.com/repos/becker33/spack/milestones{/number}","notifications_url":"https://api.github.com/repos/becker33/spack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/becker33/spack/labels{/name}","releases_url":"https://api.github.com/repos/becker33/spack/releases{/id}","created_at":"2015-08-25T22:45:04Z","updated_at":"2015-08-25T22:45:05Z","pushed_at":"2015-08-25T23:31:17Z","git_url":"git://github.com/becker33/spack.git","ssh_url":"git@github.com:becker33/spack.git","clone_url":"https://github.com/becker33/spack.git","svn_url":"https://github.com/becker33/spack","homepage":"http://scalability-llnl.github.io/spack","size":3086,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scalability-llnl:develop","ref":"develop","sha":"c8f65c15306683a5d505d4bcafa603e75c09feca","user":{"login":"scalability-llnl","id":5914720,"avatar_url":"https://avatars.githubusercontent.com/u/5914720?v=3","gravatar_id":"","url":"https://api.github.com/users/scalability-llnl","html_url":"https://github.com/scalability-llnl","followers_url":"https://api.github.com/users/scalability-llnl/followers","following_url":"https://api.github.com/users/scalability-llnl/following{/other_user}","gists_url":"https://api.github.com/users/scalability-llnl/gists{/gist_id}","starred_url":"https://api.github.com/users/scalability-llnl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalability-llnl/subscriptions","organizations_url":"https://api.github.com/users/scalability-llnl/orgs","repos_url":"https://api.github.com/users/scalability-llnl/repos","events_url":"https://api.github.com/users/scalability-llnl/events{/privacy}","received_events_url":"https://api.github.com/users/scalability-llnl/received_events","type":"Organization","site_admin":false},"repo":{"id":15730865,"name":"spack","full_name":"scalability-llnl/spack","owner":{"login":"scalability-llnl","id":5914720,"avatar_url":"https://avatars.githubusercontent.com/u/5914720?v=3","gravatar_id":"","url":"https://api.github.com/users/scalability-llnl","html_url":"https://github.com/scalability-llnl","followers_url":"https://api.github.com/users/scalability-llnl/followers","following_url":"https://api.github.com/users/scalability-llnl/following{/other_user}","gists_url":"https://api.github.com/users/scalability-llnl/gists{/gist_id}","starred_url":"https://api.github.com/users/scalability-llnl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalability-llnl/subscriptions","organizations_url":"https://api.github.com/users/scalability-llnl/orgs","repos_url":"https://api.github.com/users/scalability-llnl/repos","events_url":"https://api.github.com/users/scalability-llnl/events{/privacy}","received_events_url":"https://api.github.com/users/scalability-llnl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scalability-llnl/spack","description":"A flexible package manager designed to support multiple versions, configurations, platforms, and compilers.","fork":false,"url":"https://api.github.com/repos/scalability-llnl/spack","forks_url":"https://api.github.com/repos/scalability-llnl/spack/forks","keys_url":"https://api.github.com/repos/scalability-llnl/spack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scalability-llnl/spack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scalability-llnl/spack/teams","hooks_url":"https://api.github.com/repos/scalability-llnl/spack/hooks","issue_events_url":"https://api.github.com/repos/scalability-llnl/spack/issues/events{/number}","events_url":"https://api.github.com/repos/scalability-llnl/spack/events","assignees_url":"https://api.github.com/repos/scalability-llnl/spack/assignees{/user}","branches_url":"https://api.github.com/repos/scalability-llnl/spack/branches{/branch}","tags_url":"https://api.github.com/repos/scalability-llnl/spack/tags","blobs_url":"https://api.github.com/repos/scalability-llnl/spack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scalability-llnl/spack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scalability-llnl/spack/git/refs{/sha}","trees_url":"https://api.github.com/repos/scalability-llnl/spack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scalability-llnl/spack/statuses/{sha}","languages_url":"https://api.github.com/repos/scalability-llnl/spack/languages","stargazers_url":"https://api.github.com/repos/scalability-llnl/spack/stargazers","contributors_url":"https://api.github.com/repos/scalability-llnl/spack/contributors","subscribers_url":"https://api.github.com/repos/scalability-llnl/spack/subscribers","subscription_url":"https://api.github.com/repos/scalability-llnl/spack/subscription","commits_url":"https://api.github.com/repos/scalability-llnl/spack/commits{/sha}","git_commits_url":"https://api.github.com/repos/scalability-llnl/spack/git/commits{/sha}","comments_url":"https://api.github.com/repos/scalability-llnl/spack/comments{/number}","issue_comment_url":"https://api.github.com/repos/scalability-llnl/spack/issues/comments{/number}","contents_url":"https://api.github.com/repos/scalability-llnl/spack/contents/{+path}","compare_url":"https://api.github.com/repos/scalability-llnl/spack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scalability-llnl/spack/merges","archive_url":"https://api.github.com/repos/scalability-llnl/spack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scalability-llnl/spack/downloads","issues_url":"https://api.github.com/repos/scalability-llnl/spack/issues{/number}","pulls_url":"https://api.github.com/repos/scalability-llnl/spack/pulls{/number}","milestones_url":"https://api.github.com/repos/scalability-llnl/spack/milestones{/number}","notifications_url":"https://api.github.com/repos/scalability-llnl/spack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scalability-llnl/spack/labels{/name}","releases_url":"https://api.github.com/repos/scalability-llnl/spack/releases{/id}","created_at":"2014-01-08T09:22:12Z","updated_at":"2015-08-20T20:00:51Z","pushed_at":"2015-08-25T23:32:37Z","git_url":"git://github.com/scalability-llnl/spack.git","ssh_url":"git@github.com:scalability-llnl/spack.git","clone_url":"https://github.com/scalability-llnl/spack.git","svn_url":"https://github.com/scalability-llnl/spack","homepage":"http://scalability-llnl.github.io/spack","size":7930,"stargazers_count":41,"watchers_count":41,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":33,"mirror_url":null,"open_issues_count":27,"forks":33,"open_issues":27,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scalability-llnl/spack/pulls/100"},"html":{"href":"https://github.com/scalability-llnl/spack/pull/100"},"issue":{"href":"https://api.github.com/repos/scalability-llnl/spack/issues/100"},"comments":{"href":"https://api.github.com/repos/scalability-llnl/spack/issues/100/comments"},"review_comments":{"href":"https://api.github.com/repos/scalability-llnl/spack/pulls/100/comments"},"review_comment":{"href":"https://api.github.com/repos/scalability-llnl/spack/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scalability-llnl/spack/pulls/100/commits"},"statuses":{"href":"https://api.github.com/repos/scalability-llnl/spack/statuses/9345e7877983d1bde8a4aefbecdc4a8cab181186"}}}}