mirror of
https://github.com/88lex/safire.git
synced 2024-09-20 14:56:06 +08:00
Created using Colaboratory
This commit is contained in:
parent
8b689e3b1f
commit
7b07297ef2
141
safire.ipynb
141
safire.ipynb
|
@ -7,7 +7,13 @@
|
||||||
"provenance": [],
|
"provenance": [],
|
||||||
"private_outputs": true,
|
"private_outputs": true,
|
||||||
"collapsed_sections": [
|
"collapsed_sections": [
|
||||||
"Ov-m1nFU9jry"
|
"Ov-m1nFU9jry",
|
||||||
|
"1FV-VHZsLkhG",
|
||||||
|
"WmnTaw3f9DF3",
|
||||||
|
"2NcemUMdp92X",
|
||||||
|
"0882m2pipfVU",
|
||||||
|
"FEwTp1m6pA_-",
|
||||||
|
"eojC1KSyFlf3"
|
||||||
],
|
],
|
||||||
"toc_visible": true,
|
"toc_visible": true,
|
||||||
"include_colab_link": true
|
"include_colab_link": true
|
||||||
|
@ -28,47 +34,6 @@
|
||||||
"<a href=\"https://colab.research.google.com/github/88lex/safire/blob/master/safire.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
"<a href=\"https://colab.research.google.com/github/88lex/safire/blob/master/safire.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {
|
|
||||||
"id": "dAku_zP_KxPG",
|
|
||||||
"colab_type": "text"
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"### Commands"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"metadata": {
|
|
||||||
"id": "OeQm5tl7dLxF",
|
|
||||||
"colab_type": "code",
|
|
||||||
"cellView": "form",
|
|
||||||
"colab": {}
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"command1 = \"list projects\" #@param {type:\"string\"}\n",
|
|
||||||
"command2 = \"\" #@param {type:\"string\"}\n",
|
|
||||||
"command3 = \"\" #@param {type:\"string\"}\n",
|
|
||||||
"command4 = \"\" #@param {type:\"string\"}\n",
|
|
||||||
"command5 = \"\" #@param {type:\"string\"}\n",
|
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
"\n"
|
|
||||||
],
|
|
||||||
"execution_count": null,
|
|
||||||
"outputs": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {
|
|
||||||
"id": "yiEEfpW_zeB9",
|
|
||||||
"colab_type": "text"
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"Enter command(s) and select Runtime, Run All from the menu or ctrl-f9. See `Output` for results"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
@ -97,7 +62,6 @@
|
||||||
"colab_type": "text"
|
"colab_type": "text"
|
||||||
},
|
},
|
||||||
"source": [
|
"source": [
|
||||||
"\n",
|
|
||||||
"1. If using Colab:\n",
|
"1. If using Colab:\n",
|
||||||
" - Save copy of the ipynb file to your drive (Colab Notebooks folder)\n",
|
" - Save copy of the ipynb file to your drive (Colab Notebooks folder)\n",
|
||||||
" - Run the init code cell to auth to your My Drive account. This gives you access to Drive where you will store your creds, svcaccts and xlsx/csv files.\n",
|
" - Run the init code cell to auth to your My Drive account. This gives you access to Drive where you will store your creds, svcaccts and xlsx/csv files.\n",
|
||||||
|
@ -128,7 +92,8 @@
|
||||||
" - `add projects 5 1 myproj` will create 5 projects starting with number 0001 using a prefix of myproj. Result: myproj0001, myproj0002 .. myproj0005\n",
|
" - `add projects 5 1 myproj` will create 5 projects starting with number 0001 using a prefix of myproj. Result: myproj0001, myproj0002 .. myproj0005\n",
|
||||||
"\n",
|
"\n",
|
||||||
"7. Run commands using `Runtime - Run All` or `Ctrl-F9`\n",
|
"7. Run commands using `Runtime - Run All` or `Ctrl-F9`\n",
|
||||||
" - NOTE: If you run only the Command cell it will do nothing. You need to Run All in order to run all of the code.\n"
|
" - NOTE: If you run only the Command cell it will do nothing. You need to Run All in order to run all of the code.\n",
|
||||||
|
"\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -148,7 +113,7 @@
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "e2xK3xi2MlXs",
|
"id": "e2xK3xi2MlXs",
|
||||||
"colab_type": "code",
|
"colab_type": "code",
|
||||||
"cellView": "both",
|
"cellView": "form",
|
||||||
"colab": {}
|
"colab": {}
|
||||||
},
|
},
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -162,6 +127,7 @@
|
||||||
"from google.auth.transport.requests import Request\n",
|
"from google.auth.transport.requests import Request\n",
|
||||||
"from google_auth_oauthlib.flow import InstalledAppFlow\n",
|
"from google_auth_oauthlib.flow import InstalledAppFlow\n",
|
||||||
"from googleapiclient.discovery import build\n",
|
"from googleapiclient.discovery import build\n",
|
||||||
|
"from shutil import copyfile\n",
|
||||||
"\n",
|
"\n",
|
||||||
"if importlib.util.find_spec('fire') is None: os.system('pip install fire')\n",
|
"if importlib.util.find_spec('fire') is None: os.system('pip install fire')\n",
|
||||||
"import fire\n",
|
"import fire\n",
|
||||||
|
@ -174,13 +140,33 @@
|
||||||
" drive.mount(gdrive_mount)\n",
|
" drive.mount(gdrive_mount)\n",
|
||||||
" safire_dir = gdrive_mount + gd_output_dir\n",
|
" safire_dir = gdrive_mount + gd_output_dir\n",
|
||||||
"except:\n",
|
"except:\n",
|
||||||
" #@markdown Root directory when safire running locally (dropdown choices):\n",
|
" base_path = str(Path.home())\n",
|
||||||
" local_safire_dir = '/opt/safire/safire' #@param ['/opt/safire/safire', '~/safire', '~/../opt/safire/safire', \"safire\"] {allow-input: true}\n",
|
" safire_dir = os.path.join(base_path, \"safire\")\n",
|
||||||
" safire_dir = local_safire_dir\n",
|
" os.makedirs(safire_dir, exist_ok=True)\n",
|
||||||
"#@markdown External config file located in safire_dir. Use any name. Def: config.py:\n",
|
" cfg_file = os.path.join(safire_dir, \"config.py\")\n",
|
||||||
"use_external_config = True #@param {type:\"boolean\"}\n",
|
" if os.path.exists(cfg_file):\n",
|
||||||
"ext_conf_file = \"/config.py\" #@param [\"/config.py\"] {allow-input: true}\n",
|
" copyfile(cfg_file, \"config.py\")\n",
|
||||||
"ext_conf_file = safire_dir + ext_conf_file"
|
" else:\n",
|
||||||
|
" copyfile(\"default_config.py\", \"config.py\")\n",
|
||||||
|
" copyfile(\"default_config.py\", cfg_file)\n",
|
||||||
|
"\n",
|
||||||
|
" ## @markdown Root directory when safire running locally (dropdown choices):\n",
|
||||||
|
" # local_safire_dir = '~/safire' #@param ['~/safire', '/opt/safire/safire', '~/../opt/safire/safire', \"safire\"] {allow-input: true}\n",
|
||||||
|
" # safire_dir = local_safire_dir\n",
|
||||||
|
"# @markdown External config file located in local_safire_dir. Default: config.py:\n",
|
||||||
|
"use_external_config = True # @param {type:\"boolean\"}\n",
|
||||||
|
"ext_conf_file = \"config.py\" # @param [\"config.py\"] {allow-input: true}\n",
|
||||||
|
"ext_conf_file = os.path.join(safire_dir, ext_conf_file)\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"# except:\n",
|
||||||
|
"# #@markdown Root directory when safire running locally (dropdown choices):\n",
|
||||||
|
"# local_safire_dir = '~/safire' #@param ['~/safire', '/opt/safire/safire', '~/../opt/safire/safire', \"safire\"] {allow-input: true}\n",
|
||||||
|
"# safire_dir = local_safire_dir\n",
|
||||||
|
"# #@markdown External config file located in local_safire_dir. Default: config.py:\n",
|
||||||
|
"# use_external_config = True #@param {type:\"boolean\"}\n",
|
||||||
|
"# ext_conf_file = \"/config.py\" #@param [\"/config.py\"] {allow-input: true}\n",
|
||||||
|
"# ext_conf_file = safire_dir + ext_conf_file"
|
||||||
],
|
],
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"outputs": []
|
"outputs": []
|
||||||
|
@ -413,8 +399,9 @@
|
||||||
" \"https://www.googleapis.com/auth/drive\",\n",
|
" \"https://www.googleapis.com/auth/drive\",\n",
|
||||||
" \"https://www.googleapis.com/auth/cloud-platform\",\n",
|
" \"https://www.googleapis.com/auth/cloud-platform\",\n",
|
||||||
" \"https://www.googleapis.com/auth/iam\",\n",
|
" \"https://www.googleapis.com/auth/iam\",\n",
|
||||||
" \"https://www.googleapis.com/auth/spreadsheets\",\n",
|
|
||||||
" ]\n",
|
" ]\n",
|
||||||
|
" # \"https://www.googleapis.com/auth/spreadsheets\",\n",
|
||||||
|
"\n",
|
||||||
" self.scopes_group = [\n",
|
" self.scopes_group = [\n",
|
||||||
" \"https://www.googleapis.com/auth/admin.directory.group\",\n",
|
" \"https://www.googleapis.com/auth/admin.directory.group\",\n",
|
||||||
" \"https://www.googleapis.com/auth/admin.directory.group.member\",\n",
|
" \"https://www.googleapis.com/auth/admin.directory.group.member\",\n",
|
||||||
|
@ -1096,14 +1083,14 @@
|
||||||
" if not files:\n",
|
" if not files:\n",
|
||||||
" return f\"No json keys found in {sa_path}, Nothing to delete\"\n",
|
" return f\"No json keys found in {sa_path}, Nothing to delete\"\n",
|
||||||
" delete_files = [i for i in sorted(files) if \".json\" and str(filter) in i]\n",
|
" delete_files = [i for i in sorted(files) if \".json\" and str(filter) in i]\n",
|
||||||
" print(f\"Files to be deleted:\\n\", *delete_files, sep=\"\\n\")\n",
|
" # print(f\"Files to be deleted:\\n\", *delete_files, sep=\"\\n\")\n",
|
||||||
" yes_no = input(\"Confirm you want to delete all of these files. y/n: \")\n",
|
" # yes_no = input(\"Confirm you want to delete all of these files. y/n: \")\n",
|
||||||
" if yes_no.lower() in [\"y\", \"yes\"]:\n",
|
" # if yes_no.lower() in [\"y\", \"yes\"]:\n",
|
||||||
" for file in delete_files:\n",
|
" for file in delete_files:\n",
|
||||||
" print(f\"Removing {file}\")\n",
|
" print(f\"Removing {file}\")\n",
|
||||||
" os.remove(f\"{sa_path}/{file}\")\n",
|
" os.remove(f\"{sa_path}/{file}\")\n",
|
||||||
" else:\n",
|
" # else:\n",
|
||||||
" print(\"Deletion of json files aborted\")\n",
|
" # print(\"Deletion of json files aborted\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def members(\n",
|
" def members(\n",
|
||||||
" self,\n",
|
" self,\n",
|
||||||
|
@ -1255,7 +1242,18 @@
|
||||||
"colab_type": "text"
|
"colab_type": "text"
|
||||||
},
|
},
|
||||||
"source": [
|
"source": [
|
||||||
"## Output"
|
"## Commands"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "yiEEfpW_zeB9",
|
||||||
|
"colab_type": "text"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"- Enter command(s) and select `Runtime, Run All` from the top menu in Colab (or use ctrl-f9 to run all). \n",
|
||||||
|
"- See below for results of each command. All results are also exported to xlsx and csv files in the /data directory"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1267,42 +1265,39 @@
|
||||||
"colab": {}
|
"colab": {}
|
||||||
},
|
},
|
||||||
"source": [
|
"source": [
|
||||||
"%%time\n",
|
"if \"safire_ip.py\" == sys.argv[0] and __name__ == \"__main__\":\n",
|
||||||
"# %%timeit\n",
|
|
||||||
"\n",
|
|
||||||
"#@markdown\n",
|
|
||||||
"if \"safire.py\" == sys.argv[0] and __name__ == \"__main__\":\n",
|
|
||||||
" fire.Fire(Commands)\n",
|
" fire.Fire(Commands)\n",
|
||||||
"else:\n",
|
"else:\n",
|
||||||
|
" %%time\n",
|
||||||
|
" command1 = \"\" #@param {type:\"string\"}\n",
|
||||||
" if command1:\n",
|
" if command1:\n",
|
||||||
" sys.argv = [\"\"] + list(command1.split(\" \"))\n",
|
" sys.argv = [\"\"] + list(command1.split(\" \"))\n",
|
||||||
" print(f\"safire command: {command1} \\n\\nOutput: \\n\")\n",
|
" print(f\"safire command: {command1} \\n\\nOutput: \\n\")\n",
|
||||||
" fire.Fire(Commands)\n",
|
" fire.Fire(Commands)\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
" command2 = \"\" #@param {type:\"string\"}\n",
|
||||||
" if command2:\n",
|
" if command2:\n",
|
||||||
" sys.argv = [\"\"] + list(command2.split(\" \"))\n",
|
" sys.argv = [\"\"] + list(command2.split(\" \"))\n",
|
||||||
" print(f\"safire command: {command2} \\n\\nOutput: \\n\")\n",
|
" print(f\"safire command: {command2} \\n\\nOutput: \\n\")\n",
|
||||||
" fire.Fire(Commands)\n",
|
" fire.Fire(Commands)\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
" command3 = \"\" #@param {type:\"string\"}\n",
|
||||||
" if command3:\n",
|
" if command3:\n",
|
||||||
" sys.argv = [\"\"] + list(command3.split(\" \"))\n",
|
" sys.argv = [\"\"] + list(command3.split(\" \"))\n",
|
||||||
" print(f\"safire command: {command3} \\n\\nOutput: \\n\")\n",
|
" print(f\"safire command: {command3} \\n\\nOutput: \\n\")\n",
|
||||||
" fire.Fire(Commands)\n",
|
" fire.Fire(Commands)\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
" command4 = \"\" #@param {type:\"string\"}\n",
|
||||||
" if command4:\n",
|
" if command4:\n",
|
||||||
" sys.argv = [\"\"] + list(command4.split(\" \"))\n",
|
" sys.argv = [\"\"] + list(command4.split(\" \"))\n",
|
||||||
" print(f\"safire command: {command4} \\n\\nOutput: \\n\")\n",
|
" print(f\"safire command: {command4} \\n\\nOutput: \\n\")\n",
|
||||||
" fire.Fire(Commands)\n",
|
" fire.Fire(Commands)\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
" command5 = \"\" #@param {type:\"string\"}\n",
|
||||||
" if command5:\n",
|
" if command5:\n",
|
||||||
" sys.argv = [\"\"] + list(command5.split(\" \"))\n",
|
" sys.argv = [\"\"] + list(command5.split(\" \"))\n",
|
||||||
" print(f\"safire command: {command5} \\n\\nOutput: \\n\")\n",
|
" print(f\"safire command: {command5} \\n\\nOutput: \\n\")\n",
|
||||||
" fire.Fire(Commands)\n",
|
" fire.Fire(Commands)\n"
|
||||||
"# else:\n",
|
|
||||||
"# if __name__ == \"__main__\":\n",
|
|
||||||
"# fire.Fire(Commands)\n",
|
|
||||||
"\n",
|
|
||||||
"\n"
|
|
||||||
],
|
],
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"outputs": []
|
"outputs": []
|
||||||
|
|
Loading…
Reference in a new issue