{ "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 }