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
}
]
}
}

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,18 +57,21 @@
"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": "64f3e119-408a-4b61-bce4-68114e2a727c"
"azdata_cell_guid": "64f3e119-408a-4b61-bce4-68114e2a727c",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -89,7 +93,10 @@
"run_command()"
],
"metadata": {
"azdata_cell_guid": "dd665751-efbc-4089-af1b-0fa456a4fb58"
"azdata_cell_guid": "dd665751-efbc-4089-af1b-0fa456a4fb58",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -123,7 +130,10 @@
"print(f'Port: {sql_port}')"
],
"metadata": {
"azdata_cell_guid": "a2e06bb2-23f3-4fc7-81bc-d38e250b24c0"
"azdata_cell_guid": "a2e06bb2-23f3-4fc7-81bc-d38e250b24c0",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -144,7 +154,10 @@
"run_command()"
],
"metadata": {
"azdata_cell_guid": "d75ae87c-2e59-4cf5-b61e-43f4bf8ac680"
"azdata_cell_guid": "d75ae87c-2e59-4cf5-b61e-43f4bf8ac680",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -166,11 +179,17 @@
"else:\n",
" container_name = 'sql2017-' + time.strftime(\"%Y%m%d%H%M%S\", time.localtime())\n",
"print('New container name: ' + container_name)\n",
"cmd = f'docker run -e ACCEPT_EULA=Y -e \"SA_PASSWORD={sql_password}\" -p {sql_port}:1433 --name {container_name} -d mcr.microsoft.com/mssql/server:2017-latest'\n",
"run_command()"
"\n",
"template = Template(f'docker run -e ACCEPT_EULA=Y -e \"SA_PASSWORD=$password\" -p {sql_port}:1433 --name {container_name} -d mcr.microsoft.com/mssql/server:2017-latest')\n",
"cmd = template.substitute(password=sql_password)\n",
"run_command(template.substitute(password='******'))\n",
""
],
"metadata": {
"azdata_cell_guid": "73585d5d-0c8c-4786-92f2-7e0fd2653f9e"
"azdata_cell_guid": "73585d5d-0c8c-4786-92f2-7e0fd2653f9e",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -191,7 +210,10 @@
"run_command()"
],
"metadata": {
"azdata_cell_guid": "5e30c110-a631-4c9b-8485-cd64d34c54d5"
"azdata_cell_guid": "5e30c110-a631-4c9b-8485-cd64d34c54d5",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -214,7 +236,10 @@
"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": "182517d3-f6d6-4ecc-b2cb-4c21a0f23b4e"
"azdata_cell_guid": "182517d3-f6d6-4ecc-b2cb-4c21a0f23b4e",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -238,7 +263,10 @@
"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": "1593a0a6-7009-4d0b-9f3f-ac7ed6d2bb1e"
"azdata_cell_guid": "1593a0a6-7009-4d0b-9f3f-ac7ed6d2bb1e",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null

View File

@@ -49,6 +49,7 @@
"cell_type": "code",
"source": [
"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,18 +57,21 @@
"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": "6196300e-f896-489b-8dca-b2c42eda2d6d"
"azdata_cell_guid": "6196300e-f896-489b-8dca-b2c42eda2d6d",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -89,7 +93,10 @@
"run_command()"
],
"metadata": {
"azdata_cell_guid": "26170d1b-4332-4383-bcc4-1d97030daffc"
"azdata_cell_guid": "26170d1b-4332-4383-bcc4-1d97030daffc",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -123,7 +130,10 @@
"print(f'Port: {sql_port}')"
],
"metadata": {
"azdata_cell_guid": "93cb0147-7bf6-4630-b796-3811dfd1354b"
"azdata_cell_guid": "93cb0147-7bf6-4630-b796-3811dfd1354b",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -144,7 +154,10 @@
"run_command()"
],
"metadata": {
"azdata_cell_guid": "7b102447-3198-488f-a995-982ae1fc8555"
"azdata_cell_guid": "7b102447-3198-488f-a995-982ae1fc8555",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -166,11 +179,16 @@
"else:\n",
" container_name = 'sql2019-' + time.strftime(\"%Y%m%d%H%M%S\", time.localtime())\n",
"print('New container name: ' + container_name)\n",
"cmd = f'docker run -e ACCEPT_EULA=Y -e \"SA_PASSWORD={sql_password}\" -p {sql_port}:1433 --name {container_name} -d mcr.microsoft.com/mssql/server:2019-latest'\n",
"run_command()"
"\n",
"template = Template(f'docker run -e ACCEPT_EULA=Y -e \"SA_PASSWORD=$password\" -p {sql_port}:1433 --name {container_name} -d mcr.microsoft.com/mssql/server:2019-latest')\n",
"cmd = template.substitute(password=sql_password)\n",
"run_command(template.substitute(password='******'))"
],
"metadata": {
"azdata_cell_guid": "82f27460-88eb-4484-92ee-40305e650d70"
"azdata_cell_guid": "82f27460-88eb-4484-92ee-40305e650d70",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -191,7 +209,10 @@
"run_command()"
],
"metadata": {
"azdata_cell_guid": "211ee198-f1d1-4781-9daa-8497c2665de6"
"azdata_cell_guid": "211ee198-f1d1-4781-9daa-8497c2665de6",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -214,7 +235,10 @@
"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": "4bc64915-c5ae-4507-8fb0-9e413ccc2fd0"
"azdata_cell_guid": "4bc64915-c5ae-4507-8fb0-9e413ccc2fd0",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null
@@ -238,7 +262,10 @@
"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": "f9e0f1ad-ba6e-4c17-84ea-cc5dceb1289b"
"azdata_cell_guid": "f9e0f1ad-ba6e-4c17-84ea-cc5dceb1289b",
"tags": [
"hide_input"
]
},
"outputs": [],
"execution_count": null