{"action":"created","comment":{"url":"https://api.github.com/repos/saltstack/salt/pulls/comments/27047189","id":27047189,"diff_hunk":"@@ -0,0 +1,139 @@\n+# -*- coding: utf-8 -*-\n+# Copyright (C) 2014 Floris Bruynooghe <flub@devork.be>\n+\n+'''Use remote Mercurial repository as a Pillar source\n+\n+The module depends on the ``hglib`` python module being available.\n+This is the same requirement as for hgfs_ so should not pose any extra\n+hurdles.\n+\n+This external Pillar source can be configued in the master config file as such:\n+\n+.. code-block:: yaml\n+\n+   ext_pillar:\n+     - hg: ssh://hg@example.co/user/repo\n+'''\n+\n+import copy\n+import hashlib\n+import logging\n+import os\n+\n+import salt.pillar\n+\n+try:\n+    import hglib\n+except ImportError:\n+    hglib = None\n+\n+\n+__virtualname__ = 'hg'\n+log = logging.getLogger(__name__)\n+\n+\n+# The default option values\n+__opts__ = {}\n+\n+\n+def __virtual__():\n+    '''\n+    Only load if hglib is available\n+    '''\n+    ext_pillar_sources = [x for x in __opts__.get('ext_pillar', [])]\n+    if not any(['hg' in x for x in ext_pillar_sources]):\n+        return False\n+    if not hglib:\n+        log.error('hglib not present')\n+        return False\n+    return __virtualname__\n+\n+\n+def __init__(__opts__):\n+    '''\n+    Initialise\n+\n+    This is called every time a minion calls this external pillar.\n+    '''\n+\n+\n+def ext_pillar(minion_id, pillar, repo, branch='default', root=None):\n+    '''\n+    Extract pillar from an hg repository\n+    '''\n+    with Repo(repo) as repo:\n+        repo.update(branch)\n+    envname = 'base' if branch == 'default' else branch\n+    if root:\n+        path = os.path.normpath(os.path.join(repo.working_dir, root))\n+    else:\n+        path = repo.working_dir\n+\n+    opts = copy.deepcopy(__opts__)\n+    opts['pillar_roots'][envname] = [path]\n+    pil = salt.pillar.Pillar(opts, __grains__, minion_id, envname)\n+    return pil.compile_pillar(ext=False)\n+\n+\n+def update(repo_uri):\n+    '''\n+    Execute an hg pull on all the repos\n+    '''\n+    with Repo(repo_uri) as repo:\n+        repo.pull()\n+\n+\n+def envs():\n+    '''\n+    Return a list of branches that can be used as environments\n+    '''\n+\n+\n+def purge_cache():\n+    '''\n+    Purge the hg_pillar cache\n+    '''\n+","path":"salt/pillar/hg_pillar.py","position":96,"original_position":96,"commit_id":"15f66d1f0ff2b6b5519c0b08ad1dae7fc8c9230a","original_commit_id":"15f66d1f0ff2b6b5519c0b08ad1dae7fc8c9230a","user":{"login":"ptonelli","id":4579998,"avatar_url":"https://avatars.githubusercontent.com/u/4579998?v=3","gravatar_id":"","url":"https://api.github.com/users/ptonelli","html_url":"https://github.com/ptonelli","followers_url":"https://api.github.com/users/ptonelli/followers","following_url":"https://api.github.com/users/ptonelli/following{/other_user}","gists_url":"https://api.github.com/users/ptonelli/gists{/gist_id}","starred_url":"https://api.github.com/users/ptonelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ptonelli/subscriptions","organizations_url":"https://api.github.com/users/ptonelli/orgs","repos_url":"https://api.github.com/users/ptonelli/repos","events_url":"https://api.github.com/users/ptonelli/events{/privacy}","received_events_url":"https://api.github.com/users/ptonelli/received_events","type":"User","site_admin":false},"body":"I believe they are for future implementation, but should be removed as they are not called in the hg_pillar.py. I am testing if things are working correctly without them","created_at":"2015-03-24T16:42:48Z","updated_at":"2015-03-24T16:42:48Z","html_url":"https://github.com/saltstack/salt/pull/21930#discussion_r27047189","pull_request_url":"https://api.github.com/repos/saltstack/salt/pulls/21930","_links":{"self":{"href":"https://api.github.com/repos/saltstack/salt/pulls/comments/27047189"},"html":{"href":"https://github.com/saltstack/salt/pull/21930#discussion_r27047189"},"pull_request":{"href":"https://api.github.com/repos/saltstack/salt/pulls/21930"}}},"pull_request":{"url":"https://api.github.com/repos/saltstack/salt/pulls/21930","id":31817749,"html_url":"https://github.com/saltstack/salt/pull/21930","diff_url":"https://github.com/saltstack/salt/pull/21930.diff","patch_url":"https://github.com/saltstack/salt/pull/21930.patch","issue_url":"https://api.github.com/repos/saltstack/salt/issues/21930","number":21930,"state":"open","locked":false,"title":"add hg_pillar similar to git_pillar ","user":{"login":"ptonelli","id":4579998,"avatar_url":"https://avatars.githubusercontent.com/u/4579998?v=3","gravatar_id":"","url":"https://api.github.com/users/ptonelli","html_url":"https://github.com/ptonelli","followers_url":"https://api.github.com/users/ptonelli/followers","following_url":"https://api.github.com/users/ptonelli/following{/other_user}","gists_url":"https://api.github.com/users/ptonelli/gists{/gist_id}","starred_url":"https://api.github.com/users/ptonelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ptonelli/subscriptions","organizations_url":"https://api.github.com/users/ptonelli/orgs","repos_url":"https://api.github.com/users/ptonelli/repos","events_url":"https://api.github.com/users/ptonelli/events{/privacy}","received_events_url":"https://api.github.com/users/ptonelli/received_events","type":"User","site_admin":false},"body":"originally from https://bitbucket.org/flub/hg_pillar\r\n\r\nThis pull requests also adds the first true unit test for custom ext pillars","created_at":"2015-03-24T11:33:26Z","updated_at":"2015-03-24T16:42:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"205288f9508280663811f77548825fc251d5bafa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/saltstack/salt/pulls/21930/commits","review_comments_url":"https://api.github.com/repos/saltstack/salt/pulls/21930/comments","review_comment_url":"https://api.github.com/repos/saltstack/salt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/21930/comments","statuses_url":"https://api.github.com/repos/saltstack/salt/statuses/15f66d1f0ff2b6b5519c0b08ad1dae7fc8c9230a","head":{"label":"ptonelli:develop","ref":"develop","sha":"15f66d1f0ff2b6b5519c0b08ad1dae7fc8c9230a","user":{"login":"ptonelli","id":4579998,"avatar_url":"https://avatars.githubusercontent.com/u/4579998?v=3","gravatar_id":"","url":"https://api.github.com/users/ptonelli","html_url":"https://github.com/ptonelli","followers_url":"https://api.github.com/users/ptonelli/followers","following_url":"https://api.github.com/users/ptonelli/following{/other_user}","gists_url":"https://api.github.com/users/ptonelli/gists{/gist_id}","starred_url":"https://api.github.com/users/ptonelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ptonelli/subscriptions","organizations_url":"https://api.github.com/users/ptonelli/orgs","repos_url":"https://api.github.com/users/ptonelli/repos","events_url":"https://api.github.com/users/ptonelli/events{/privacy}","received_events_url":"https://api.github.com/users/ptonelli/received_events","type":"User","site_admin":false},"repo":{"id":24092728,"name":"salt","full_name":"ptonelli/salt","owner":{"login":"ptonelli","id":4579998,"avatar_url":"https://avatars.githubusercontent.com/u/4579998?v=3","gravatar_id":"","url":"https://api.github.com/users/ptonelli","html_url":"https://github.com/ptonelli","followers_url":"https://api.github.com/users/ptonelli/followers","following_url":"https://api.github.com/users/ptonelli/following{/other_user}","gists_url":"https://api.github.com/users/ptonelli/gists{/gist_id}","starred_url":"https://api.github.com/users/ptonelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ptonelli/subscriptions","organizations_url":"https://api.github.com/users/ptonelli/orgs","repos_url":"https://api.github.com/users/ptonelli/repos","events_url":"https://api.github.com/users/ptonelli/events{/privacy}","received_events_url":"https://api.github.com/users/ptonelli/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ptonelli/salt","description":"Infrastructure automation and management system","fork":true,"url":"https://api.github.com/repos/ptonelli/salt","forks_url":"https://api.github.com/repos/ptonelli/salt/forks","keys_url":"https://api.github.com/repos/ptonelli/salt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ptonelli/salt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ptonelli/salt/teams","hooks_url":"https://api.github.com/repos/ptonelli/salt/hooks","issue_events_url":"https://api.github.com/repos/ptonelli/salt/issues/events{/number}","events_url":"https://api.github.com/repos/ptonelli/salt/events","assignees_url":"https://api.github.com/repos/ptonelli/salt/assignees{/user}","branches_url":"https://api.github.com/repos/ptonelli/salt/branches{/branch}","tags_url":"https://api.github.com/repos/ptonelli/salt/tags","blobs_url":"https://api.github.com/repos/ptonelli/salt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ptonelli/salt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ptonelli/salt/git/refs{/sha}","trees_url":"https://api.github.com/repos/ptonelli/salt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ptonelli/salt/statuses/{sha}","languages_url":"https://api.github.com/repos/ptonelli/salt/languages","stargazers_url":"https://api.github.com/repos/ptonelli/salt/stargazers","contributors_url":"https://api.github.com/repos/ptonelli/salt/contributors","subscribers_url":"https://api.github.com/repos/ptonelli/salt/subscribers","subscription_url":"https://api.github.com/repos/ptonelli/salt/subscription","commits_url":"https://api.github.com/repos/ptonelli/salt/commits{/sha}","git_commits_url":"https://api.github.com/repos/ptonelli/salt/git/commits{/sha}","comments_url":"https://api.github.com/repos/ptonelli/salt/comments{/number}","issue_comment_url":"https://api.github.com/repos/ptonelli/salt/issues/comments{/number}","contents_url":"https://api.github.com/repos/ptonelli/salt/contents/{+path}","compare_url":"https://api.github.com/repos/ptonelli/salt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ptonelli/salt/merges","archive_url":"https://api.github.com/repos/ptonelli/salt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ptonelli/salt/downloads","issues_url":"https://api.github.com/repos/ptonelli/salt/issues{/number}","pulls_url":"https://api.github.com/repos/ptonelli/salt/pulls{/number}","milestones_url":"https://api.github.com/repos/ptonelli/salt/milestones{/number}","notifications_url":"https://api.github.com/repos/ptonelli/salt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ptonelli/salt/labels{/name}","releases_url":"https://api.github.com/repos/ptonelli/salt/releases{/id}","created_at":"2014-09-16T09:06:10Z","updated_at":"2015-03-24T14:52:21Z","pushed_at":"2015-03-24T14:52:17Z","git_url":"git://github.com/ptonelli/salt.git","ssh_url":"git@github.com:ptonelli/salt.git","clone_url":"https://github.com/ptonelli/salt.git","svn_url":"https://github.com/ptonelli/salt","homepage":"saltstack.com","size":85926,"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":"develop"}},"base":{"label":"saltstack:develop","ref":"develop","sha":"56c438910a213e8cd94543fddead65f6f17603e4","user":{"login":"saltstack","id":1147473,"avatar_url":"https://avatars.githubusercontent.com/u/1147473?v=3","gravatar_id":"","url":"https://api.github.com/users/saltstack","html_url":"https://github.com/saltstack","followers_url":"https://api.github.com/users/saltstack/followers","following_url":"https://api.github.com/users/saltstack/following{/other_user}","gists_url":"https://api.github.com/users/saltstack/gists{/gist_id}","starred_url":"https://api.github.com/users/saltstack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saltstack/subscriptions","organizations_url":"https://api.github.com/users/saltstack/orgs","repos_url":"https://api.github.com/users/saltstack/repos","events_url":"https://api.github.com/users/saltstack/events{/privacy}","received_events_url":"https://api.github.com/users/saltstack/received_events","type":"Organization","site_admin":false},"repo":{"id":1390248,"name":"salt","full_name":"saltstack/salt","owner":{"login":"saltstack","id":1147473,"avatar_url":"https://avatars.githubusercontent.com/u/1147473?v=3","gravatar_id":"","url":"https://api.github.com/users/saltstack","html_url":"https://github.com/saltstack","followers_url":"https://api.github.com/users/saltstack/followers","following_url":"https://api.github.com/users/saltstack/following{/other_user}","gists_url":"https://api.github.com/users/saltstack/gists{/gist_id}","starred_url":"https://api.github.com/users/saltstack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saltstack/subscriptions","organizations_url":"https://api.github.com/users/saltstack/orgs","repos_url":"https://api.github.com/users/saltstack/repos","events_url":"https://api.github.com/users/saltstack/events{/privacy}","received_events_url":"https://api.github.com/users/saltstack/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/saltstack/salt","description":"Infrastructure automation and management system","fork":false,"url":"https://api.github.com/repos/saltstack/salt","forks_url":"https://api.github.com/repos/saltstack/salt/forks","keys_url":"https://api.github.com/repos/saltstack/salt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/saltstack/salt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/saltstack/salt/teams","hooks_url":"https://api.github.com/repos/saltstack/salt/hooks","issue_events_url":"https://api.github.com/repos/saltstack/salt/issues/events{/number}","events_url":"https://api.github.com/repos/saltstack/salt/events","assignees_url":"https://api.github.com/repos/saltstack/salt/assignees{/user}","branches_url":"https://api.github.com/repos/saltstack/salt/branches{/branch}","tags_url":"https://api.github.com/repos/saltstack/salt/tags","blobs_url":"https://api.github.com/repos/saltstack/salt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/saltstack/salt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/saltstack/salt/git/refs{/sha}","trees_url":"https://api.github.com/repos/saltstack/salt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/saltstack/salt/statuses/{sha}","languages_url":"https://api.github.com/repos/saltstack/salt/languages","stargazers_url":"https://api.github.com/repos/saltstack/salt/stargazers","contributors_url":"https://api.github.com/repos/saltstack/salt/contributors","subscribers_url":"https://api.github.com/repos/saltstack/salt/subscribers","subscription_url":"https://api.github.com/repos/saltstack/salt/subscription","commits_url":"https://api.github.com/repos/saltstack/salt/commits{/sha}","git_commits_url":"https://api.github.com/repos/saltstack/salt/git/commits{/sha}","comments_url":"https://api.github.com/repos/saltstack/salt/comments{/number}","issue_comment_url":"https://api.github.com/repos/saltstack/salt/issues/comments{/number}","contents_url":"https://api.github.com/repos/saltstack/salt/contents/{+path}","compare_url":"https://api.github.com/repos/saltstack/salt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/saltstack/salt/merges","archive_url":"https://api.github.com/repos/saltstack/salt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/saltstack/salt/downloads","issues_url":"https://api.github.com/repos/saltstack/salt/issues{/number}","pulls_url":"https://api.github.com/repos/saltstack/salt/pulls{/number}","milestones_url":"https://api.github.com/repos/saltstack/salt/milestones{/number}","notifications_url":"https://api.github.com/repos/saltstack/salt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/saltstack/salt/labels{/name}","releases_url":"https://api.github.com/repos/saltstack/salt/releases{/id}","created_at":"2011-02-20T20:16:56Z","updated_at":"2015-03-24T16:03:46Z","pushed_at":"2015-03-24T16:35:02Z","git_url":"git://github.com/saltstack/salt.git","ssh_url":"git@github.com:saltstack/salt.git","clone_url":"https://github.com/saltstack/salt.git","svn_url":"https://github.com/saltstack/salt","homepage":"saltstack.com","size":197267,"stargazers_count":4872,"watchers_count":4872,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2032,"mirror_url":null,"open_issues_count":2381,"forks":2032,"open_issues":2381,"watchers":4872,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/saltstack/salt/pulls/21930"},"html":{"href":"https://github.com/saltstack/salt/pull/21930"},"issue":{"href":"https://api.github.com/repos/saltstack/salt/issues/21930"},"comments":{"href":"https://api.github.com/repos/saltstack/salt/issues/21930/comments"},"review_comments":{"href":"https://api.github.com/repos/saltstack/salt/pulls/21930/comments"},"review_comment":{"href":"https://api.github.com/repos/saltstack/salt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/saltstack/salt/pulls/21930/commits"},"statuses":{"href":"https://api.github.com/repos/saltstack/salt/statuses/15f66d1f0ff2b6b5519c0b08ad1dae7fc8c9230a"}}}}