add to parameter to decide whether to print the command (#11052)

* don't print command

* show password as ******
This commit is contained in:
Alan Ren
2020-06-24 15:20:06 -07:00
committed by GitHub
parent c3fbce4b83
commit da9e58485b
3 changed files with 135 additions and 54 deletions

View File

@@ -48,7 +48,8 @@
{
"cell_type": "code",
"source": [
"import pandas,sys,getpass,os,json,html,time\n",
"import pandas,sys,os,getpass,json,html,time\n",
"from string import Template\n",
"pandas_version = pandas.__version__.split('.')\n",
"pandas_major = int(pandas_version[0])\n",
"pandas_minor = int(pandas_version[1])\n",
@@ -56,21 +57,24 @@
"if not (pandas_major > 0 or (pandas_major == 0 and pandas_minor > 24) or (pandas_major == 0 and pandas_minor == 24 and pandas_patch >= 2)):\n",
" sys.exit('Please upgrade the Notebook dependency before you can proceed, you can do it by running the \"Reinstall Notebook dependencies\" command in command palette (View menu -> Command Palette…).')\n",
"\n",
"def run_command():\n",
" print(\"Executing: \" + cmd)\n",
"def run_command(displayCommand = \"\"):\n",
" print(\"Executing: \" + (displayCommand if displayCommand != \"\" else cmd))\n",
" !{cmd}\n",
" if _exit_code != 0:\n",
" sys.exit(f'Command execution failed with exit code: {str(_exit_code)}.\\n\\t{cmd}\\n')\n",
" print(f'Successfully executed: {cmd}')\n",
" sys.exit(f'Command execution failed with exit code: {str(_exit_code)}.\\n')\n",
" print(f'Command successfully executed')\n",
"\n",
"cmd = 'docker version'\n",
"run_command()"
],
"metadata": {
"azdata_cell_guid": "a0a8cd9b-ab0f-4ba2-b568-0c68d950c8bf"
"azdata_cell_guid": "a0a8cd9b-ab0f-4ba2-b568-0c68d950c8bf",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": 1
"execution_count": null
},
{
"cell_type": "markdown",
@@ -89,10 +93,13 @@
"run_command()"
],
"metadata": {
"azdata_cell_guid": "5a253372-1a98-4b07-a3e0-9ae5f47cb0a5"
"azdata_cell_guid": "5a253372-1a98-4b07-a3e0-9ae5f47cb0a5",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": 2
"execution_count": null
},
{
"cell_type": "markdown",
@@ -139,10 +146,13 @@
"print(f'Image tag: {docker_imagetag}')"
],
"metadata": {
"azdata_cell_guid": "c0af4e4e-4232-4a67-9a21-05a4d54fd0f4"
"azdata_cell_guid": "c0af4e4e-4232-4a67-9a21-05a4d54fd0f4",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": 3
"execution_count": null
},
{
"cell_type": "markdown",
@@ -158,15 +168,18 @@
"source": [
"if docker_username != '':\n",
" cmd = f'docker login {docker_registry} -u {docker_username} -p {docker_password}'\n",
" run_command()\n",
" run_command(False)\n",
"cmd = f'docker pull {docker_registry}/{docker_repository}:{docker_imagetag}'\n",
"run_command()"
],
"metadata": {
"azdata_cell_guid": "58b2156b-da0c-47d5-9706-4bd9f630d28b"
"azdata_cell_guid": "58b2156b-da0c-47d5-9706-4bd9f630d28b",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": 4
"execution_count": null
},
{
"cell_type": "markdown",
@@ -180,14 +193,18 @@
{
"cell_type": "code",
"source": [
"cmd = f'docker run -e ACCEPT_EULA=Y -e \"SA_PASSWORD={sql_password}\" -p {sql_port}:1433 --name {container_name} -d {docker_registry}/{docker_repository}:{docker_imagetag}'\n",
"run_command()"
"template = Template(f'docker run -e ACCEPT_EULA=Y -e \"SA_PASSWORD=$password\" -p {sql_port}:1433 --name {container_name} -d {docker_registry}/{docker_repository}:{docker_imagetag}')\n",
"cmd = template.substitute(password=sql_password)\n",
"run_command(template.substitute(password='******'))"
],
"metadata": {
"azdata_cell_guid": "4cdcf011-06fd-4df4-bd20-3024d0a5ab9d"
"azdata_cell_guid": "4cdcf011-06fd-4df4-bd20-3024d0a5ab9d",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": 5
"execution_count": null
},
{
"cell_type": "markdown",
@@ -205,10 +222,13 @@
"run_command()"
],
"metadata": {
"azdata_cell_guid": "345dc24f-0028-47b4-b35b-aaac047b7a62"
"azdata_cell_guid": "345dc24f-0028-47b4-b35b-aaac047b7a62",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": 6
"execution_count": null
},
{
"cell_type": "markdown",
@@ -228,10 +248,13 @@
"display(HTML('<br/><a href=\"command:azdata.connect?' + html.escape(connectionParameter)+'\"><font size=\"3\">Click here to connect to SQL Server</font></a><br/>'))"
],
"metadata": {
"azdata_cell_guid": "187a0067-a04c-4afb-a684-3103bb4522ae"
"azdata_cell_guid": "187a0067-a04c-4afb-a684-3103bb4522ae",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": 7
"execution_count": null
},
{
"cell_type": "markdown",
@@ -252,10 +275,13 @@
"display(HTML(\"Remove the container: <a href=\\\"command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22\"+remove_container_command.replace(\" \",\"%20\")+\"%22%7D\\\">\" + remove_container_command + \"</a>\"))"
],
"metadata": {
"azdata_cell_guid": "9b6c34c2-7a47-43f5-971d-ce9768fec587"
"azdata_cell_guid": "9b6c34c2-7a47-43f5-971d-ce9768fec587",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": 8
"execution_count": null
}
]
}
}