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,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