{"action":"created","comment":{"url":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/comments/68745702","id":68745702,"diff_hunk":"@@ -0,0 +1,128 @@\n+import glob\n+import re\n+\n+from fabric.api import run, put\n+\n+from host_setup import DOCKER_COMPOSE_EXECUTABLE, mkdir, provide_docker_compose\n+\n+\n+class CallList(object):\n+    def __init__(self, command, predicate=lambda: True):\n+        self.command_list = command\n+        self.base_command = ['echo']\n+        self.predicate = predicate\n+\n+    def execute(self, project, hostname, environment=None):\n+        if environment is None:\n+            environment = {}\n+        self.base_command = [\n+            '{}={}'.format(env_var_name, env_var_value) for env_var_name, env_var_value in environment.items()\n+        ] + self.base_command\n+        commands = self.base_command + \\\n+                   [command.format(project=project, hostname=hostname) for command in self.command_list]\n+        if self.predicate():\n+            return run(' '.join(commands))\n+\n+\n+class Docker(CallList):\n+    def __init__(self, command, predicate=lambda: True):\n+        super(Docker, self).__init__(command=command, predicate=predicate)\n+        self.base_command = ['docker']\n+\n+\n+class Compose(CallList):\n+    def __init__(self, command, predicate=lambda: True):\n+        super(Compose, self).__init__(command=command, predicate=predicate)\n+\n+        self.base_command = [DOCKER_COMPOSE_EXECUTABLE]\n+\n+    def execute(self, project, hostname, environment=None):\n+\n+        provide_docker_compose()\n+        compose_main_file = '{0}/docker-compose.yml'.format(project)\n+        compose_host_file = '{0}/{1}.yml'.format(project, hostname)\n+\n+        mkdir(project)\n+\n+        put(local_path=compose_main_file, remote_path=compose_main_file)\n+        put(local_path=compose_host_file, remote_path=compose_host_file)\n+        env_file_path = \"{}/*.env\".format(project)\n+        if len(glob.glob(env_file_path)) > 0:\n+            put(local_path=\"{}/*.env\".format(project), remote_path=\"{}/\".format(project))\n+\n+        self.base_command += [\n+            '-f', compose_main_file, '-f', compose_host_file\n+        ]\n+        super(Compose, self).execute(project, hostname, environment=environment)\n+\n+\n+def is_running(container_name, name_is_regex=False):\n+    if not name_is_regex:\n+        container_name = re.escape(container_name)\n+    result = run('docker ps')\n+    m = re.search(r'\\ {}\\r?$'.format(container_name), result, flags=re.MULTILINE)\n+    return m is not None\n+\n+\n+def is_not_running(container_name, name_is_regex=False):\n+    return not is_running(container_name, name_is_regex=name_is_regex)\n+\n+\n+def has_succeeded(container_name, name_is_regex=False):\n+    if not name_is_regex:\n+        container_name = re.escape(container_name)\n+    result = run('docker ps -a')\n+    pattern = r'{status}.*{container_name}\\r?$'.format(status=re.escape('Exited (0)'), container_name=container_name)\n+    m = re.search(pattern, result, flags=re.MULTILINE)\n+    return m is not None\n+\n+\n+def has_not_succeeded(container_name, name_is_regex=False):\n+    return not has_succeeded(container_name, name_is_regex=name_is_regex)\n+\n+\n+def container_exists(container_name, name_is_regex=False):\n+    if not name_is_regex:\n+        container_name = re.escape(container_name)\n+    result = run('docker ps -a')\n+    pattern = r'.*{container_name}\\r?$'.format(container_name=container_name)\n+    m = re.search(pattern, result, flags=re.MULTILINE)\n+    return m is not None\n+\n+\n+def container_not_exists(container_name, name_is_regex=False):\n+    return not container_exists(container_name, name_is_regex=name_is_regex)\n+\n+\n+def has_succeeded_or_is_running(container_name, name_is_regex=False):\n+    return is_running(container_name, name_is_regex=name_is_regex) or has_succeeded(container_name, name_is_regex=name_is_regex)\n+\n+\n+def not_has_succeeded_or_is_running(container_name, name_is_regex=False):","path":"command_definitions.py","position":101,"original_position":101,"commit_id":"d4c270f1cb4e7ce74894b77c17be823c45755015","original_commit_id":"10338a390ef2f4654bed68e8105cafab8845992d","user":{"login":"hixi","id":97119,"avatar_url":"https://avatars.githubusercontent.com/u/97119?v=3","gravatar_id":"","url":"https://api.github.com/users/hixi","html_url":"https://github.com/hixi","followers_url":"https://api.github.com/users/hixi/followers","following_url":"https://api.github.com/users/hixi/following{/other_user}","gists_url":"https://api.github.com/users/hixi/gists{/gist_id}","starred_url":"https://api.github.com/users/hixi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hixi/subscriptions","organizations_url":"https://api.github.com/users/hixi/orgs","repos_url":"https://api.github.com/users/hixi/repos","events_url":"https://api.github.com/users/hixi/events{/privacy}","received_events_url":"https://api.github.com/users/hixi/received_events","type":"User","site_admin":false},"body":"I like `neither_has_succeeded_nor_is_running` because it doesn't use the (confusing) not operator in the name.","created_at":"2016-06-28T12:23:17Z","updated_at":"2016-06-28T12:23:17Z","html_url":"https://github.com/geometalab/osmaxx-deploy/pull/1#discussion_r68745702","pull_request_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/comments/68745702"},"html":{"href":"https://github.com/geometalab/osmaxx-deploy/pull/1#discussion_r68745702"},"pull_request":{"href":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/1","id":75379760,"html_url":"https://github.com/geometalab/osmaxx-deploy/pull/1","diff_url":"https://github.com/geometalab/osmaxx-deploy/pull/1.diff","patch_url":"https://github.com/geometalab/osmaxx-deploy/pull/1.patch","issue_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/issues/1","number":1,"state":"open","locked":false,"title":"Feature/first trial","user":{"login":"hixi","id":97119,"avatar_url":"https://avatars.githubusercontent.com/u/97119?v=3","gravatar_id":"","url":"https://api.github.com/users/hixi","html_url":"https://github.com/hixi","followers_url":"https://api.github.com/users/hixi/followers","following_url":"https://api.github.com/users/hixi/following{/other_user}","gists_url":"https://api.github.com/users/hixi/gists{/gist_id}","starred_url":"https://api.github.com/users/hixi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hixi/subscriptions","organizations_url":"https://api.github.com/users/hixi/orgs","repos_url":"https://api.github.com/users/hixi/repos","events_url":"https://api.github.com/users/hixi/events{/privacy}","received_events_url":"https://api.github.com/users/hixi/received_events","type":"User","site_admin":false},"body":"Reviewed by:\r\n- [x] @das-g \r\n","created_at":"2016-06-27T21:04:49Z","updated_at":"2016-06-28T12:23:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"024a375b851950c49d0ee2c817be2859151c3bae","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/1/commits","review_comments_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/1/comments","review_comment_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/issues/1/comments","statuses_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/statuses/d4c270f1cb4e7ce74894b77c17be823c45755015","head":{"label":"geometalab:feature/first_trial","ref":"feature/first_trial","sha":"d4c270f1cb4e7ce74894b77c17be823c45755015","user":{"login":"geometalab","id":8266374,"avatar_url":"https://avatars.githubusercontent.com/u/8266374?v=3","gravatar_id":"","url":"https://api.github.com/users/geometalab","html_url":"https://github.com/geometalab","followers_url":"https://api.github.com/users/geometalab/followers","following_url":"https://api.github.com/users/geometalab/following{/other_user}","gists_url":"https://api.github.com/users/geometalab/gists{/gist_id}","starred_url":"https://api.github.com/users/geometalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geometalab/subscriptions","organizations_url":"https://api.github.com/users/geometalab/orgs","repos_url":"https://api.github.com/users/geometalab/repos","events_url":"https://api.github.com/users/geometalab/events{/privacy}","received_events_url":"https://api.github.com/users/geometalab/received_events","type":"Organization","site_admin":false},"repo":{"id":61713284,"name":"osmaxx-deploy","full_name":"geometalab/osmaxx-deploy","owner":{"login":"geometalab","id":8266374,"avatar_url":"https://avatars.githubusercontent.com/u/8266374?v=3","gravatar_id":"","url":"https://api.github.com/users/geometalab","html_url":"https://github.com/geometalab","followers_url":"https://api.github.com/users/geometalab/followers","following_url":"https://api.github.com/users/geometalab/following{/other_user}","gists_url":"https://api.github.com/users/geometalab/gists{/gist_id}","starred_url":"https://api.github.com/users/geometalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geometalab/subscriptions","organizations_url":"https://api.github.com/users/geometalab/orgs","repos_url":"https://api.github.com/users/geometalab/repos","events_url":"https://api.github.com/users/geometalab/events{/privacy}","received_events_url":"https://api.github.com/users/geometalab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/geometalab/osmaxx-deploy","description":"Deployment scripts for OSMaxx","fork":false,"url":"https://api.github.com/repos/geometalab/osmaxx-deploy","forks_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/forks","keys_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/teams","hooks_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/hooks","issue_events_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/issues/events{/number}","events_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/events","assignees_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/assignees{/user}","branches_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/branches{/branch}","tags_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/tags","blobs_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/git/refs{/sha}","trees_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/statuses/{sha}","languages_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/languages","stargazers_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/stargazers","contributors_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/contributors","subscribers_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/subscribers","subscription_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/subscription","commits_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/commits{/sha}","git_commits_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/git/commits{/sha}","comments_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/comments{/number}","issue_comment_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/issues/comments{/number}","contents_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/contents/{+path}","compare_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/merges","archive_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/downloads","issues_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/issues{/number}","pulls_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls{/number}","milestones_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/milestones{/number}","notifications_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/labels{/name}","releases_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/releases{/id}","deployments_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/deployments","created_at":"2016-06-22T11:19:48Z","updated_at":"2016-06-22T11:19:48Z","pushed_at":"2016-06-28T11:58:35Z","git_url":"git://github.com/geometalab/osmaxx-deploy.git","ssh_url":"git@github.com:geometalab/osmaxx-deploy.git","clone_url":"https://github.com/geometalab/osmaxx-deploy.git","svn_url":"https://github.com/geometalab/osmaxx-deploy","homepage":null,"size":37,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"geometalab:master","ref":"master","sha":"3a4c5b3a389653d8d75daa32d9ab15b696d7c2b4","user":{"login":"geometalab","id":8266374,"avatar_url":"https://avatars.githubusercontent.com/u/8266374?v=3","gravatar_id":"","url":"https://api.github.com/users/geometalab","html_url":"https://github.com/geometalab","followers_url":"https://api.github.com/users/geometalab/followers","following_url":"https://api.github.com/users/geometalab/following{/other_user}","gists_url":"https://api.github.com/users/geometalab/gists{/gist_id}","starred_url":"https://api.github.com/users/geometalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geometalab/subscriptions","organizations_url":"https://api.github.com/users/geometalab/orgs","repos_url":"https://api.github.com/users/geometalab/repos","events_url":"https://api.github.com/users/geometalab/events{/privacy}","received_events_url":"https://api.github.com/users/geometalab/received_events","type":"Organization","site_admin":false},"repo":{"id":61713284,"name":"osmaxx-deploy","full_name":"geometalab/osmaxx-deploy","owner":{"login":"geometalab","id":8266374,"avatar_url":"https://avatars.githubusercontent.com/u/8266374?v=3","gravatar_id":"","url":"https://api.github.com/users/geometalab","html_url":"https://github.com/geometalab","followers_url":"https://api.github.com/users/geometalab/followers","following_url":"https://api.github.com/users/geometalab/following{/other_user}","gists_url":"https://api.github.com/users/geometalab/gists{/gist_id}","starred_url":"https://api.github.com/users/geometalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geometalab/subscriptions","organizations_url":"https://api.github.com/users/geometalab/orgs","repos_url":"https://api.github.com/users/geometalab/repos","events_url":"https://api.github.com/users/geometalab/events{/privacy}","received_events_url":"https://api.github.com/users/geometalab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/geometalab/osmaxx-deploy","description":"Deployment scripts for OSMaxx","fork":false,"url":"https://api.github.com/repos/geometalab/osmaxx-deploy","forks_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/forks","keys_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/teams","hooks_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/hooks","issue_events_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/issues/events{/number}","events_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/events","assignees_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/assignees{/user}","branches_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/branches{/branch}","tags_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/tags","blobs_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/git/refs{/sha}","trees_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/statuses/{sha}","languages_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/languages","stargazers_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/stargazers","contributors_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/contributors","subscribers_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/subscribers","subscription_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/subscription","commits_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/commits{/sha}","git_commits_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/git/commits{/sha}","comments_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/comments{/number}","issue_comment_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/issues/comments{/number}","contents_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/contents/{+path}","compare_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/merges","archive_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/downloads","issues_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/issues{/number}","pulls_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls{/number}","milestones_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/milestones{/number}","notifications_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/labels{/name}","releases_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/releases{/id}","deployments_url":"https://api.github.com/repos/geometalab/osmaxx-deploy/deployments","created_at":"2016-06-22T11:19:48Z","updated_at":"2016-06-22T11:19:48Z","pushed_at":"2016-06-28T11:58:35Z","git_url":"git://github.com/geometalab/osmaxx-deploy.git","ssh_url":"git@github.com:geometalab/osmaxx-deploy.git","clone_url":"https://github.com/geometalab/osmaxx-deploy.git","svn_url":"https://github.com/geometalab/osmaxx-deploy","homepage":null,"size":37,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/1"},"html":{"href":"https://github.com/geometalab/osmaxx-deploy/pull/1"},"issue":{"href":"https://api.github.com/repos/geometalab/osmaxx-deploy/issues/1"},"comments":{"href":"https://api.github.com/repos/geometalab/osmaxx-deploy/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/geometalab/osmaxx-deploy/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/geometalab/osmaxx-deploy/statuses/d4c270f1cb4e7ce74894b77c17be823c45755015"}}}}
{"actor":{"display_login":"hixi"}}