{"action":"created","comment":{"url":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/comments/44602275","id":44602275,"diff_hunk":"@@ -517,3 +525,205 @@ def _uninstall(package_name, remove_all, app_id, cli, app):\n         return 1\n \n     return 0\n+\n+\n+def _bundle(package_directory, output_directory):\n+    \"\"\"\n+    :param package_directory: directory containing the package\n+    :type package_directory: str\n+    :param output_directory: directory where to save the package zip file\n+    :type output_directory: str\n+    :returns: process status\n+    :rtype: int\n+    \"\"\"\n+\n+    if output_directory is None:\n+        output_directory = os.getcwd()\n+    logger.debug('Using [%s] as the ouput directory', output_directory)\n+\n+    # Find package.json file and parse it\n+    package_json = _validate_json_file(\n+        os.path.join(package_directory, 'package.json'))\n+\n+    with tempfile.NamedTemporaryFile() as temp_file:\n+        with zipfile.ZipFile(\n+                temp_file.name,\n+                mode='w',\n+                compression=zipfile.ZIP_DEFLATED,\n+                allowZip64=True) as zip_file:\n+            # list through package directory and add files zip archive\n+            for filename in sorted(os.listdir(package_directory)):\n+                fullpath = os.path.join(package_directory, filename)\n+                if filename == 'marathon.json.mustache':\n+                    zip_file.write(fullpath, arcname=filename)\n+                elif (filename == 'config.json' or\n+                        filename == 'command.json' or\n+                        filename == 'package.json'):\n+                    # schema check the config and command json file\n+                    _validate_json_file(fullpath)\n+                    zip_file.write(fullpath, arcname=filename)\n+                elif filename == 'assets' and os.path.isdir(fullpath):\n+                    _import_assets(fullpath, zip_file)\n+                elif filename == 'images' and os.path.isdir(fullpath):\n+                    _import_images(fullpath, zip_file)\n+                else:\n+                    # anything else is an error\n+                    raise DCOSException('Unknown file [{}]'.format(fullpath))\n+\n+        # Compute the name of the package file\n+        zip_file_name = os.path.join(\n+            output_directory,\n+            '{}-{}-{}.zip'.format(\n+                package_json['name'],\n+                package_json['version'],\n+                _hashfile(temp_file.name)))\n+\n+        if os.path.exists(zip_file_name):\n+            raise DCOSException(\n+                'Output file [{}] already exists'.format(\n+                    zip_file_name))\n+\n+        # rename with digest\n+        util.sh_copy(temp_file.name, zip_file_name)\n+\n+    # Print the full path to the file\n+    emitter.publish(\n+        errors.DefaultError(\n+            'Created DCOS Universe package [{}].'.format(zip_file_name)))\n+\n+    return 0\n+\n+\n+def _validate_json_file(fullpath):\n+    \"\"\"Validates the content of the file against its schema. Throws an\n+    exception if the file is not valid.\n+\n+    :param fullpath: full path to the file.\n+    :type fullpath: str\n+    :return: json object if it is a special file\n+    :rtype: dict\n+    \"\"\"\n+\n+    if os.path.basename(fullpath) == 'command.json':\n+        schema_path = 'data/universe-schema/command.json'\n+    elif os.path.basename(fullpath) == 'config.json':\n+        schema_path = 'data/universe-schema/config.json'\n+    elif os.path.basename(fullpath) == 'package.json':\n+        schema_path = 'data/universe-schema/package.json'\n+    else:\n+        raise DCOSException(('Error while process package directory. Unknown '\n+                             'file: {}').format(fullpath))\n+\n+    special_schema = util.load_jsons(\n+        pkg_resources.resource_string('dcoscli', schema_path).decode('utf-8'))\n+\n+    with util.open_file(fullpath) as special_file:\n+        special_json = util.load_json(special_file)\n+\n+    errs = util.validate_json(special_json, special_schema)\n+    if errs:\n+        emitter.publish(\n+            errors.DefaultError(\n+                'Error validating JSON file [{}]'.format(fullpath)))\n+        raise DCOSException(util.list_to_err(errs))\n+\n+    return special_json\n+\n+\n+def _hashfile(filename):\n+    \"\"\"Calculates the sha256 of a file\n+\n+    :param filename: path to the file to sum\n+    :type filename: str\n+    :returns: digest in hexadecimal\n+    :rtype: str\n+    \"\"\"\n+\n+    hasher = hashlib.sha256()\n+    with open(filename, 'rb') as f:\n+        for chunk in iter(lambda: f.read(4096), b''):\n+            hasher.update(chunk)\n+    return hasher.hexdigest()\n+\n+\n+def _import_assets(assets_directory, zip_file):\n+    \"\"\"Import the assets directory\n+\n+    :param assets_directory: path to the assets directory\n+    :type assets_directory: str\n+    :param zip_file: zip file object\n+    :type zip_file: zipfile.ZipFile\n+    :rtype: None\n+    \"\"\"\n+\n+    for filename in sorted(os.listdir(assets_directory)):\n+        fullpath = os.path.join(assets_directory, filename)\n+        if filename == 'uris' and os.path.isdir(fullpath):\n+            _import_uris(fullpath, zip_file)\n+        else:\n+            # anything else is an error\n+            raise DCOSException(\n+                'Unknown file [{}]'.format(fullpath))","path":"cli/dcoscli/package/main.py","position":201,"original_position":201,"commit_id":"7da2afb7f3c64b5dd999f004dc83204a8da18a74","original_commit_id":"7da2afb7f3c64b5dd999f004dc83204a8da18a74","user":{"login":"jsancio","id":794394,"avatar_url":"https://avatars.githubusercontent.com/u/794394?v=3","gravatar_id":"","url":"https://api.github.com/users/jsancio","html_url":"https://github.com/jsancio","followers_url":"https://api.github.com/users/jsancio/followers","following_url":"https://api.github.com/users/jsancio/following{/other_user}","gists_url":"https://api.github.com/users/jsancio/gists{/gist_id}","starred_url":"https://api.github.com/users/jsancio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsancio/subscriptions","organizations_url":"https://api.github.com/users/jsancio/orgs","repos_url":"https://api.github.com/users/jsancio/repos","events_url":"https://api.github.com/users/jsancio/events{/privacy}","received_events_url":"https://api.github.com/users/jsancio/received_events","type":"User","site_admin":false},"body":"Hmm. Maybe we should print: \"Error bundling. Extra file in package directory [...]\".","created_at":"2015-11-11T23:24:55Z","updated_at":"2015-11-11T23:24:55Z","html_url":"https://github.com/mesosphere/dcos-cli/pull/370#discussion_r44602275","pull_request_url":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/370","_links":{"self":{"href":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/comments/44602275"},"html":{"href":"https://github.com/mesosphere/dcos-cli/pull/370#discussion_r44602275"},"pull_request":{"href":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/370"}}},"pull_request":{"url":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/370","id":49767393,"html_url":"https://github.com/mesosphere/dcos-cli/pull/370","diff_url":"https://github.com/mesosphere/dcos-cli/pull/370.diff","patch_url":"https://github.com/mesosphere/dcos-cli/pull/370.patch","issue_url":"https://api.github.com/repos/mesosphere/dcos-cli/issues/370","number":370,"state":"open","locked":false,"title":"Dcos 3254 package create","user":{"login":"jsancio","id":794394,"avatar_url":"https://avatars.githubusercontent.com/u/794394?v=3","gravatar_id":"","url":"https://api.github.com/users/jsancio","html_url":"https://github.com/jsancio","followers_url":"https://api.github.com/users/jsancio/followers","following_url":"https://api.github.com/users/jsancio/following{/other_user}","gists_url":"https://api.github.com/users/jsancio/gists{/gist_id}","starred_url":"https://api.github.com/users/jsancio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsancio/subscriptions","organizations_url":"https://api.github.com/users/jsancio/orgs","repos_url":"https://api.github.com/users/jsancio/repos","events_url":"https://api.github.com/users/jsancio/events{/privacy}","received_events_url":"https://api.github.com/users/jsancio/received_events","type":"User","site_admin":false},"body":"@tamarrow. The majority of the implementation and tests are done. I need to go through the diff in detail in clean stuff a bit.","created_at":"2015-11-05T00:34:45Z","updated_at":"2015-11-11T23:24:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"53f5dd16d2e30a4d2c7ccf1d5241f8ec93bdd67c","assignee":{"login":"tamarrow","id":1292768,"avatar_url":"https://avatars.githubusercontent.com/u/1292768?v=3","gravatar_id":"","url":"https://api.github.com/users/tamarrow","html_url":"https://github.com/tamarrow","followers_url":"https://api.github.com/users/tamarrow/followers","following_url":"https://api.github.com/users/tamarrow/following{/other_user}","gists_url":"https://api.github.com/users/tamarrow/gists{/gist_id}","starred_url":"https://api.github.com/users/tamarrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tamarrow/subscriptions","organizations_url":"https://api.github.com/users/tamarrow/orgs","repos_url":"https://api.github.com/users/tamarrow/repos","events_url":"https://api.github.com/users/tamarrow/events{/privacy}","received_events_url":"https://api.github.com/users/tamarrow/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/370/commits","review_comments_url":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/370/comments","review_comment_url":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mesosphere/dcos-cli/issues/370/comments","statuses_url":"https://api.github.com/repos/mesosphere/dcos-cli/statuses/7da2afb7f3c64b5dd999f004dc83204a8da18a74","head":{"label":"mesosphere:dcos-3254-package-create","ref":"dcos-3254-package-create","sha":"7da2afb7f3c64b5dd999f004dc83204a8da18a74","user":{"login":"mesosphere","id":3458585,"avatar_url":"https://avatars.githubusercontent.com/u/3458585?v=3","gravatar_id":"","url":"https://api.github.com/users/mesosphere","html_url":"https://github.com/mesosphere","followers_url":"https://api.github.com/users/mesosphere/followers","following_url":"https://api.github.com/users/mesosphere/following{/other_user}","gists_url":"https://api.github.com/users/mesosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/mesosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mesosphere/subscriptions","organizations_url":"https://api.github.com/users/mesosphere/orgs","repos_url":"https://api.github.com/users/mesosphere/repos","events_url":"https://api.github.com/users/mesosphere/events{/privacy}","received_events_url":"https://api.github.com/users/mesosphere/received_events","type":"Organization","site_admin":false},"repo":{"id":26653348,"name":"dcos-cli","full_name":"mesosphere/dcos-cli","owner":{"login":"mesosphere","id":3458585,"avatar_url":"https://avatars.githubusercontent.com/u/3458585?v=3","gravatar_id":"","url":"https://api.github.com/users/mesosphere","html_url":"https://github.com/mesosphere","followers_url":"https://api.github.com/users/mesosphere/followers","following_url":"https://api.github.com/users/mesosphere/following{/other_user}","gists_url":"https://api.github.com/users/mesosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/mesosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mesosphere/subscriptions","organizations_url":"https://api.github.com/users/mesosphere/orgs","repos_url":"https://api.github.com/users/mesosphere/repos","events_url":"https://api.github.com/users/mesosphere/events{/privacy}","received_events_url":"https://api.github.com/users/mesosphere/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mesosphere/dcos-cli","description":"The command line for your datacenter! ","fork":false,"url":"https://api.github.com/repos/mesosphere/dcos-cli","forks_url":"https://api.github.com/repos/mesosphere/dcos-cli/forks","keys_url":"https://api.github.com/repos/mesosphere/dcos-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mesosphere/dcos-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mesosphere/dcos-cli/teams","hooks_url":"https://api.github.com/repos/mesosphere/dcos-cli/hooks","issue_events_url":"https://api.github.com/repos/mesosphere/dcos-cli/issues/events{/number}","events_url":"https://api.github.com/repos/mesosphere/dcos-cli/events","assignees_url":"https://api.github.com/repos/mesosphere/dcos-cli/assignees{/user}","branches_url":"https://api.github.com/repos/mesosphere/dcos-cli/branches{/branch}","tags_url":"https://api.github.com/repos/mesosphere/dcos-cli/tags","blobs_url":"https://api.github.com/repos/mesosphere/dcos-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mesosphere/dcos-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mesosphere/dcos-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/mesosphere/dcos-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mesosphere/dcos-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/mesosphere/dcos-cli/languages","stargazers_url":"https://api.github.com/repos/mesosphere/dcos-cli/stargazers","contributors_url":"https://api.github.com/repos/mesosphere/dcos-cli/contributors","subscribers_url":"https://api.github.com/repos/mesosphere/dcos-cli/subscribers","subscription_url":"https://api.github.com/repos/mesosphere/dcos-cli/subscription","commits_url":"https://api.github.com/repos/mesosphere/dcos-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/mesosphere/dcos-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/mesosphere/dcos-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/mesosphere/dcos-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/mesosphere/dcos-cli/contents/{+path}","compare_url":"https://api.github.com/repos/mesosphere/dcos-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mesosphere/dcos-cli/merges","archive_url":"https://api.github.com/repos/mesosphere/dcos-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mesosphere/dcos-cli/downloads","issues_url":"https://api.github.com/repos/mesosphere/dcos-cli/issues{/number}","pulls_url":"https://api.github.com/repos/mesosphere/dcos-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/mesosphere/dcos-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/mesosphere/dcos-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mesosphere/dcos-cli/labels{/name}","releases_url":"https://api.github.com/repos/mesosphere/dcos-cli/releases{/id}","created_at":"2014-11-14T19:11:48Z","updated_at":"2015-11-09T08:38:58Z","pushed_at":"2015-11-11T18:02:29Z","git_url":"git://github.com/mesosphere/dcos-cli.git","ssh_url":"git@github.com:mesosphere/dcos-cli.git","clone_url":"https://github.com/mesosphere/dcos-cli.git","svn_url":"https://github.com/mesosphere/dcos-cli","homepage":"http://docs.mesosphere.com/using/cli/","size":7662,"stargazers_count":54,"watchers_count":54,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":12,"forks":15,"open_issues":12,"watchers":54,"default_branch":"master"}},"base":{"label":"mesosphere:master","ref":"master","sha":"f592aab064e87417906df9698a1cf0ac9f3fea5c","user":{"login":"mesosphere","id":3458585,"avatar_url":"https://avatars.githubusercontent.com/u/3458585?v=3","gravatar_id":"","url":"https://api.github.com/users/mesosphere","html_url":"https://github.com/mesosphere","followers_url":"https://api.github.com/users/mesosphere/followers","following_url":"https://api.github.com/users/mesosphere/following{/other_user}","gists_url":"https://api.github.com/users/mesosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/mesosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mesosphere/subscriptions","organizations_url":"https://api.github.com/users/mesosphere/orgs","repos_url":"https://api.github.com/users/mesosphere/repos","events_url":"https://api.github.com/users/mesosphere/events{/privacy}","received_events_url":"https://api.github.com/users/mesosphere/received_events","type":"Organization","site_admin":false},"repo":{"id":26653348,"name":"dcos-cli","full_name":"mesosphere/dcos-cli","owner":{"login":"mesosphere","id":3458585,"avatar_url":"https://avatars.githubusercontent.com/u/3458585?v=3","gravatar_id":"","url":"https://api.github.com/users/mesosphere","html_url":"https://github.com/mesosphere","followers_url":"https://api.github.com/users/mesosphere/followers","following_url":"https://api.github.com/users/mesosphere/following{/other_user}","gists_url":"https://api.github.com/users/mesosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/mesosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mesosphere/subscriptions","organizations_url":"https://api.github.com/users/mesosphere/orgs","repos_url":"https://api.github.com/users/mesosphere/repos","events_url":"https://api.github.com/users/mesosphere/events{/privacy}","received_events_url":"https://api.github.com/users/mesosphere/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mesosphere/dcos-cli","description":"The command line for your datacenter! ","fork":false,"url":"https://api.github.com/repos/mesosphere/dcos-cli","forks_url":"https://api.github.com/repos/mesosphere/dcos-cli/forks","keys_url":"https://api.github.com/repos/mesosphere/dcos-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mesosphere/dcos-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mesosphere/dcos-cli/teams","hooks_url":"https://api.github.com/repos/mesosphere/dcos-cli/hooks","issue_events_url":"https://api.github.com/repos/mesosphere/dcos-cli/issues/events{/number}","events_url":"https://api.github.com/repos/mesosphere/dcos-cli/events","assignees_url":"https://api.github.com/repos/mesosphere/dcos-cli/assignees{/user}","branches_url":"https://api.github.com/repos/mesosphere/dcos-cli/branches{/branch}","tags_url":"https://api.github.com/repos/mesosphere/dcos-cli/tags","blobs_url":"https://api.github.com/repos/mesosphere/dcos-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mesosphere/dcos-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mesosphere/dcos-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/mesosphere/dcos-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mesosphere/dcos-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/mesosphere/dcos-cli/languages","stargazers_url":"https://api.github.com/repos/mesosphere/dcos-cli/stargazers","contributors_url":"https://api.github.com/repos/mesosphere/dcos-cli/contributors","subscribers_url":"https://api.github.com/repos/mesosphere/dcos-cli/subscribers","subscription_url":"https://api.github.com/repos/mesosphere/dcos-cli/subscription","commits_url":"https://api.github.com/repos/mesosphere/dcos-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/mesosphere/dcos-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/mesosphere/dcos-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/mesosphere/dcos-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/mesosphere/dcos-cli/contents/{+path}","compare_url":"https://api.github.com/repos/mesosphere/dcos-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mesosphere/dcos-cli/merges","archive_url":"https://api.github.com/repos/mesosphere/dcos-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mesosphere/dcos-cli/downloads","issues_url":"https://api.github.com/repos/mesosphere/dcos-cli/issues{/number}","pulls_url":"https://api.github.com/repos/mesosphere/dcos-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/mesosphere/dcos-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/mesosphere/dcos-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mesosphere/dcos-cli/labels{/name}","releases_url":"https://api.github.com/repos/mesosphere/dcos-cli/releases{/id}","created_at":"2014-11-14T19:11:48Z","updated_at":"2015-11-09T08:38:58Z","pushed_at":"2015-11-11T18:02:29Z","git_url":"git://github.com/mesosphere/dcos-cli.git","ssh_url":"git@github.com:mesosphere/dcos-cli.git","clone_url":"https://github.com/mesosphere/dcos-cli.git","svn_url":"https://github.com/mesosphere/dcos-cli","homepage":"http://docs.mesosphere.com/using/cli/","size":7662,"stargazers_count":54,"watchers_count":54,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":12,"forks":15,"open_issues":12,"watchers":54,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/370"},"html":{"href":"https://github.com/mesosphere/dcos-cli/pull/370"},"issue":{"href":"https://api.github.com/repos/mesosphere/dcos-cli/issues/370"},"comments":{"href":"https://api.github.com/repos/mesosphere/dcos-cli/issues/370/comments"},"review_comments":{"href":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/370/comments"},"review_comment":{"href":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mesosphere/dcos-cli/pulls/370/commits"},"statuses":{"href":"https://api.github.com/repos/mesosphere/dcos-cli/statuses/7da2afb7f3c64b5dd999f004dc83204a8da18a74"}}}}