File size: 3,764 Bytes
9fcb2ba |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "1ba72ed3",
"metadata": {},
"outputs": [],
"source": [
"t_a = tarfile.open(f\"ethereum_0.tar\", \"r\")\n",
"# for itm in t_a:\n",
"# print(dir(itm))\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "b42aea41",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ls: cannot access '/home/jquave/dev/smart-contract-sanctuary/ethereum/contracts/mainnet/00': No such file or directory\r\n"
]
}
],
"source": [
"!ls ~/dev/smart-contract-sanctuary/ethereum/contracts/mainnet/00"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3969730c",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import shutil\n",
"import json\n",
"import tarfile\n",
"\n",
"# archive = tarfile.open(\"ethereum.tar\", \"a\")\n",
"# archive.add(\"repo/a.git\", arcname=\"a.git\")\n",
"# archive.close()\n",
"\n",
"class A:\n",
" def __init__(self):\n",
" self.n = 0\n",
" self.i = 0\n",
" self.archive = tarfile.open(f\"ethereum_0.tar\", \"a\")\n",
" \n",
" def recursive_dump_sol_to_json(self, root_dir):\n",
" # Traverse the directory and list all .sol files\n",
" path_items = os.listdir(root_dir)\n",
" # print(path_items)\n",
" # Iterate over the list of .sol files\n",
" # archive = tarfile.open(f\"ethereum_{tar_split_n}.tar\", \"a\")\n",
" for path_item in path_items:\n",
" self.i = self.i + 1\n",
" if i % 10 == 0:\n",
" print(f\"{self.n}:{root_dir} path_item {path_item}\")\n",
" if path_item == \".\" or path_item == \"..\" or path_item ==\"../\" or path_item == \"./\":\n",
" return\n",
" # Read the contents of the .sol file\n",
" full_path_item = os.path.join(root_dir, path_item)\n",
" if os.path.isdir(full_path_item):\n",
" self.n = self.n + 1\n",
" self.recursive_dump_sol_to_json(full_path_item)\n",
" else:\n",
" if path_item.endswith(\".sol\"):\n",
"# f=1\n",
" if self.i > 20_000:\n",
" self.i = 0\n",
" self.n = self.n + 1\n",
" old_archive = self.archive\n",
" self.archive = tarfile.open(f\"ethereum_{self.n}.tar\", \"a\")\n",
" old_archive.close()\n",
" self.archive.add(full_path_item, arcname=f\"{path_item}.txt\")\n",
" \n",
"# Driver code\n",
"a = A()\n",
"root_dir = '../smart-contract-sanctuary/ethereum/contracts/mainnet'\n",
"a.recursive_dump_sol_to_json(root_dir)\n",
"# archive.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c88f36bc",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "88b22976",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|